fix: make files initial migration idempotent
Some checks failed
CI / hygiene (push) Successful in 1s
Build and Deploy / build-and-deploy (push) Failing after 4m16s
CI / test (push) Successful in 18s

This commit is contained in:
Grendgi
2026-06-16 13:12:34 +03:00
parent 5d721186cd
commit 79eac4d251

View File

@@ -1,6 +1,6 @@
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE files_nodes (
CREATE TABLE IF NOT EXISTS files_nodes (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
parent_id UUID REFERENCES files_nodes(id) ON DELETE CASCADE,
node_type TEXT NOT NULL CHECK (node_type IN ('folder', 'file', 'google_sheet', 'office_document')),
@@ -25,11 +25,11 @@ CREATE TABLE files_nodes (
)
);
CREATE INDEX files_nodes_parent_idx ON files_nodes(parent_id) WHERE deleted_at IS NULL;
CREATE INDEX files_nodes_owner_idx ON files_nodes(owner_user_id) WHERE deleted_at IS NULL;
CREATE INDEX files_nodes_type_idx ON files_nodes(node_type) WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS files_nodes_parent_idx ON files_nodes(parent_id) WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS files_nodes_owner_idx ON files_nodes(owner_user_id) WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS files_nodes_type_idx ON files_nodes(node_type) WHERE deleted_at IS NULL;
CREATE TABLE files_access (
CREATE TABLE IF NOT EXISTS files_access (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
node_id UUID NOT NULL REFERENCES files_nodes(id) ON DELETE CASCADE,
user_id UUID NOT NULL,
@@ -39,10 +39,10 @@ CREATE TABLE files_access (
UNIQUE (node_id, user_id)
);
CREATE INDEX files_access_node_idx ON files_access(node_id);
CREATE INDEX files_access_user_idx ON files_access(user_id);
CREATE INDEX IF NOT EXISTS files_access_node_idx ON files_access(node_id);
CREATE INDEX IF NOT EXISTS files_access_user_idx ON files_access(user_id);
CREATE TABLE files_public_links (
CREATE TABLE IF NOT EXISTS files_public_links (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
node_id UUID NOT NULL REFERENCES files_nodes(id) ON DELETE CASCADE,
token_hash TEXT NOT NULL UNIQUE,
@@ -53,10 +53,10 @@ CREATE TABLE files_public_links (
revoked_at TIMESTAMPTZ
);
CREATE INDEX files_public_links_node_idx ON files_public_links(node_id);
CREATE INDEX files_public_links_active_idx ON files_public_links(token_hash, expires_at) WHERE revoked_at IS NULL;
CREATE INDEX IF NOT EXISTS files_public_links_node_idx ON files_public_links(node_id);
CREATE INDEX IF NOT EXISTS files_public_links_active_idx ON files_public_links(token_hash, expires_at) WHERE revoked_at IS NULL;
CREATE TABLE files_audit_events (
CREATE TABLE IF NOT EXISTS files_audit_events (
id BIGSERIAL PRIMARY KEY,
actor_user_id UUID,
action TEXT NOT NULL,
@@ -66,6 +66,5 @@ CREATE TABLE files_audit_events (
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX files_audit_events_actor_idx ON files_audit_events(actor_user_id, created_at DESC);
CREATE INDEX files_audit_events_entity_idx ON files_audit_events(entity_type, entity_id, created_at DESC);
CREATE INDEX IF NOT EXISTS files_audit_events_actor_idx ON files_audit_events(actor_user_id, created_at DESC);
CREATE INDEX IF NOT EXISTS files_audit_events_entity_idx ON files_audit_events(entity_type, entity_id, created_at DESC);