From 8b17a175c3e7e27b789812eba4e3cd760beadb10 Mon Sep 17 00:00:00 2001
From: soryu <soryu@soryu.co>
Date: Tue, 6 Jan 2026 04:08:11 +0000
Subject: Initial Control system

---
 .../20250110000008_remove_owner_defaults.sql       | 46 ++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 makima/migrations/20250110000008_remove_owner_defaults.sql

(limited to 'makima/migrations/20250110000008_remove_owner_defaults.sql')

diff --git a/makima/migrations/20250110000008_remove_owner_defaults.sql b/makima/migrations/20250110000008_remove_owner_defaults.sql
new file mode 100644
index 0000000..307f077
--- /dev/null
+++ b/makima/migrations/20250110000008_remove_owner_defaults.sql
@@ -0,0 +1,46 @@
+-- Remove default owner_id values from tables
+-- This should be done after application code is updated to always provide owner_id
+
+-- IMPORTANT: Only apply this migration after updating all code to provide owner_id
+-- Otherwise, inserts will fail
+
+-- Remove default values (they are no longer needed since code provides owner_id)
+ALTER TABLE files
+    ALTER COLUMN owner_id DROP DEFAULT;
+
+ALTER TABLE tasks
+    ALTER COLUMN owner_id DROP DEFAULT;
+
+ALTER TABLE daemons
+    ALTER COLUMN owner_id DROP DEFAULT;
+
+ALTER TABLE mesh_chat_conversations
+    ALTER COLUMN owner_id DROP DEFAULT;
+
+-- Make owner_id NOT NULL explicit (should already be, but ensure)
+-- Note: These columns were created with NOT NULL, so this is a no-op validation
+-- The SET NOT NULL will succeed if all existing rows have non-null values
+
+-- Files already has NOT NULL in original migration (20241222000000)
+-- Tasks already has NOT NULL in original migration (20250102000000)
+-- Daemons already has NOT NULL in original migration (20250102000000)
+-- Mesh chat conversations already has NOT NULL in original migration (20250104000000)
+
+-- However, we explicitly restate it for clarity and documentation
+ALTER TABLE files
+    ALTER COLUMN owner_id SET NOT NULL;
+
+ALTER TABLE tasks
+    ALTER COLUMN owner_id SET NOT NULL;
+
+ALTER TABLE daemons
+    ALTER COLUMN owner_id SET NOT NULL;
+
+ALTER TABLE mesh_chat_conversations
+    ALTER COLUMN owner_id SET NOT NULL;
+
+-- Add comments documenting the constraint
+COMMENT ON COLUMN files.owner_id IS 'Owner ID is required - no default value, must be provided by application';
+COMMENT ON COLUMN tasks.owner_id IS 'Owner ID is required - no default value, must be provided by application';
+COMMENT ON COLUMN daemons.owner_id IS 'Owner ID is required - no default value, must be provided by application';
+COMMENT ON COLUMN mesh_chat_conversations.owner_id IS 'Owner ID is required - no default value, must be provided by application';
-- 
cgit v1.2.3

