Reputation: 2669
I converted a DB using this:
https://github.com/maxlapshin/mysql2postgres
At a glance it looks like it worked. Tables/columns/indices are in place inside of postgres... Great.
However, db:migrate wants to run all of my migrations. It's as if the schema_migrations table didn't get converted correctly - or had no records. But it does have all of the records, and looks the same as it does in mysql.
That or the postgres adapter tracks migrations in some other way.
Upvotes: 0
Views: 318
Reputation: 434945
Are you sure your schema_migrations
table has the right schema? Go into psql
and do:
> \d schema_migrations
You should see this:
Table "public.schema_migrations"
Column | Type | Modifiers
---------+------------------------+-----------
version | character varying(255) | not null
Indexes:
"unique_schema_migrations" UNIQUE, btree (version)
or nearly that.
If it looks like that and db:migrate
still wants to run all your migrations then you probably have some stray spaces in the column values or something similar. You can waste more time trying to fix it or you can just rebuild it by hand and move on to more interesting activities. From psql
:
> drop table schema_migrations;
> create table schema_migrations (
version varchar(255) not null,
constraint unique_schema_migrations unique (version)
);
and then from your migrations directory (assuming you're on something Unixy):
$ for m in *.rb; do printf "insert into schema_migrations (version) values ('%s');\n" $(echo $m | sed 's/_.*//');done | psql -h your_host -U your_user -d your_db
You'll have to supply the correct values for the -h
, -U
, and -d
switches of course.
Upvotes: 2