Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix schema.rb with ActiveRecord::Schema[7.0].define #106

Conversation

andrewjstrominger
Copy link

ActiveRecord::Schema[7.0].define(version: 2022_05_17_144011) do

Without Fix:

[1] pry(main)> HairTrigger::migrations_current?
  ActiveRecord::SchemaMigration Pluck (0.5ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
ArgumentError: comparison of NilClass with 20220517144011 failed
from /usr/local/rvm/gems/ruby-3.1.2/gems/hairtrigger-0.2.25/lib/hair_trigger.rb:90:in `sort_by'

With Fix:

[1] pry(main)> HairTrigger::migrations_current?
  ActiveRecord::SchemaMigration Pluck (0.5ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
=> true

@andrewjstrominger andrewjstrominger marked this pull request as ready for review May 17, 2022 15:51
@alanhala
Copy link

Is this gem still maintained? Would be great to have this for newer Rails app as hairtrigger is not currently supporting it.

@@ -82,7 +82,7 @@ def current_migrations(options = {})
if previous_schema = (options.has_key?(:previous_schema) ? options[:previous_schema] : File.exist?(schema_rb_path) && File.read(schema_rb_path))
base_triggers = MigrationReader.get_triggers(previous_schema, options)
unless base_triggers.empty?
version = (previous_schema =~ /ActiveRecord::Schema\.define\(.*?(\d+)\)/) && $1.to_i
version = (previous_schema =~ /ActiveRecord::Schema(\[\d\.\d\])?\.define\(.*?(\d+)\)/) && $1.to_i

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also match underscored version number 2022_10_06_165942

version = (previous_schema =~ /ActiveRecord::Schema(?:\[\d\.\d\])\.define\(.*?(\d+(?:_\d+)*)\)/) && $1.to_i

@jenseng
Copy link
Owner

jenseng commented Dec 12, 2022

Merged #104 which should address this, sorry for the delay! I'll cut a new release shortly

@jenseng jenseng closed this Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants