Files
tsumugu/backend/migrations/20261019T120000Z_source_storage.sql
T
LarsandCursor d6b70d8f92
Deploy Development / deploy (push) Successful in 28s
Test Suite / pytest-backend (push) Failing after 2m18s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 10s
Schließe die Connector-Kapselung ab, damit Paperless, IMAP und weitere Quellen über dieselbe Anbindung laufen.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-19 15:00:50 +02:00

67 lines
2.6 KiB
SQL

-- Source instance binding and opaque storage generation.
-- Connector ids are not a foreign key: deleting an access must not
-- retarget or remove an existing reference.
-- The legacy root path is bound in the migrator, not in this file.
CREATE TABLE storage_instances (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
kind text NOT NULL,
generation text NOT NULL,
root_path text,
created_at timestamptz NOT NULL DEFAULT now(),
CONSTRAINT storage_instances_kind CHECK (kind IN ('local')),
CONSTRAINT storage_instances_generation UNIQUE (generation),
CONSTRAINT storage_instances_generation_len CHECK (char_length(generation) BETWEEN 1 AND 80)
);
ALTER TABLE media_assets
ADD COLUMN storage_instance_id uuid REFERENCES storage_instances (id),
ADD COLUMN storage_generation text,
ADD COLUMN object_key text,
ADD COLUMN content_revision text,
ADD COLUMN protection_profile text NOT NULL DEFAULT 'legacy-plaintext',
ADD COLUMN key_responsibility text NOT NULL DEFAULT 'none',
ADD CONSTRAINT media_assets_protection CHECK (
protection_profile IN ('legacy-plaintext', 'managed-encrypted', 'client-encrypted')
),
ADD CONSTRAINT media_assets_key_responsibility CHECK (
key_responsibility IN ('none', 'operator', 'client')
);
ALTER TABLE dispatch_snapshots
ADD COLUMN storage_instance_id uuid REFERENCES storage_instances (id),
ADD COLUMN storage_generation text,
ADD COLUMN object_key text,
ADD COLUMN content_revision text,
ADD COLUMN protection_profile text NOT NULL DEFAULT 'legacy-plaintext',
ADD COLUMN key_responsibility text NOT NULL DEFAULT 'none',
ADD CONSTRAINT dispatch_snapshots_protection CHECK (
protection_profile IN ('legacy-plaintext', 'managed-encrypted', 'client-encrypted')
),
ADD CONSTRAINT dispatch_snapshots_key_responsibility CHECK (
key_responsibility IN ('none', 'operator', 'client')
);
UPDATE media_assets
SET storage_generation = 'legacy-local-1',
object_key = id::text,
content_revision = id::text,
protection_profile = 'legacy-plaintext',
key_responsibility = 'none'
WHERE object_key IS NULL;
UPDATE dispatch_snapshots
SET storage_generation = 'legacy-local-1',
object_key = 'dispatch/' || id::text,
content_revision = id::text,
protection_profile = 'legacy-plaintext',
key_responsibility = 'none'
WHERE object_key IS NULL;
ALTER TABLE external_references
ADD COLUMN connector_id uuid,
ADD COLUMN resolution text NOT NULL DEFAULT 'unresolved',
ADD CONSTRAINT external_references_resolution CHECK (
resolution IN ('bound', 'ambiguous', 'unresolved', 'none')
);