summaryrefslogtreecommitdiff
path: root/makima/migrations/20250110000008_remove_owner_defaults.sql
diff options
context:
space:
mode:
Diffstat (limited to 'makima/migrations/20250110000008_remove_owner_defaults.sql')
-rw-r--r--makima/migrations/20250110000008_remove_owner_defaults.sql46
1 files changed, 46 insertions, 0 deletions
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';