|
| 1 | +CREATE TABLE "settings" ( |
| 2 | + "id" INTEGER PRIMARY KEY NOT NULL, |
| 3 | + "tenant_name" TEXT NOT NULL, |
| 4 | + "tenant_domain" TEXT NOT NULL, |
| 5 | + "created_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 6 | + "updated_at" DATETIME NOT NULL DEFAULT (datetime('now')) |
| 7 | +); |
| 8 | + |
| 9 | +-- References to DXTA organizations |
| 10 | +CREATE TABLE "organizations" ( |
| 11 | + "id" INTEGER PRIMARY KEY NOT NULL, |
| 12 | + "name" TEXT NOT NULL, |
| 13 | + "auth_id" TEXT DEFAULT NULL, -- From Better Auth |
| 14 | + "created_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 15 | + "updated_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 16 | + "deleted_at" DATETIME DEFAULT NULL |
| 17 | +); |
| 18 | + |
| 19 | +-- References to DXTA teams |
| 20 | +CREATE TABLE "teams" ( |
| 21 | + "id" INTEGER PRIMARY KEY NOT NULL, |
| 22 | + "name" TEXT NOT NULL, |
| 23 | + "organization_id" INTEGER NOT NULL, |
| 24 | + "created_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 25 | + "updated_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 26 | + "deleted_at" DATETIME DEFAULT NULL, |
| 27 | + FOREIGN KEY ("organization_id") references "organizations" ("id") |
| 28 | +); |
| 29 | + |
| 30 | +CREATE TABLE "members" ( |
| 31 | + "id" INTEGER PRIMARY KEY NOT NULL, |
| 32 | + "name" TEXT NOT NULL, |
| 33 | + "email" TEXT DEFAULT NULL, |
| 34 | + "created_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 35 | + "updated_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 36 | + "deleted_at" DATETIME DEFAULT NULL |
| 37 | +); |
| 38 | + |
| 39 | +CREATE TABLE "teams__members" ( |
| 40 | + "team_id" INTEGER NOT NULL, |
| 41 | + "member_id" INTEGER NOT NULL, |
| 42 | + "created_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 43 | + PRIMARY KEY ("team_id", "member_id"), |
| 44 | + FOREIGN KEY ("team_id") REFERENCES "teams" ("id"), |
| 45 | + FOREIGN KEY ("member_id") REFERENCES "members" ("id") |
| 46 | +); |
| 47 | + |
| 48 | +---------------------------------- Github ---------------------------------- |
| 49 | + |
| 50 | +CREATE TABLE "github_organizations" ( |
| 51 | + "id" INTEGER PRIMARY KEY NOT NULL, |
| 52 | + "external_id" INTEGER NOT NULL, |
| 53 | + "name" TEXT NOT NULL, |
| 54 | + "github_app_installation_id" INTEGER NOT NULL, |
| 55 | + "created_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 56 | + "updated_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 57 | + "deleted_at" DATETIME DEFAULT NULL |
| 58 | +); |
| 59 | + |
| 60 | +-- DXTA organizations to github organizations |
| 61 | +CREATE TABLE "organizations__github_organizations" ( |
| 62 | + "organization_id" INTEGER NOT NULL, |
| 63 | + "github_organization_id" INTEGER NOT NULL, |
| 64 | + "created_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 65 | + PRIMARY KEY ("organization_id", "github_organization_id"), |
| 66 | + FOREIGN KEY ("organization_id") REFERENCES "organizations" ("id"), |
| 67 | + FOREIGN KEY ("github_organization_id") REFERENCES "github_organizations" ("id") |
| 68 | +); |
| 69 | + |
| 70 | +CREATE TABLE "github_members" ( |
| 71 | + "id" INTEGER PRIMARY KEY NOT NULL, |
| 72 | + "external_id" INTEGER NOT NULL, |
| 73 | + "username" TEXT NOT NULL, |
| 74 | + "email" TEXT DEFAULT NULL, |
| 75 | + "member_id" INTEGER NULL, |
| 76 | + "created_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 77 | + "updated_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 78 | + "deleted_at" DATETIME DEFAULT NULL, |
| 79 | + FOREIGN KEY ("member_id") REFERENCES "members" ("id") |
| 80 | +); |
| 81 | + |
| 82 | +CREATE TABLE "github_teams" ( |
| 83 | + "id" INTEGER PRIMARY KEY NOT NULL, |
| 84 | + "external_id" INTEGER NOT NULL, |
| 85 | + "name" TEXT NOT NULL, |
| 86 | + "github_organization_id" INTEGER NOT NULL, |
| 87 | + "created_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 88 | + "updated_at" DATETIME NOT NULL DEFAULT (datetime('now')), |
| 89 | + "deleted_at" DATETIME DEFAULT NULL, |
| 90 | + FOREIGN KEY ("github_organization_id") references "github_organizations" ("id") |
| 91 | +); |
| 92 | + |
| 93 | +CREATE TABLE "github_teams__github_members" ( |
| 94 | + "github_team_id" INTEGER NOT NULL, |
| 95 | + "github_member_id" INTEGER NOT NULL, |
| 96 | + PRIMARY KEY ("github_team_id", "github_member_id"), |
| 97 | + FOREIGN KEY ("github_team_id") REFERENCES "github_teams" ("id"), |
| 98 | + FOREIGN KEY ("github_member_id") REFERENCES "github_members" ("id") |
| 99 | +); |
| 100 | + |
| 101 | +---------------------------------- Last updated at triggers ---------------------------------- |
| 102 | + |
| 103 | +CREATE TRIGGER "settings_set_updated_at" |
| 104 | +AFTER UPDATE ON "settings" |
| 105 | +FOR EACH ROW |
| 106 | +BEGIN |
| 107 | + UPDATE "settings" |
| 108 | + SET updated_at = datetime('now') |
| 109 | + WHERE id = OLD.id; |
| 110 | +END; |
| 111 | + |
| 112 | +CREATE TRIGGER "organizations_set_updated_at" |
| 113 | +AFTER UPDATE ON "organizations" |
| 114 | +FOR EACH ROW |
| 115 | +BEGIN |
| 116 | + UPDATE "organizations" |
| 117 | + SET updated_at = datetime('now') |
| 118 | + WHERE id = OLD.id; |
| 119 | +END; |
| 120 | + |
| 121 | +CREATE TRIGGER "teams_set_updated_at" |
| 122 | +AFTER UPDATE ON "teams" |
| 123 | +FOR EACH ROW |
| 124 | +BEGIN |
| 125 | + UPDATE "teams" |
| 126 | + SET updated_at = datetime('now') |
| 127 | + WHERE id = OLD.id; |
| 128 | +END; |
| 129 | + |
| 130 | +CREATE TRIGGER "members_set_updated_at" |
| 131 | +AFTER UPDATE ON "members" |
| 132 | +FOR EACH ROW |
| 133 | +BEGIN |
| 134 | + UPDATE "members" |
| 135 | + SET updated_at = datetime('now') |
| 136 | + WHERE id = OLD.id; |
| 137 | +END; |
| 138 | + |
| 139 | +CREATE TRIGGER "github_organizations_set_updated_at" |
| 140 | +AFTER UPDATE ON "github_organizations" |
| 141 | +FOR EACH ROW |
| 142 | +BEGIN |
| 143 | + UPDATE "github_organizations" |
| 144 | + SET updated_at = datetime('now') |
| 145 | + WHERE id = OLD.id; |
| 146 | +END; |
| 147 | + |
| 148 | +CREATE TRIGGER "github_members_set_updated_at" |
| 149 | +AFTER UPDATE ON "github_members" |
| 150 | +FOR EACH ROW |
| 151 | +BEGIN |
| 152 | + UPDATE "github_members" |
| 153 | + SET updated_at = datetime('now') |
| 154 | + WHERE id = OLD.id; |
| 155 | +END; |
| 156 | + |
| 157 | +CREATE TRIGGER "github_teams_set_updated_at" |
| 158 | +AFTER UPDATE ON "github_teams" |
| 159 | +FOR EACH ROW |
| 160 | +BEGIN |
| 161 | + UPDATE "github_teams" |
| 162 | + SET updated_at = datetime('now') |
| 163 | + WHERE id = OLD.id; |
| 164 | +END; |
0 commit comments