diff --git a/lib/generators/geocoder/maxmind/geolite_city_generator.rb b/lib/generators/geocoder/maxmind/geolite_city_generator.rb index 2743957a48206d6ceae072810e6b1ae03ab1de70..9858975547b87afd907fc6e9651cfcbc0aa32e34 100644 --- a/lib/generators/geocoder/maxmind/geolite_city_generator.rb +++ b/lib/generators/geocoder/maxmind/geolite_city_generator.rb @@ -1,10 +1,12 @@ require 'rails/generators/migration' +require 'generators/geocoder/migration_version' module Geocoder module Generators module Maxmind class GeoliteCityGenerator < Rails::Generators::Base include Rails::Generators::Migration + include Generators::MigrationVersion source_root File.expand_path('../templates', __FILE__) diff --git a/lib/generators/geocoder/maxmind/geolite_country_generator.rb b/lib/generators/geocoder/maxmind/geolite_country_generator.rb index c9e4bc9560f31e9bae357e9ebb8b568ac12e9e64..6aa07f71ca437a5f0b5036f5a7bc804af901e03b 100644 --- a/lib/generators/geocoder/maxmind/geolite_country_generator.rb +++ b/lib/generators/geocoder/maxmind/geolite_country_generator.rb @@ -1,10 +1,12 @@ require 'rails/generators/migration' +require 'generators/geocoder/migration_version' module Geocoder module Generators module Maxmind class GeoliteCountryGenerator < Rails::Generators::Base include Rails::Generators::Migration + include Generators::MigrationVersion source_root File.expand_path('../templates', __FILE__) diff --git a/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb b/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb index bf87520620fbcbedd3fae64f8b342bf047c0a673..b4068e047fe2012696290398a777c3b23f037870 100644 --- a/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +++ b/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb @@ -1,4 +1,4 @@ -class GeocoderMaxmindGeoliteCity < ActiveRecord::Migration +class GeocoderMaxmindGeoliteCity < ActiveRecord::Migration<%= migration_version %> def self.up create_table :maxmind_geolite_city_blocks, id: false do |t| t.column :start_ip_num, :bigint, null: false diff --git a/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb b/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb index 5b3e1bf36d9526e93a86bc20a80bd16baf156dba..e7dc982a4f05bf24e49a710aee21f0890db03e8c 100644 --- a/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +++ b/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb @@ -1,4 +1,4 @@ -class GeocoderMaxmindGeoliteCountry < ActiveRecord::Migration +class GeocoderMaxmindGeoliteCountry < ActiveRecord::Migration<%= migration_version %> def self.up create_table :maxmind_geolite_country, id: false do |t| t.column :start_ip, :string diff --git a/lib/generators/geocoder/migration_version.rb b/lib/generators/geocoder/migration_version.rb new file mode 100644 index 0000000000000000000000000000000000000000..71711eb44a293a8d59e4ecda09ed242f0a44c6cc --- /dev/null +++ b/lib/generators/geocoder/migration_version.rb @@ -0,0 +1,15 @@ +module Geocoder + module Generators + module MigrationVersion + def rails_5? + Rails::VERSION::MAJOR == 5 + end + + def migration_version + if rails_5? + "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" + end + end + end + end +end diff --git a/test/db/migrate/001_create_test_schema.rb b/test/db/migrate/001_create_test_schema.rb index aca50cfffb96d36f3c1010fb3a88841d627930fe..649f99b81ce7ce8931ecdc915e351eb239b4b748 100644 --- a/test/db/migrate/001_create_test_schema.rb +++ b/test/db/migrate/001_create_test_schema.rb @@ -1,5 +1,10 @@ # CreateTestSchema creates the tables used in test_helper.rb -class CreateTestSchema < ActiveRecord::Migration + +superclass = ActiveRecord::Migration +# TODO: Inherit from the 5.0 Migration class directly when we drop support for Rails 4. +superclass = ActiveRecord::Migration[5.0] if superclass.respond_to?(:[]) + +class CreateTestSchema < superclass def self.up [ :places,