internal/store/migrations/0076_org_limits.up.sql

main
gitbay/internal/store/migrations/0076_org_limits.up.sql history · blame · raw

14 lines · 729 bytes

 1-- Quotas for organizations: limits.max_orgs_per_user counts orgs by the
 2-- account that created them; max_repos_per_org and max_bytes_per_org cap
 3-- each org, with per-org overrides. NULL means the configured default.
 4-- created_by carries no foreign key: ids are never reused (#306), and an
 5-- org outlives the account that made it.
 6ALTER TABLE orgs ADD COLUMN created_by INTEGER;
 7ALTER TABLE orgs ADD COLUMN repo_limit INTEGER;
 8ALTER TABLE orgs ADD COLUMN byte_limit INTEGER;
 9ALTER TABLE users ADD COLUMN org_limit INTEGER;
10UPDATE orgs SET created_by = (
11    SELECT m.user_id FROM org_members m
12    WHERE m.org_id = orgs.id AND m.role = 'admin'
13    ORDER BY m.rowid LIMIT 1);
14CREATE INDEX orgs_created_by ON orgs(created_by);