diff --git a/lib/generators/doorkeeper/application_owner_generator.rb b/lib/generators/doorkeeper/application_owner_generator.rb index ce6ca58e1..0db39ea47 100644 --- a/lib/generators/doorkeeper/application_owner_generator.rb +++ b/lib/generators/doorkeeper/application_owner_generator.rb @@ -7,12 +7,19 @@ class Doorkeeper::ApplicationOwnerGenerator < Rails::Generators::Base def application_owner migration_template( - 'add_owner_to_application_migration.rb', - 'db/migrate/add_owner_to_application.rb' + "add_owner_to_application_migration.rb.erb", + "db/migrate/add_owner_to_application.rb", + migration_version: migration_version ) end def self.next_migration_number(dirname) ActiveRecord::Generators::Base.next_migration_number(dirname) end + + def migration_version + if Rails.version >= "5.0.0" + "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" + end + end end diff --git a/lib/generators/doorkeeper/migration_generator.rb b/lib/generators/doorkeeper/migration_generator.rb index 53ad21be2..510ade772 100644 --- a/lib/generators/doorkeeper/migration_generator.rb +++ b/lib/generators/doorkeeper/migration_generator.rb @@ -7,8 +7,8 @@ class Doorkeeper::MigrationGenerator < ::Rails::Generators::Base def install migration_template( - 'migration.rb', - 'db/migrate/create_doorkeeper_tables.rb', + "migration.rb.erb", + "db/migrate/create_doorkeeper_tables.rb", migration_version: migration_version ) end diff --git a/lib/generators/doorkeeper/previous_refresh_token_generator.rb b/lib/generators/doorkeeper/previous_refresh_token_generator.rb index 88509e394..1f650dcc3 100644 --- a/lib/generators/doorkeeper/previous_refresh_token_generator.rb +++ b/lib/generators/doorkeeper/previous_refresh_token_generator.rb @@ -8,12 +8,19 @@ class Doorkeeper::PreviousRefreshTokenGenerator < Rails::Generators::Base def self.next_migration_number(path) ActiveRecord::Generators::Base.next_migration_number(path) end + + def migration_version + if Rails.version >= "5.0.0" + "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" + end + end def previous_refresh_token if no_previous_refresh_token_column? migration_template( - 'add_previous_refresh_token_to_access_tokens.rb', - 'db/migrate/add_previous_refresh_token_to_access_tokens.rb' + "add_previous_refresh_token_to_access_tokens.rb.erb", + "db/migrate/add_previous_refresh_token_to_access_tokens.rb", + migration_version: migration_version ) end end diff --git a/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb b/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb similarity index 73% rename from lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb rename to lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb index 76fcf8993..542a17b02 100644 --- a/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +++ b/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb @@ -1,4 +1,4 @@ -class AddOwnerToApplication < ActiveRecord::Migration +class AddOwnerToApplication < ActiveRecord::Migration<%= migration_version %> def change add_column :oauth_applications, :owner_id, :integer, null: true add_column :oauth_applications, :owner_type, :string, null: true diff --git a/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb b/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb.erb similarity index 88% rename from lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb rename to lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb.erb index e3f07e352..9dc447512 100644 --- a/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb +++ b/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb.erb @@ -1,4 +1,4 @@ -class AddPreviousRefreshTokenToAccessTokens < ActiveRecord::Migration +class AddPreviousRefreshTokenToAccessTokens < ActiveRecord::Migration<%= migration_version %> def change add_column( :oauth_access_tokens, diff --git a/lib/generators/doorkeeper/templates/migration.rb b/lib/generators/doorkeeper/templates/migration.rb.erb similarity index 100% rename from lib/generators/doorkeeper/templates/migration.rb rename to lib/generators/doorkeeper/templates/migration.rb.erb