validate_check_constraint fails with multiple schemas
During an upgrade I got the following error:
Could not find check constraint "(...)" on table "application_settings" which was referenced during the migration.
But checking on the DB I saw (\d+ application_settings
) the constraint there.
After hours debugging it, I figure it out that "half" of my tables were in another schema, other then public
, with the
same name as the username used to connect to the DB.
In my case, application_settings
is in public
schema.
It seems PGSQL has this search_path
config that says: if the schema is not explicit, it searches in "$user"
then public
.
So, db:migrate applies the constraint in the right schema.table, but validate_check_constraint
tries to check it in the other schema.
How to fix that: Moving all tables to public
and renaming the other schema.
What should be fixed: The validate_check_constraint behavior against multiple schemes.
Suggestion: Would be interesting to set the schema in gitlab.rb .
Thanks to @brodock for helping in this case.