feat(coord): DB migration — project-scoped missions, multi-tenant RBAC (#149)
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #149.
This commit is contained in:
29
packages/db/drizzle/0001_magical_rattler.sql
Normal file
29
packages/db/drizzle/0001_magical_rattler.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
CREATE TABLE "mission_tasks" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"mission_id" uuid NOT NULL,
|
||||
"task_id" uuid,
|
||||
"user_id" text NOT NULL,
|
||||
"status" text DEFAULT 'not-started' NOT NULL,
|
||||
"description" text,
|
||||
"notes" text,
|
||||
"pr" text,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "missions" ADD COLUMN "user_id" text;--> statement-breakpoint
|
||||
ALTER TABLE "missions" ADD COLUMN "phase" text;--> statement-breakpoint
|
||||
ALTER TABLE "missions" ADD COLUMN "milestones" jsonb;--> statement-breakpoint
|
||||
ALTER TABLE "missions" ADD COLUMN "config" jsonb;--> statement-breakpoint
|
||||
ALTER TABLE "users" ADD COLUMN "banned" boolean DEFAULT false;--> statement-breakpoint
|
||||
ALTER TABLE "users" ADD COLUMN "ban_reason" text;--> statement-breakpoint
|
||||
ALTER TABLE "users" ADD COLUMN "ban_expires" timestamp with time zone;--> statement-breakpoint
|
||||
ALTER TABLE "mission_tasks" ADD CONSTRAINT "mission_tasks_mission_id_missions_id_fk" FOREIGN KEY ("mission_id") REFERENCES "public"."missions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "mission_tasks" ADD CONSTRAINT "mission_tasks_task_id_tasks_id_fk" FOREIGN KEY ("task_id") REFERENCES "public"."tasks"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "mission_tasks" ADD CONSTRAINT "mission_tasks_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "mission_tasks_mission_id_idx" ON "mission_tasks" USING btree ("mission_id");--> statement-breakpoint
|
||||
CREATE INDEX "mission_tasks_task_id_idx" ON "mission_tasks" USING btree ("task_id");--> statement-breakpoint
|
||||
CREATE INDEX "mission_tasks_user_id_idx" ON "mission_tasks" USING btree ("user_id");--> statement-breakpoint
|
||||
CREATE INDEX "mission_tasks_status_idx" ON "mission_tasks" USING btree ("status");--> statement-breakpoint
|
||||
ALTER TABLE "missions" ADD CONSTRAINT "missions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "missions_user_id_idx" ON "missions" USING btree ("user_id");
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "a519a9b8-5882-4141-82e4-0b35be280738",
|
||||
"prevId": "ed7dea23-55fa-4f92-9256-7809a1e637f1",
|
||||
"id": "d1721c50-8da3-4cc5-9542-34d79f335541",
|
||||
"prevId": "a519a9b8-5882-4141-82e4-0b35be280738",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"tables": {
|
||||
@@ -833,6 +833,184 @@
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
},
|
||||
"public.mission_tasks": {
|
||||
"name": "mission_tasks",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"default": "gen_random_uuid()"
|
||||
},
|
||||
"mission_id": {
|
||||
"name": "mission_id",
|
||||
"type": "uuid",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"task_id": {
|
||||
"name": "task_id",
|
||||
"type": "uuid",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"status": {
|
||||
"name": "status",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'not-started'"
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"notes": {
|
||||
"name": "notes",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"pr": {
|
||||
"name": "pr",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "now()"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "now()"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"mission_tasks_mission_id_idx": {
|
||||
"name": "mission_tasks_mission_id_idx",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "mission_id",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": false,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
},
|
||||
"mission_tasks_task_id_idx": {
|
||||
"name": "mission_tasks_task_id_idx",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "task_id",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": false,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
},
|
||||
"mission_tasks_user_id_idx": {
|
||||
"name": "mission_tasks_user_id_idx",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "user_id",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": false,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
},
|
||||
"mission_tasks_status_idx": {
|
||||
"name": "mission_tasks_status_idx",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "status",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": false,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"mission_tasks_mission_id_missions_id_fk": {
|
||||
"name": "mission_tasks_mission_id_missions_id_fk",
|
||||
"tableFrom": "mission_tasks",
|
||||
"tableTo": "missions",
|
||||
"columnsFrom": [
|
||||
"mission_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"mission_tasks_task_id_tasks_id_fk": {
|
||||
"name": "mission_tasks_task_id_tasks_id_fk",
|
||||
"tableFrom": "mission_tasks",
|
||||
"tableTo": "tasks",
|
||||
"columnsFrom": [
|
||||
"task_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "set null",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"mission_tasks_user_id_users_id_fk": {
|
||||
"name": "mission_tasks_user_id_users_id_fk",
|
||||
"tableFrom": "mission_tasks",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"policies": {},
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
},
|
||||
"public.missions": {
|
||||
"name": "missions",
|
||||
"schema": "",
|
||||
@@ -869,6 +1047,30 @@
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"phase": {
|
||||
"name": "phase",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"milestones": {
|
||||
"name": "milestones",
|
||||
"type": "jsonb",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"config": {
|
||||
"name": "config",
|
||||
"type": "jsonb",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
@@ -905,6 +1107,21 @@
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
},
|
||||
"missions_user_id_idx": {
|
||||
"name": "missions_user_id_idx",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "user_id",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": false,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
@@ -920,6 +1137,19 @@
|
||||
],
|
||||
"onDelete": "set null",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"missions_user_id_users_id_fk": {
|
||||
"name": "missions_user_id_users_id_fk",
|
||||
"tableFrom": "missions",
|
||||
"tableTo": "users",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
@@ -1705,6 +1935,25 @@
|
||||
"notNull": true,
|
||||
"default": "'member'"
|
||||
},
|
||||
"banned": {
|
||||
"name": "banned",
|
||||
"type": "boolean",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": false
|
||||
},
|
||||
"ban_reason": {
|
||||
"name": "ban_reason",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"ban_expires": {
|
||||
"name": "ban_expires",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamp with time zone",
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
"when": 1773368153122,
|
||||
"tag": "0000_loud_ezekiel_stane",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "7",
|
||||
"when": 1773602195609,
|
||||
"tag": "0001_magical_rattler",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,9 @@ export const users = pgTable('users', {
|
||||
emailVerified: boolean('email_verified').notNull().default(false),
|
||||
image: text('image'),
|
||||
role: text('role').notNull().default('member'),
|
||||
banned: boolean('banned').default(false),
|
||||
banReason: text('ban_reason'),
|
||||
banExpires: timestamp('ban_expires', { withTimezone: true }),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
@@ -95,11 +98,18 @@ export const missions = pgTable(
|
||||
.notNull()
|
||||
.default('planning'),
|
||||
projectId: uuid('project_id').references(() => projects.id, { onDelete: 'set null' }),
|
||||
userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }),
|
||||
phase: text('phase'),
|
||||
milestones: jsonb('milestones').$type<Record<string, unknown>[]>(),
|
||||
config: jsonb('config'),
|
||||
metadata: jsonb('metadata'),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(t) => [index('missions_project_id_idx').on(t.projectId)],
|
||||
(t) => [
|
||||
index('missions_project_id_idx').on(t.projectId),
|
||||
index('missions_user_id_idx').on(t.userId),
|
||||
],
|
||||
);
|
||||
|
||||
export const tasks = pgTable(
|
||||
@@ -132,6 +142,40 @@ export const tasks = pgTable(
|
||||
],
|
||||
);
|
||||
|
||||
// ─── Coord Mission Tasks ─────────────────────────────────────────────────────
|
||||
// Join table tracking coord-managed tasks within a mission.
|
||||
// Scoped to userId for multi-tenant RBAC isolation.
|
||||
|
||||
export const missionTasks = pgTable(
|
||||
'mission_tasks',
|
||||
{
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
missionId: uuid('mission_id')
|
||||
.notNull()
|
||||
.references(() => missions.id, { onDelete: 'cascade' }),
|
||||
taskId: uuid('task_id').references(() => tasks.id, { onDelete: 'set null' }),
|
||||
userId: text('user_id')
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: 'cascade' }),
|
||||
status: text('status', {
|
||||
enum: ['not-started', 'in-progress', 'blocked', 'done', 'cancelled'],
|
||||
})
|
||||
.notNull()
|
||||
.default('not-started'),
|
||||
description: text('description'),
|
||||
notes: text('notes'),
|
||||
pr: text('pr'),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(t) => [
|
||||
index('mission_tasks_mission_id_idx').on(t.missionId),
|
||||
index('mission_tasks_task_id_idx').on(t.taskId),
|
||||
index('mission_tasks_user_id_idx').on(t.userId),
|
||||
index('mission_tasks_status_idx').on(t.status),
|
||||
],
|
||||
);
|
||||
|
||||
export const events = pgTable(
|
||||
'events',
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user