ilyakatz / data-migrate

Migrate and update data alongside your database structure.
MIT License
1.42k stars 194 forks source link

Data Migration with Postgres, logging version to wrong table #15

Closed mjsommer closed 8 years ago

mjsommer commented 10 years ago

Hi,

I just setup Data Migrate with Rails 4 and Postgres 9.2, and am having an issue with the version being stored in the wrong table. Even though: 1) I use the '--skip-schema-migration' flag, and 2) create a migration (only) in the db/data folder, when I run 'rake data:migrate', the version is stored in the schema_migrations table, and not data_migrations.

In addition, if I do a 'rake data:migrate:status' after successfully running the migration, the status comes back as 'down', vs 'up'. This is most likely, because the version was listed in the wrong table, to begin with.

I tried building the migration without the '--skip-schema-migration' flag, and got the same results.

Fyi, here is my table info:

abc_development=# \d schema_migrations Table "public.schema_migrations" Column | Type | Modifiers ---------+------------------------+----------- version | character varying(255) | not null Indexes: "unique_schema_migrations" UNIQUE, btree (version)

abc_development=# \d data_migrations Table "public.data_migrations" Column | Type | Modifiers ---------+------------------------+----------- version | character varying(255) | not null Indexes: "unique_data_migrations" UNIQUE, btree (version)

How can I fix this?

Thanks, Martin

ajvargo commented 10 years ago

@mjsommer - You'll have to pull it out, sorry. I'm at work and was just too busy this weekend to hack at it. Very sorry about hat.

I don't know that its been testing against Rails 4, so there might be some underlying changes. I'll try my best to get to things this week, but no promises.

Incidentally, if someone has a good idea of how to add specs for this bad-boy.. :)

annaswims commented 10 years ago

I've started to take a stab at adding rpsec here - https://github.com/nextgearcapital/data-migrate/tree/rspec

mjsommer commented 10 years ago

Hi Andrew,

I took a stab at this. Your mentioned schema_migrations_table_name method is properly returning "data_migrations" as the table name, but ActiveRecord appears to be missing this, and sending the new version number to the schema_migrations table in:

active_record/migration.rb, line 990 => ActiveRecord::SchemaMigration.create!(:version => version.to_s)

I am thinking this should be ActiveRecord::DataMigration.create, but that does not exist.

Can you connect the dots here?

Thanks again, Martin

ilyakatz commented 8 years ago

This was resolved in this issue https://github.com/ilyakatz/data-migrate/issues/22. Please check it out and if there are any problems please create a followup issue.

Thanks for reporting this!