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

Wrong value for current_data_version in db:migrate:with_data? #201

Open
sully7 opened this issue Jan 6, 2022 · 1 comment
Open

Wrong value for current_data_version in db:migrate:with_data? #201

sully7 opened this issue Jan 6, 2022 · 1 comment

Comments

@sully7
Copy link
Contributor

sully7 commented Jan 6, 2022

In the blob:

if target_version.nil?
migrations = pending_migrations.map{ |m| m.merge(:direction =>:up) }
else
current_schema_version = ActiveRecord::Migrator.current_version
schema_migrations = if target_version > current_schema_version
pending_schema_migrations.keep_if{ |m| m[:version] <= target_version }.map{ |m| m.merge(:direction =>:up) }
elsif target_version < current_schema_version
past_migrations.keep_if{ |m| m[:version] > target_version }.map{ |m| m.merge(:direction =>:down) }
else # ==
[]
end
current_data_version = ActiveRecord::Migrator.current_version
data_migrations = if target_version > current_data_version
pending_data_migrations.keep_if{ |m| m[:version] <= target_version }.map{ |m| m.merge(:direction =>:up) }
elsif target_version < current_data_version
past_migrations.keep_if{ |m| m[:version] > target_version }.map{ |m| m.merge(:direction =>:down) }
else # ==
[]
end
migrations = if schema_migrations.empty?
data_migrations
elsif data_migrations.empty?
schema_migrations
elsif target_version > current_data_version && target_version > current_schema_version
sort_migrations data_migrations, schema_migrations
elsif target_version < current_data_version && target_version < current_schema_version
sort_migrations(data_migrations, schema_migrations).reverse
elsif target_version > current_data_version && target_version < current_schema_version
schema_migrations + data_migrations
elsif target_version < current_data_version && target_version > current_schema_version
schema_migrations + data_migrations
end
end

The following variables are currently assigned to the same value:

current_schema_version = ActiveRecord::Migrator.current_version

current_data_version = ActiveRecord::Migrator.current_version

I think Line 25 is instead supposed to read

current_data_version = DataMigrate::DataMigrator.current_version

Haven't gone through testing yet, but wanted to see if anyone else thought this was incorrect?

@ilyakatz
Copy link
Owner

ilyakatz commented Jan 6, 2022

hi @sully7 thanks for this as well. a few major versions ago, there was a lot more reliance directly on ActiveRecord::Migrator, i later introduced DataMigrate::DataMigrator so this sounds like this is correct change. To be honest, I haven't worked with rails (and this gem) for over 2 years so i'd appreciate if you could test it out a bit. Let me know if you need anything else from me

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

No branches or pull requests

2 participants