From ae44540860db8fb8ece4598e1ac09b2dfdc1be3f Mon Sep 17 00:00:00 2001 From: Hans Lemuet Date: Fri, 8 Mar 2024 20:59:09 +0100 Subject: [PATCH] Use ActiveRecord.timestamped_migrations (#352) * Remove duplicate method in InstallGenerator There's no need to call `inject_sorcery_to_model` in the previous method, since the generators execute all public methods in order. * Update CHANGELOG.md * Use ActiveRecord.timestamped_migrations Replace ActiveRecord::Base.timestamped_migrations with the newer ActiveRecord.timestamped_migrations * Update CHANGELOG.md * Improve compatibility * Fix method scope --------- Co-authored-by: Josh Buker --- CHANGELOG.md | 1 + lib/generators/sorcery/install_generator.rb | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 778227a7..555a2662 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## HEAD +* Fix Rails 7.1 compatibility by using `ActiveRecord.timestamped_migrations` [#352](https://github.com/Sorcery/sorcery/pull/352) * Change CI settings for support Ruby3.0+ Rails6.1+ [#357](https://github.com/Sorcery/sorcery/pull/357) * Fix error when running the install generator [#339](https://github.com/Sorcery/sorcery/pull/339) diff --git a/lib/generators/sorcery/install_generator.rb b/lib/generators/sorcery/install_generator.rb index 856c0eb5..fe615821 100644 --- a/lib/generators/sorcery/install_generator.rb +++ b/lib/generators/sorcery/install_generator.rb @@ -74,7 +74,7 @@ def copy_migration_files # Define the next_migration_number method (necessary for the migration_template method to work) def self.next_migration_number(dirname) - if ActiveRecord::Base.timestamped_migrations + if timestamped_migrations? sleep 1 # make sure each time we get a different timestamp Time.new.utc.strftime('%Y%m%d%H%M%S') else @@ -84,6 +84,14 @@ def self.next_migration_number(dirname) private + def self.timestamped_migrations? + if Rails::VERSION::MAJOR >= 7 + ActiveRecord.timestamped_migrations + else + ActiveRecord::Base.timestamped_migrations + end + end + def only_submodules? options[:migrations] || options[:only_submodules] end