deckhearth/migrations/1780378340194_system-collection-description.js
varutasu e78f78e3f6
ci: run migrations against Postgres service container in CI (#64)
* ci: run migrations against Postgres service container in CI

Add a migrate job that applies node-pg-migrate against an ephemeral
Postgres 16 service container so broken migrations fail at PR time.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(migrations): retimestamp scan tables after initial-schema.

Fresh CI/postgres runs failed because 1748365200000 sorted before
initial-schema. Renamed to 1779853647566 with IF NOT EXISTS guards intact.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(migrations): ensure is_system_collection exists before description backfill.

Fresh CI Postgres runs initial-schema without this column (added historically
via scripts); ADD COLUMN IF NOT EXISTS makes the data migration safe on new
and existing envs.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 11:01:18 -05:00

34 lines
1 KiB
JavaScript

/**
* Backfill system collection descriptions to match VOCAB.SYSTEM_COLLECTION_SEED_DESCRIPTION
* in lib/collection-vocabulary.js (pick-a-name / collection-vocabulary convoy).
*
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
*/
export const shorthands = undefined;
/**
* @param pgm {import('node-pg-migrate').MigrationBuilder}
* @param run {() => void | undefined}
* @returns {Promise<void> | void}
*/
export const up = (pgm) => {
pgm.sql(`
ALTER TABLE collections
ADD COLUMN IF NOT EXISTS is_system_collection BOOLEAN DEFAULT false;
UPDATE collections
SET description = 'Automatically syncs with My Collection. This list cannot be deleted or made public.'
WHERE is_system_collection = true
`);
};
/**
* Irreversible — prior description text is not preserved.
*
* @param pgm {import('node-pg-migrate').MigrationBuilder}
* @param run {() => void | undefined}
* @returns {Promise<void> | void}
*/
export const down = () => {
throw new Error('Irreversible data migration');
};