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

---
 .../20250110000000_create_owners_table.sql         | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 makima/migrations/20250110000000_create_owners_table.sql

(limited to 'makima/migrations/20250110000000_create_owners_table.sql')

diff --git a/makima/migrations/20250110000000_create_owners_table.sql b/makima/migrations/20250110000000_create_owners_table.sql
new file mode 100644
index 0000000..7b0d696
--- /dev/null
+++ b/makima/migrations/20250110000000_create_owners_table.sql
@@ -0,0 +1,25 @@
+-- Create owners table for multi-tenant support
+-- Owners are the logical entities that own resources (files, tasks, daemons)
+-- Users belong to owners via groups
+
+CREATE TABLE IF NOT EXISTS owners (
+    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+    name VARCHAR(255) NOT NULL,
+    -- 'personal' for individual users, 'organization' for teams
+    owner_type VARCHAR(32) NOT NULL DEFAULT 'personal',
+    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
+    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
+
+    CONSTRAINT valid_owner_type CHECK (owner_type IN ('personal', 'organization'))
+);
+
+CREATE INDEX idx_owners_owner_type ON owners(owner_type);
+
+-- Trigger to update updated_at timestamp (reuse existing function)
+CREATE TRIGGER update_owners_updated_at
+    BEFORE UPDATE ON owners
+    FOR EACH ROW
+    EXECUTE FUNCTION update_updated_at_column();
+
+COMMENT ON TABLE owners IS 'Logical entities that own resources. Users access owners via group membership.';
+COMMENT ON COLUMN owners.owner_type IS 'Type of owner: personal (single user) or organization (team)';
-- 
cgit v1.2.3

