Project

General

Profile

Bug #2377

postgresql migrations are currently failing

Added by Greg Sutcliffe over 6 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
High
Assignee:
-
Category:
DB migrations
Target version:
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

Currently both myself and Lukas are seeing failures on Postgresql, which look like this:

==  AddSuseTemplates: migrating ===============================================
-- Failed to migrate PG::Error: ERROR:  column "operatingsystem_id" of relation "media" does not exist
LINE 1: INSERT INTO "media" ("created_at", "name", "operatingsystem_...
                                                   ^
: INSERT INTO "media" ("created_at", "name", "operatingsystem_id", "path", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" 
==  AddSuseTemplates: migrated (0.2182s) ======================================

rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR:  current transaction is aborted, commands ignored until end of transaction block
:           SELECT attr.attname
          FROM pg_attribute attr
          INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1]
          WHERE cons.contype = 'p'
            AND cons.conrelid = '"schema_migrations"'::regclass
/tmp/foreman/vendorgems/ruby/1.8/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `async_exec'

Git bisecting shows the Rails 3.2 commit is at fault, so I'm not sure how Jenkins is passing tests at the moment. I can't track down what's causing it - the Suse Migration in the error is quite complex, so I assume it relied on something Rails 3.0 specific...

Associated revisions

Revision 2c0ab9be (diff)
Added by Dominic Cleal over 6 years ago

fixes #2377 - refresh column info after editing Medium

Fixes error in 20110725142054_add_suse_templates referencing non-existent
operatingsystem_id column.

History

#1 Updated by Ohad Levy over 6 years ago

I blame this line:

https://github.com/theforeman/foreman/commit/feacea35f07f362d9e2c694a83516bbc902321a0#L127L3

Originally I had no idea why this change was required, but according to @Amos, this fixed another failure in pg.

can you try reverting that and see if it solves the issue?

#2 Updated by Greg Sutcliffe over 6 years ago

Sadly no, it doesn't fix the problem. Exactly the same error.

#3 Updated by Dominic Cleal over 6 years ago

  • Status changed from New to Ready For Testing

https://github.com/theforeman/foreman/pull/512

Even if you were a SQLite user, you'd see a log message due to the rescue block in this migration as AR was still thinking that the operatingsystem_id field was present in the media table. For some reason, PostgreSQL wasn't hitting the rescue block (maybe the error was thrown in a transaction commit?).

I think the reason this didn't occur on Jenkins was some change in behaviour when under the test environment. I don't see AR "create" calls happening in migrations (could this be a Rails optimisation as fixtures are used instead?), so the line causing the problem never caused an INSERT statement. I think I'll change Jenkins to migrate in the development environment and then we'll rely on schema loading for test.

#4 Updated by Dominic Cleal over 6 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#5 Updated by Dominic Cleal over 6 years ago

Jenkins config has been changed to run the migrate in the development env instead, which now picks up this error and class of bug.

Also available in: Atom PDF