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 <cursoragent@cursor.com>
This commit is contained in:
varutasu 2026-08-14 20:32:10 -05:00 committed by GitHub
parent c52891a6b2
commit f6305f96f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 6 deletions

View file

@ -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);
`);
};

View file

@ -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`.
*

View file

@ -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');
};