fix: a rollback never stops the database from starting; schema changes are migration files
schema.sql dropped and re-added three CHECK constraints on every start, so an older image narrowed the lists and failed on rows written by a newer one (an Expedição user, for example). They are now created only when missing, and app/migrate.py applies timestamped files from app/migrations/ once each, recording them in dtf_local.migrations; an older image skips names it does not know. The first migration sets today's full lists. A CI step rehearses the rollback on the real database inside a rolled-back transaction. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -286,9 +286,16 @@ CREATE TABLE IF NOT EXISTS dtf_local.cnpj_names (
|
||||
-- the printed sheet and are the only ones to release it to Finalizado;
|
||||
-- vendedores only read; expedição assembles sheets in the Kanban's montador.
|
||||
ALTER TABLE dtf_local.operators ADD COLUMN IF NOT EXISTS role text NOT NULL DEFAULT 'admin';
|
||||
ALTER TABLE dtf_local.operators DROP CONSTRAINT IF EXISTS operators_role;
|
||||
ALTER TABLE dtf_local.operators ADD CONSTRAINT operators_role
|
||||
CHECK (role IN ('superadmin','admin','gestao','designer','operador','revisor','vendedor','financeiro','expedicao'));
|
||||
-- Created once, and widened only by a migration: re-adding it on every start
|
||||
-- would let an older image narrow the list and refuse rows written under a
|
||||
-- later one, and the database would not finish starting.
|
||||
DO $$ BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='operators_role'
|
||||
AND conrelid='dtf_local.operators'::regclass) THEN
|
||||
ALTER TABLE dtf_local.operators ADD CONSTRAINT operators_role
|
||||
CHECK (role IN ('superadmin','admin','gestao','designer','operador','revisor','vendedor','financeiro','expedicao'));
|
||||
END IF;
|
||||
END $$;
|
||||
-- Print machines and which products each prints. An order gets its machine
|
||||
-- when someone pulls it into Imprimindo; no machine is assigned at payment.
|
||||
-- limit_metres remains the load shown for a machine.
|
||||
@@ -410,11 +417,16 @@ UPDATE dtf_local.accounts a SET email_verified=true WHERE NOT a.email_verified A
|
||||
-- E-mail kinds: a password-recovery link, a code, the notice that an account
|
||||
-- already exists, the notice of a changed e-mail, a customer's paid order,
|
||||
-- the team's alerts and a test.
|
||||
-- Defined once, here: the schema runs on every start, and an earlier, narrower
|
||||
-- copy would refuse the rows of the kinds added after it.
|
||||
ALTER TABLE dtf_local.mail_queue DROP CONSTRAINT IF EXISTS mail_queue_kind_check;
|
||||
ALTER TABLE dtf_local.mail_queue ADD CONSTRAINT mail_queue_kind_check
|
||||
CHECK(kind IN ('reset','code','account','notice','order','alert','test'));
|
||||
-- Created once, and widened only by a migration: the schema runs on every
|
||||
-- start, and re-adding an earlier, narrower copy would refuse the rows of the
|
||||
-- kinds added after it.
|
||||
DO $$ BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='mail_queue_kind_check'
|
||||
AND conrelid='dtf_local.mail_queue'::regclass) THEN
|
||||
ALTER TABLE dtf_local.mail_queue ADD CONSTRAINT mail_queue_kind_check
|
||||
CHECK(kind IN ('reset','code','account','notice','order','alert','test'));
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- The print proof (Dropstar, 2026-10-21): an order above 10 m, or one whose
|
||||
-- customer asked for a proof at checkout, prints 20 cm first; the room marks
|
||||
@@ -452,8 +464,13 @@ WHERE o.contact_since IS NOT NULL AND NOT EXISTS (SELECT 1 FROM dtf_local.contac
|
||||
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS origin text;
|
||||
UPDATE dtf_local.orders SET origin='site' WHERE origin IS NULL;
|
||||
ALTER TABLE dtf_local.orders ALTER COLUMN origin SET NOT NULL;
|
||||
ALTER TABLE dtf_local.orders DROP CONSTRAINT IF EXISTS orders_origin_check;
|
||||
ALTER TABLE dtf_local.orders ADD CONSTRAINT orders_origin_check CHECK (origin IN ('site','dropflow','atendimento'));
|
||||
-- Created once, and widened only by a migration; never re-added on start.
|
||||
DO $$ BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname='orders_origin_check'
|
||||
AND conrelid='dtf_local.orders'::regclass) THEN
|
||||
ALTER TABLE dtf_local.orders ADD CONSTRAINT orders_origin_check CHECK (origin IN ('site','dropflow','atendimento'));
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Rework (Dropstar's rules D-02 to D-04, 2026-10-26; the user's answers of
|
||||
-- 2026-10-27). Gestão opens it with its cause, and the cause never changes
|
||||
|
||||
Reference in New Issue
Block a user