diff options
Diffstat (limited to 'makima/migrations/20250110000006_add_owner_foreign_keys.sql')
| -rw-r--r-- | makima/migrations/20250110000006_add_owner_foreign_keys.sql | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/makima/migrations/20250110000006_add_owner_foreign_keys.sql b/makima/migrations/20250110000006_add_owner_foreign_keys.sql new file mode 100644 index 0000000..c4fb53a --- /dev/null +++ b/makima/migrations/20250110000006_add_owner_foreign_keys.sql @@ -0,0 +1,30 @@ +-- Add foreign key constraints to existing tables +-- This links all data to the owners table +-- NOTE: This migration depends on placeholder owners existing (migration 005) + +-- Files table +ALTER TABLE files + ADD CONSTRAINT fk_files_owner + FOREIGN KEY (owner_id) REFERENCES owners(id); + +-- Tasks table +ALTER TABLE tasks + ADD CONSTRAINT fk_tasks_owner + FOREIGN KEY (owner_id) REFERENCES owners(id); + +-- Daemons table +ALTER TABLE daemons + ADD CONSTRAINT fk_daemons_owner + FOREIGN KEY (owner_id) REFERENCES owners(id); + +-- Mesh chat conversations table +ALTER TABLE mesh_chat_conversations + ADD CONSTRAINT fk_mesh_chat_conversations_owner + FOREIGN KEY (owner_id) REFERENCES owners(id); + +-- Verify indexes exist (they should from original migrations) +-- If not, add them for query performance: +CREATE INDEX IF NOT EXISTS idx_files_owner_id ON files(owner_id); +CREATE INDEX IF NOT EXISTS idx_tasks_owner_id ON tasks(owner_id); +CREATE INDEX IF NOT EXISTS idx_daemons_owner_id ON daemons(owner_id); +CREATE INDEX IF NOT EXISTS idx_mesh_chat_conversations_owner_id ON mesh_chat_conversations(owner_id); |
