| Table | Index Name | Columns | Type | Query Pattern Served |
|---|---|---|---|---|
documents |
idx_docs_workspace_updated |
(workspace_id, updated_at DESC) WHERE deleted_at IS NULL |
Partial B-Tree | Dashboard recent files list |
document_revisions |
uq_revisions_doc_ver |
(document_id, version_number) |
Unique B-Tree | Optimistic concurrency & history lookup |
share_links |
uq_shares_short_slug |
(short_slug) |
Unique B-Tree | Public /s/:slug hot path |
share_links |
idx_shares_expires |
(expires_at) WHERE expires_at IS NOT NULL |
Partial B-Tree | Nightly expired-link cleanup job |
To migrate documents.owner_id to documents.workspace_id with zero downtime, execute across four deploy phases:
SET lock_timeout = '3s';
ALTER TABLE documents
ADD COLUMN workspace_id uuid;
CREATE INDEX CONCURRENTLY idx_docs_workspace_updated
ON documents (workspace_id, updated_at DESC)
WHERE deleted_at IS NULL;
owner_id and workspace_id on insert/update.5,000 with 100ms sleep between chunks.ALTER TABLE documents
ADD CONSTRAINT fk_documents_workspace
FOREIGN KEY (workspace_id) REFERENCES workspaces(id)
NOT VALID;
ALTER TABLE documents
VALIDATE CONSTRAINT fk_documents_workspace;
workspace_id.owner_id in a follow-up migration.EXPLAIN ANALYZE confirms index-only or index scan on hot queriesSELECT count(*) FROM documents WHERE workspace_id IS NULL; returns 0