pub const POSTGRES_MIGRATION_SQL: &str = "-- Reference schema for baukit-sync.\n--\n-- Copy this file into the product\'s own ordered migrations. Products own\n-- migration execution; baukit-sync deliberately does not migrate on startup.\n--\n-- Replace `owner_id`\'s REFERENCES clause with the product\'s own owner table.\n-- Baukit does not own that table and cannot name it here.\n\nCREATE TABLE sync_revisions (\n owner_id UUID PRIMARY KEY,\n last_revision BIGINT NOT NULL DEFAULT 0 CHECK (last_revision >= 0)\n);\n\nCOMMENT ON TABLE sync_revisions IS\n \'Per-owner monotonic revision counter allocated by baukit-sync::next_revision\';\n\n-- Every syncable table carries these four columns:\n--\n-- id UUID PRIMARY KEY,\n-- owner_id UUID NOT NULL REFERENCES <owner table>(id),\n-- updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),\n-- deleted_at TIMESTAMPTZ,\n-- revision BIGINT NOT NULL\n--\n-- `deleted_at` makes deletion a tombstone rather than a row removal, so a pull\n-- can deliver the deletion to clients that have not seen it yet. `revision` is\n-- allocated by `next_revision` in the same transaction as the row write, and\n-- every syncable table needs this index so an incremental pull is a range scan\n-- rather than a sort:\n--\n-- CREATE INDEX <table>_sync_idx ON <table> (owner_id, revision);\n--\n-- The example below is the shape to copy, not a table to create as-is.\n--\n-- CREATE TABLE product_records (\n-- id UUID PRIMARY KEY,\n-- owner_id UUID NOT NULL REFERENCES users (id),\n-- updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),\n-- deleted_at TIMESTAMPTZ,\n-- revision BIGINT NOT NULL\n-- );\n-- CREATE INDEX product_records_sync_idx ON product_records (owner_id, revision);\n";Expand description
Reference PostgreSQL schema and column convention for product migrations.
Copy this SQL into a product migration; do not execute it dynamically during application startup.