summaryrefslogtreecommitdiff
path: root/makima/migrations/20250110000000_create_owners_table.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/20250110000000_create_owners_table.sql
parentf79c416c58557d2f946aa5332989afdfa8c021cd (diff)
downloadsoryu-8b17a175c3e7e27b789812eba4e3cd760beadb10.tar.gz
soryu-8b17a175c3e7e27b789812eba4e3cd760beadb10.zip
Initial Control system
Diffstat (limited to 'makima/migrations/20250110000000_create_owners_table.sql')
-rw-r--r--makima/migrations/20250110000000_create_owners_table.sql25
1 files changed, 25 insertions, 0 deletions
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)';