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

rails db:setup doesn't mark data migrations completed using data_schema.rb #82

Closed
harigopal opened this issue Feb 12, 2018 · 4 comments
Closed

Comments

@harigopal
Copy link

@harigopal harigopal commented Feb 12, 2018

I've been running into an issue with rails db:setup command not loading the data_schema.rb file, like it does for schema.rb. Basically, when dropping my development database and setting it up again, rails data:migrate:status shows all previous migrations as incomplete, even though the data_schema.rb file contains the last version number.

I also tried running the tasks by unpacking setup: db:create, and db:schema:load:with_data in order, with no change.

I've gone through the code a bit, and noticed that the data:schema:load:with_data task runs DataMigrate::DatabaseTasks.load_schema_current, which is an ActiveRecord method. However, this method internally uses another method schema_file(format) for determining the file which should be used to load the version.

However, DataMigrate::DatabaseTasks only defined a self.data_schema_file() method which, as far as I can tell, is never used except for dumping the version after a data migration is executed. Shouldn't this class override ActiveRecord's schema_file(format) method instead of defining a new method?

I tried a simple method rename to override the original implementation, but that didn't have any effect. Do you have any idea what could be going wrong?

@harigopal harigopal changed the title rails db:setup doesn't mark data migrations completed using `data_schema.rb` rails db:setup doesn't mark data migrations completed using data_schema.rb Feb 12, 2018
@ilyakatz

This comment has been minimized.

Copy link
Owner

@ilyakatz ilyakatz commented Feb 12, 2018

when dropping my development database and setting it up again

if you drop the database, than all data migrations are nullified. In order to load them back in, you would need to run regular rake data:migrate. This happens because we don't actually store the data migration in the data_schema file (unlike db_schema)

@harigopal

This comment has been minimized.

Copy link
Author

@harigopal harigopal commented Feb 19, 2018

@ilyakatz I'm not sure I understand what you mean.

The data_schema.rb file contains the code:

DataMigrate::Data.define(version: 20180219091554)

If I manually run this line in a rails console, it correctly sets up the entries in the data_migrations table - i.e., it goes through all the available data migrations and marks them as completed.

My issue is that this isn't done when a database is set up using rails db:setup.

My check in the codebase indicates that this is supposed to happen, but is blocked - possibly because of the reason I listed above.

I currently have to manually run this line in a rails console after setting up the database to make sure that data migrations that have already been accounted for (using updated seeds / fixtures), are not run again.

@ilyakatz ilyakatz mentioned this issue Mar 7, 2018
@kavitakanojiya

This comment has been minimized.

Copy link

@kavitakanojiya kavitakanojiya commented Apr 8, 2018

Recently, I faced this same issue. I tried fixing this through #85. But I ended up adding versions of data migrations into schema migrations.

Apparently, https://github.com/rails/rails/blob/master/activerecord/lib/active_record/tasks/database_tasks.rb#L251 bumps everything all at once. Still I am debugging the workflow to make it work.

Meanwhile, do you have any inputs?

@ilyakatz

This comment has been minimized.

Copy link
Owner

@ilyakatz ilyakatz commented Sep 30, 2019

this has been open for a while without much support, going to close it out

@ilyakatz ilyakatz closed this Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.