From 7a1c80dfb27b7cd02d545748b0e8e15090034249 Mon Sep 17 00:00:00 2001 From: Tomoya Yoshida Date: Wed, 12 Jun 2024 16:46:00 +0900 Subject: [PATCH] Use ActiveRecord.timestamped_migrations when rails major version is 7 or higher --- .../active_record/impressionist_generator.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/generators/active_record/impressionist_generator.rb b/lib/generators/active_record/impressionist_generator.rb index 1c899782..c9f517eb 100644 --- a/lib/generators/active_record/impressionist_generator.rb +++ b/lib/generators/active_record/impressionist_generator.rb @@ -7,7 +7,7 @@ class ImpressionistGenerator < Rails::Generators::Base # FIX, why is this implementing rails behaviour? def self.next_migration_number(dirname) sleep 1 - if ActiveRecord::Base.timestamped_migrations + if timestamped_migrations? Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) @@ -17,6 +17,18 @@ def self.next_migration_number(dirname) def create_migration_file migration_template 'create_impressions_table.rb.erb', 'db/migrate/create_impressions_table.rb' end + + class << self + private + + def timestamped_migrations? + if Rails::VERSION::MAJOR >= 7 + ActiveRecord.timestamped_migrations + else + ActiveRecord::Base.timestamped_migrations + end + end + end end end end