feat(F-177): completed feature

This commit is contained in:
chattie
2026-08-22 18:54:41 +02:00
parent 4081462cc4
commit abdb03b6b5
17 changed files with 326 additions and 23 deletions

View File

@@ -0,0 +1,28 @@
/** @param {import('node-pg-migrate').MigrationBuilder} pgm */
exports.shorthands = undefined;
exports.up = (pgm) => {
pgm.sql(`
ALTER TABLE orders_orders
ADD COLUMN IF NOT EXISTS state_changed_at timestamptz;
UPDATE orders_orders
SET state_changed_at = updated_at
WHERE state_changed_at IS NULL;
ALTER TABLE orders_orders
ALTER COLUMN state_changed_at SET DEFAULT now(),
ALTER COLUMN state_changed_at SET NOT NULL;
CREATE INDEX IF NOT EXISTS orders_orders_stale_state_idx
ON orders_orders (state, state_changed_at)
WHERE state IN ('PENDING', 'SHIPPED');
`);
};
exports.down = (pgm) => {
pgm.sql(`
DROP INDEX IF EXISTS orders_orders_stale_state_idx;
ALTER TABLE orders_orders DROP COLUMN IF EXISTS state_changed_at;
`);
};