summaryrefslogtreecommitdiff
path: root/makima/migrations/20250110000006_add_owner_foreign_keys.sql
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-01-06 04:08:11 +0000
committersoryu <soryu@soryu.co>2026-01-11 03:01:13 +0000
commit8b17a175c3e7e27b789812eba4e3cd760beadb10 (patch)
tree7864dcaa2fa9db47fdfd4e8bfdb0b1dde832aa33 /makima/migrations/20250110000006_add_owner_foreign_keys.sql
parentf79c416c58557d2f946aa5332989afdfa8c021cd (diff)
downloadsoryu-8b17a175c3e7e27b789812eba4e3cd760beadb10.tar.gz
soryu-8b17a175c3e7e27b789812eba4e3cd760beadb10.zip
Initial Control system
Diffstat (limited to 'makima/migrations/20250110000006_add_owner_foreign_keys.sql')
-rw-r--r--makima/migrations/20250110000006_add_owner_foreign_keys.sql30
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);