From b737eed34965d6a4b183ac1a8a2675bdcb7b09d6 Mon Sep 17 00:00:00 2001 From: James Adam Date: Fri, 9 Feb 2024 10:45:31 +0000 Subject: [PATCH] Fix migration generator to support Rails 7.1 As in 50285aca0b6ed44be192c7c808fb05ce85236b33 we need to support the new location of `timestamped_migrations` --- .../unread/migration/migration_generator.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/generators/unread/migration/migration_generator.rb b/lib/generators/unread/migration/migration_generator.rb index e197c9b..3684340 100644 --- a/lib/generators/unread/migration/migration_generator.rb +++ b/lib/generators/unread/migration/migration_generator.rb @@ -13,11 +13,22 @@ def create_migration_file end def self.next_migration_number(dirname) - if ActiveRecord::Base.timestamped_migrations + if self.timestamped_migrations? Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end + + def self.timestamped_migrations? + ( + ActiveRecord::Base.respond_to?(:timestamped_migrations) && + ActiveRecord::Base.timestamped_migrations + ) || + ( + ActiveRecord.respond_to?(:timestamped_migrations) && + ActiveRecord.timestamped_migrations + ) + end end end