Duplicate constraint migration errors
From https://gitlab.com/gitlab-org/gitlab/-/jobs/1094785780:
An error occurred in an `after(:context)` hook.
Failure/Error:
execute(<<~SQL)
ALTER TABLE #{quote_table_name(table_name)}
#{constraint_clauses.join(",\n")}
SQL
StandardError:
An error has occurred, all later migrations canceled:
PG::DuplicateObject: ERROR: constraint "check_fedff82d3b" for relation "iterations_cadences" already exists
# ./lib/gitlab/database/migration_helpers.rb:121:in `block in create_table_with_constraints'
# ./lib/gitlab/database/with_lock_retries.rb:121:in `run_block'
# ./lib/gitlab/database/with_lock_retries.rb:130:in `block in run_block_with_transaction'
# ./lib/gitlab/database.rb:325:in `block in transaction'
# ./lib/gitlab/database.rb:324:in `transaction'
# ./lib/gitlab/database/with_lock_retries.rb:125:in `run_block_with_transaction'
# ./lib/gitlab/database/with_lock_retries.rb:95:in `run'
# ./lib/gitlab/database/migration_helpers.rb:394:in `with_lock_retries'
# ./lib/gitlab/database/migration_helpers.rb:92:in `create_table_with_constraints'
# ./db/migrate/20201228110136_create_iterations_cadence.rb:11:in `up'
# ./spec/support/helpers/migrations_helpers.rb:118:in `block in schema_migrate_up!'
# ./spec/support/helpers/migrations_helpers.rb:128:in `disable_migrations_output'
# ./spec/support/helpers/migrations_helpers.rb:117:in `schema_migrate_up!'
# ./spec/support/migration.rb:27:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# PG::DuplicateObject:
# ERROR: constraint "check_fedff82d3b" for relation "iterations_cadences" already exists
# ./lib/gitlab/database/migration_helpers.rb:121:in `block in create_table_with_constraints'
CapDesignsFilenameLengthToNewLimit
Failures:
1) CapDesignsFilenameLengthToNewLimit correctly sets filenames that are above the limit
Failure/Error: start = start.take
StandardError:
An error has occurred, all later migrations canceled:
PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "incident"
LINE 1: ...."id" FROM "issues" WHERE "issues"."issue_type" = 'incident'...
^
# ./app/models/concerns/each_batch.rb:61:in `each_batch'
# ./db/post_migrate/20200723040950_migrate_incident_issues_to_incident_type.rb:43:in `down'
# ./spec/support/helpers/migrations_helpers.rb:108:in `block in schema_migrate_down!'
# ./spec/support/helpers/migrations_helpers.rb:128:in `disable_migrations_output'
# ./spec/support/helpers/migrations_helpers.rb:107:in `schema_migrate_down!'
# ./spec/support/migration.rb:16:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# PG::InvalidTextRepresentation:
# ERROR: invalid input syntax for integer: "incident"
# LINE 1: ...."id" FROM "issues" WHERE "issues"."issue_type" = 'incident'...
# ^
# ./app/models/concerns/each_batch.rb:61:in `each_batch'
2) CapDesignsFilenameLengthToNewLimit runs after filename limit has been set
Failure/Error: start = start.take
StandardError:
An error has occurred, all later migrations canceled:
PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "incident"
LINE 1: ...."id" FROM "issues" WHERE "issues"."issue_type" = 'incident'...
^
# ./app/models/concerns/each_batch.rb:61:in `each_batch'
# ./db/post_migrate/20200723040950_migrate_incident_issues_to_incident_type.rb:43:in `down'
# ./spec/support/helpers/migrations_helpers.rb:108:in `block in schema_migrate_down!'
# ./spec/support/helpers/migrations_helpers.rb:128:in `disable_migrations_output'
# ./spec/support/helpers/migrations_helpers.rb:107:in `schema_migrate_down!'
# ./spec/support/migration.rb:16:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# PG::InvalidTextRepresentation:
# ERROR: invalid input syntax for integer: "incident"
# LINE 1: ...."id" FROM "issues" WHERE "issues"."issue_type" = 'incident'...
# ^
# ./app/models/concerns/each_batch.rb:61:in `each_batch'
Finished in 14 minutes 31 seconds (files took 33.12 seconds to load)
138 examples, 2 failures, 1 error occurred outside of examples
Failed examples:
rspec ./spec/migrations/cap_designs_filename_length_to_new_limit_spec.rb:34 # CapDesignsFilenameLengthToNewLimit correctly sets filenames that are above the limit
rspec ./spec/migrations/cap_designs_filename_length_to_new_limit_spec.rb:50 # CapDesignsFilenameLengthToNewLimit runs after filename limit has been set
SimpleCov failed with exit 1
Uploading artifacts for failed job
I haven't been able to reproduce this locally, but it's odd that the enum
value of 1 isn't being used here, and the string incident
is:
enum issue_type: {
issue: 0,
incident: 1
}
<snip>
def up
incident_issues = Issue.incident_labelled
incident_issues.each_batch(of: BATCH_SIZE) do |batch|
batch.update_all(issue_type: :incident)
end
https://gitlab.com/gitlab-org/gitlab/-/jobs/1094561410 has a similar error but on a different spec.
Edited by Stan Hu