feat(12-01): add migration 0008 for offer tier schema + idempotent push script
- Hand-write 0008_offer_tier_schema.sql: additive ALTER TABLE ADD COLUMN IF NOT EXISTS for offer_macros/offer_micros, guarded DO-block CHECK constraint on tier_letter, CREATE TABLE IF NOT EXISTS offer_tier_services + index - Append journal entry for 0008_offer_tier_schema following the 0006 entry shape - Add scripts/push-12-offer-tier-schema.ts: idempotent push script with PRODUCTION DEPLOY NOTE — BLOCKING step for Plan 02 (SSH+docker exec) before Wave 3 query layer
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
-- Phase 12: Offer Editor — additive schema for tier designations, public pricing,
|
||||
-- archive flag, category/ticket dimensions, structured transformation promise, and
|
||||
-- tier<->services junction. All statements additive/idempotent. No drops/truncates
|
||||
-- (Data Safety LOCKED).
|
||||
|
||||
-- offer_macros: archive flag + short description + category/ticket dimensions +
|
||||
-- structured transformation promise
|
||||
ALTER TABLE offer_macros ADD COLUMN IF NOT EXISTS description text;
|
||||
ALTER TABLE offer_macros ADD COLUMN IF NOT EXISTS category text;
|
||||
ALTER TABLE offer_macros ADD COLUMN IF NOT EXISTS ticket text;
|
||||
ALTER TABLE offer_macros ADD COLUMN IF NOT EXISTS is_archived boolean NOT NULL DEFAULT false;
|
||||
ALTER TABLE offer_macros ADD COLUMN IF NOT EXISTS cliente_ideale text;
|
||||
ALTER TABLE offer_macros ADD COLUMN IF NOT EXISTS risultato text;
|
||||
ALTER TABLE offer_macros ADD COLUMN IF NOT EXISTS tempo text;
|
||||
ALTER TABLE offer_macros ADD COLUMN IF NOT EXISTS pain text;
|
||||
ALTER TABLE offer_macros ADD COLUMN IF NOT EXISTS metodo text;
|
||||
|
||||
-- offer_micros: tier designation (A/B/C) + manual public price
|
||||
ALTER TABLE offer_micros ADD COLUMN IF NOT EXISTS tier_letter text;
|
||||
ALTER TABLE offer_micros ADD COLUMN IF NOT EXISTS public_price numeric(10, 2);
|
||||
|
||||
-- CHECK constraint for tier_letter, added separately so the ADD COLUMN above stays
|
||||
-- idempotent even if the constraint already exists (guarded via DO block).
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint WHERE conname = 'offer_micros_tier_letter_check'
|
||||
) THEN
|
||||
ALTER TABLE offer_micros
|
||||
ADD CONSTRAINT offer_micros_tier_letter_check
|
||||
CHECK (tier_letter IS NULL OR tier_letter IN ('A', 'B', 'C'));
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- New junction table: tier (offer_micros) <-> unified services catalog.
|
||||
-- Additive replacement for legacy offer_micro_services (untouched, points to offer_services).
|
||||
CREATE TABLE IF NOT EXISTS offer_tier_services (
|
||||
tier_id text NOT NULL REFERENCES offer_micros(id) ON DELETE CASCADE,
|
||||
service_id text NOT NULL REFERENCES services(id) ON DELETE CASCADE,
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
PRIMARY KEY (tier_id, service_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS offer_tier_services_tier_idx ON offer_tier_services USING btree (tier_id);
|
||||
@@ -22,6 +22,13 @@
|
||||
"when": 1781442000000,
|
||||
"tag": "0006_add_tags_table",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 8,
|
||||
"version": "7",
|
||||
"when": 1781700000000,
|
||||
"tag": "0008_offer_tier_schema",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user