From a908ca334c3c584e7aec73d431dc4f685ebfe549 Mon Sep 17 00:00:00 2001 From: Mark Mennell Date: Mon, 3 Aug 2026 20:45:02 +1000 Subject: [PATCH] Document dd.sql idempotency: migration is re-running the whole script Co-Authored-By: Claude Fable 5 --- dd.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dd.sql b/dd.sql index 735d2f2..4f6db9c 100644 --- a/dd.sql +++ b/dd.sql @@ -5,6 +5,16 @@ -- -- fmsg-webapi assumes fmsgd is the fmsg host implementation and uses the same -- PostgreSQL database. +-- +-- This script is IDEMPOTENT: every statement is safe to re-run (CREATE ... IF +-- NOT EXISTS, ALTER TABLE ... ADD COLUMN IF NOT EXISTS, DROP CONSTRAINT IF +-- EXISTS, guarded DO blocks). Migrating an existing database is therefore +-- just re-running the whole script, e.g.: +-- +-- psql -d fmsgd -v ON_ERROR_STOP=1 -f dd.sql +-- +-- Keep it that way: add new objects and columns only with idempotent +-- statements. CREATE TABLE IF NOT EXISTS fmsg_api_sub_account ( owner_addr varchar(255) NOT NULL,