From f6305f96f2dbc4bb64fbacca1157b6113132298e Mon Sep 17 00:00:00 2001 From: varutasu <104105839+varutasu@users.noreply.github.com> Date: Fri, 14 Aug 2026 20:32:10 -0500 Subject: [PATCH] Stop CI migrate-up from indexing collections.visibility before the column exists. (#159) B3 ran before the B2 column add on a fresh database. Move the index to a later migration so collaboration tables still apply and the index lands after visibility is present. Co-authored-by: Cursor --- ...00000003_reconcile-collaboration-tables.js | 10 ++++-- ...442330002_reconcile-collections-columns.js | 8 +++-- ...312884_add-collections-visibility-index.js | 33 +++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 migrations/1786757312884_add-collections-visibility-index.js diff --git a/migrations/1781000000003_reconcile-collaboration-tables.js b/migrations/1781000000003_reconcile-collaboration-tables.js index 1f9c5ab..dee2fa7 100644 --- a/migrations/1781000000003_reconcile-collaboration-tables.js +++ b/migrations/1781000000003_reconcile-collaboration-tables.js @@ -7,7 +7,13 @@ * 1. `collection_permissions` (collaboration roles + invite tokens) * 2. `collection_activity` (audit-trail with JSONB details) * 3. `users.is_pending` (column for invited-but-not-yet-accepted users) - * 4. 4 indexes for query hot-paths + * 4. 3 indexes on the tables this migration creates + * + * `idx_collections_visibility` is NOT created here. This file's timestamp + * runs before `1781442330002_reconcile-collections-columns`, which is the + * migration that adds `collections.visibility`. Creating the index here + * fails on a fresh CI database (`column "visibility" does not exist`). + * The index ships in `1786757312884_add-collections-visibility-index`. * * `lib/permission-middleware.js` reads `collection_permissions` in * `withCollectionPermission` and writes `collection_activity` from @@ -74,8 +80,6 @@ export const up = (pgm) => { ON collection_permissions(user_id); CREATE INDEX IF NOT EXISTS idx_collection_activity_collection_id ON collection_activity(collection_id); - CREATE INDEX IF NOT EXISTS idx_collections_visibility - ON collections(visibility); `); }; diff --git a/migrations/1781442330002_reconcile-collections-columns.js b/migrations/1781442330002_reconcile-collections-columns.js index b8f7439..4e85e39 100644 --- a/migrations/1781442330002_reconcile-collections-columns.js +++ b/migrations/1781442330002_reconcile-collections-columns.js @@ -14,9 +14,11 @@ * * Excluded from B2 (out of scope per architect inventory): * - `collection_permissions`, `collection_activity`, `users.is_pending`, - * `idx_collections_visibility`, `idx_collection_permissions_*`, - * `idx_collection_activity_collection_id` — these belong to B3 - * (`reconcile-collaboration-tables`) per the architect plan. + * `idx_collection_permissions_*`, `idx_collection_activity_collection_id` + * — B3 (`reconcile-collaboration-tables`). + * `idx_collections_visibility` — ships in + * `1786757312884_add-collections-visibility-index` (B3's timestamp + * precedes this file's `visibility` column add). * - `is_system_collection` — already captured by * `migrations/1780378340194_system-collection-description.js`. * diff --git a/migrations/1786757312884_add-collections-visibility-index.js b/migrations/1786757312884_add-collections-visibility-index.js new file mode 100644 index 0000000..d656625 --- /dev/null +++ b/migrations/1786757312884_add-collections-visibility-index.js @@ -0,0 +1,33 @@ +/** + * Create `idx_collections_visibility` after `collections.visibility` exists. + * + * `1781000000003_reconcile-collaboration-tables` originally created this + * index, but that file's timestamp runs before + * `1781442330002_reconcile-collections-columns` adds the column. Fresh CI + * databases failed with `column "visibility" does not exist`. + * + * Idempotent: `IF NOT EXISTS` no-ops on envs where the historical + * collaboration script or the original B3 statement already built the index. + * + * @type {import('node-pg-migrate').ColumnDefinitions | undefined} + */ +export const shorthands = undefined; + +/** + * @param {import('node-pg-migrate').MigrationBuilder} pgm + * @returns {void} + */ +export const up = (pgm) => { + pgm.sql(` + CREATE INDEX IF NOT EXISTS idx_collections_visibility + ON collections(visibility); + `); +}; + +/** + * @param {import('node-pg-migrate').MigrationBuilder} pgm + * @returns {void} + */ +export const down = (pgm) => { + pgm.sql('DROP INDEX IF EXISTS idx_collections_visibility'); +};