-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema-institutional.sql
More file actions
55 lines (49 loc) · 1.7 KB
/
Copy pathschema-institutional.sql
File metadata and controls
55 lines (49 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- Institutional Admin & Multi-Tenancy Schema Migration
-- Run after existing schema.sql
-- 1. Recreate organizations table with expanded fields
DROP TABLE IF EXISTS organizations;
CREATE TABLE IF NOT EXISTS organizations (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
slug TEXT UNIQUE NOT NULL,
owner_id TEXT NOT NULL,
tier TEXT DEFAULT 'free',
max_seats INTEGER DEFAULT 10,
used_seats INTEGER DEFAULT 0,
sector TEXT DEFAULT NULL,
logo_url TEXT DEFAULT NULL,
domain TEXT DEFAULT NULL,
settings TEXT DEFAULT '{}',
created_at TEXT DEFAULT (datetime('now')),
FOREIGN KEY (owner_id) REFERENCES users(id)
);
-- 2. Org invites table
CREATE TABLE IF NOT EXISTS org_invites (
id TEXT PRIMARY KEY,
org_id TEXT NOT NULL,
email TEXT NOT NULL,
role TEXT DEFAULT 'member',
tier TEXT DEFAULT NULL,
invited_by TEXT NOT NULL,
status TEXT DEFAULT 'pending',
created_at TEXT DEFAULT (datetime('now')),
FOREIGN KEY (org_id) REFERENCES organizations(id),
FOREIGN KEY (invited_by) REFERENCES users(id)
);
-- 3. Org pricing table
CREATE TABLE IF NOT EXISTS org_pricing (
id TEXT PRIMARY KEY,
org_id TEXT NOT NULL UNIQUE,
plan TEXT NOT NULL DEFAULT 'starter',
seats_purchased INTEGER NOT NULL DEFAULT 10,
price_per_seat REAL NOT NULL DEFAULT 50.0,
billing_cycle TEXT DEFAULT 'monthly',
billing_started_at TEXT DEFAULT (datetime('now')),
billing_expires_at TEXT DEFAULT NULL,
custom_terms TEXT DEFAULT NULL,
FOREIGN KEY (org_id) REFERENCES organizations(id)
);
-- 4. Add org_id to announcements for org-scoped announcements
ALTER TABLE announcements ADD COLUMN org_id TEXT DEFAULT NULL;
-- 5. Add org_id to agents for org-scoped agents
ALTER TABLE agents ADD COLUMN org_id TEXT DEFAULT NULL;