Centralize durable schema migration ownership
This commit is contained in:
parent
cc328237f4
commit
069f3813ae
2 changed files with 354 additions and 350 deletions
|
|
@ -0,0 +1,40 @@
|
|||
CREATE TABLE result_inventories (
|
||||
attempt_id TEXT PRIMARY KEY,
|
||||
state TEXT NOT NULL DEFAULT 'open' CHECK (state IN ('open', 'closed', 'sealed')),
|
||||
manifest_schema_version INTEGER,
|
||||
manifest_id TEXT,
|
||||
manifest_store TEXT,
|
||||
manifest_bucket TEXT,
|
||||
manifest_key TEXT,
|
||||
manifest_version_id TEXT,
|
||||
manifest_sha256 TEXT,
|
||||
manifest_size BIGINT,
|
||||
member_count BIGINT NOT NULL DEFAULT 0 CHECK (member_count >= 0),
|
||||
total_bytes BIGINT NOT NULL DEFAULT 0 CHECK (total_bytes >= 0),
|
||||
CHECK (
|
||||
(state <> 'sealed' AND manifest_schema_version IS NULL AND manifest_id IS NULL
|
||||
AND manifest_store IS NULL AND manifest_bucket IS NULL AND manifest_key IS NULL
|
||||
AND manifest_version_id IS NULL AND manifest_sha256 IS NULL AND manifest_size IS NULL)
|
||||
OR
|
||||
(state = 'sealed' AND manifest_schema_version IS NOT NULL AND manifest_id IS NOT NULL
|
||||
AND manifest_store IS NOT NULL AND manifest_bucket IS NOT NULL AND manifest_key IS NOT NULL
|
||||
AND manifest_sha256 IS NOT NULL AND manifest_size IS NOT NULL)
|
||||
)
|
||||
);
|
||||
|
||||
CREATE TABLE result_inventory_members (
|
||||
attempt_id TEXT NOT NULL REFERENCES result_inventories(attempt_id) ON DELETE CASCADE,
|
||||
member_id TEXT COLLATE "C" NOT NULL,
|
||||
path TEXT COLLATE "C" NOT NULL,
|
||||
size BIGINT NOT NULL CHECK (size >= 0),
|
||||
object_store TEXT NOT NULL,
|
||||
object_bucket TEXT NOT NULL,
|
||||
object_key TEXT NOT NULL,
|
||||
object_version_id TEXT,
|
||||
object_sha256 TEXT NOT NULL,
|
||||
PRIMARY KEY (attempt_id, member_id),
|
||||
UNIQUE (attempt_id, path)
|
||||
);
|
||||
|
||||
CREATE INDEX result_inventory_members_order_idx
|
||||
ON result_inventory_members (attempt_id, path, member_id);
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
ALTER TABLE result_inventory_members
|
||||
DROP CONSTRAINT result_inventory_members_attempt_id_fkey,
|
||||
ADD CONSTRAINT result_inventory_members_attempt_id_fkey
|
||||
FOREIGN KEY (attempt_id)
|
||||
REFERENCES result_inventories (attempt_id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE
|
||||
DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
ALTER TABLE result_inventories
|
||||
ADD COLUMN staging_origin_attempt_id TEXT,
|
||||
ADD COLUMN target_prefix TEXT,
|
||||
ADD CONSTRAINT result_inventories_staging_binding_check CHECK (
|
||||
(staging_origin_attempt_id IS NULL) = (target_prefix IS NULL)
|
||||
);
|
||||
|
||||
UPDATE result_inventories
|
||||
SET staging_origin_attempt_id = attempt_id,
|
||||
target_prefix = '';
|
||||
Loading…
Reference in a new issue