Migration fails to populate post_versions_mentions #29

Closed
graue opened this Issue Dec 28, 2012 · 2 comments

Projects

None yet

2 participants

@graue
graue commented Dec 28, 2012

I'm trying to upgrade to 0.2. The rake db:migrate step is failing:

$ DATABASE_URL=postgres://...@localhost/tent_server bundle exec rake db:migrate
Error: Sequel::DatabaseError: PG::Error: ERROR:  insert or update on table "post_versions_mentions" violates foreign key constraint "post_versions_mentions_mention_id_fkey"
DETAIL:  Key (mention_id)=(309) is not present in table "mentions".
/var/lib/gems/1.9.1/gems/sequel-3.42.0/lib/sequel/adapters/postgres.rb:145:in `async_exec'

It appears to be this migration, 002_post_versions_many_to_many.rb.

There's no row in the mentions table with id=309, but I'm not sure why that would be a problem? If I show the whole table, about 100 IDs are skipped.

@jvatic jvatic pushed a commit to tent/tentd that referenced this issue Dec 28, 2012
Jesse Stuart Fix 0.2 002_post_versions_many_to_many migration d2047f3
@jvatic
Member
jvatic commented Dec 28, 2012

The relavant portion of the migration is:

INSERT INTO post_versions_mentions
SELECT id AS mention_id, post_version_id FROM mentions
WHERE mentions.post_version_id IS NOT NULL;

what appears to be happening is postgres is inserting the selected columns in column definition order (as described in the docs) but the columns are mistakenly being selected in the oposite order. tent/tentd@d2047f3 reorders the columns in the create table statement so the query will work as expected.

id 309 I expect is referencing the post_versions table.

@graue
graue commented Dec 28, 2012

That seems to have done it. Thanks Jesse!

@graue graue closed this Dec 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment