Skip to content

fix: create missing restricted-word sequences on a fresh database - #2053

Closed
panish16 wants to merge 1 commit into
bcgov:mainfrom
panish16:fix/restricted-word-migration-fresh-db
Closed

panish16 wants to merge 1 commit into
bcgov:mainfrom
panish16:fix/restricted-word-migration-fresh-db

Conversation

@panish16

Copy link
Copy Markdown
Collaborator

Issue #, if available: follow-up to #2050 / #2051 (#31439)

Description of changes:
api unit-testing has been red on main since #2050. Every test errors in setup with relation "restricted_condition_cnd_id_seq" does not exist (373 errors, 0 run), so no api PR gets a real test signal right now (e.g. #2052).

Cause: migration c4e8a1b27f09 sets nextval('restricted_condition_cnd_id_seq') / restricted_word_word_id_seq as column defaults, but nothing in the migration history creates those sequences (the 2018 add_restricted_word_tables revision only made restricted_condition_id). They exist in the real dbs, so dev migrated fine, but a fresh db (CI, local) blows up.

Fix: before repairing each id column, create the sequence only if it's missing and setval it past the current max id. Same pattern 4c33aac6da67 / 472b3fcc1288 already use.

  • dbs that have the sequence: no-op
  • dev already ran this revision, so alembic won't run it again there
  • revision id and the rest of the SQL unchanged
  • version bump 1.3.2 / 1.50.7

Testing:

  • full api suite on a fresh postgres 15 db with this change: 373 passed, 367 skipped, alembic at head 472b3fcc1288, both sequences created
  • without the change, same setup fails exactly like CI does
  • ruff passes

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the namex license (Apache 2.0).

Migration c4e8a1b27f09 assumed restricted_condition_cnd_id_seq and
restricted_word_word_id_seq exist. They do in dev/test/prod, but the
migration history never creates them, so a fresh database (CI, local)
fails and every api unit test errors in setup. Create each sequence only
when missing and set it past the current max id.
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant