Skip to content

Commit

Permalink
Use ActiveRecord.timestamped_migrations (#352)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Spone and joshbuker authored Mar 8, 2024
1 parent 7a319c2 commit ae44540
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
10 changes: 9 additions & 1 deletion lib/generators/sorcery/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ae44540

Please sign in to comment.