Skip to content

Commit

Permalink
feat: add taskGroupAssignment table, rename userTaskGroup table
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-wasmeier-titanom committed May 20, 2024
1 parent 03fc33e commit b6edc71
Show file tree
Hide file tree
Showing 5 changed files with 401 additions and 3 deletions.
4 changes: 2 additions & 2 deletions backend/src/db/functions/task-group.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CreateTaskGroup } from 'src/task-group.controller';
import { db } from '..';
import { taskGroupTable, userTaskGroupTable } from '../schema';
import { taskGroupTable, taskGroupUserTable } from '../schema';

export async function dbGetTaskGroups() {
return await db.select().from(taskGroupTable);
Expand All @@ -26,7 +26,7 @@ export async function dbCreateTaskGroup({

const { taskGroupId } = res[0];

await db.insert(userTaskGroupTable).values(
await db.insert(taskGroupUserTable).values(
userIds.map((userId) => ({
taskGroupId,
userId,
Expand Down
19 changes: 19 additions & 0 deletions backend/src/db/migrations/0004_flippant_black_bird.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE TABLE IF NOT EXISTS "task_group_assignment_table" (
"id" serial PRIMARY KEY NOT NULL,
"task_group_id" integer NOT NULL,
"user_id" integer NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "user_task_group" RENAME TO "task_group_user";--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "task_group_assignment_table" ADD CONSTRAINT "task_group_assignment_table_task_group_id_task_group_id_fk" FOREIGN KEY ("task_group_id") REFERENCES "public"."task_group"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "task_group_assignment_table" ADD CONSTRAINT "task_group_assignment_table_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
361 changes: 361 additions & 0 deletions backend/src/db/migrations/meta/0004_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,361 @@
{
"id": "195761e6-c0c7-4afa-827e-dc8c0be2d9b3",
"prevId": "828bbbdd-14ff-4f0e-862a-97de9d3b154f",
"version": "6",
"dialect": "postgresql",
"tables": {
"public.assignment": {
"name": "assignment",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"task_id": {
"name": "task_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"state": {
"name": "state",
"type": "state",
"typeSchema": "public",
"primaryKey": false,
"notNull": false,
"default": "'pending'"
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"assignment_task_id_task_id_fk": {
"name": "assignment_task_id_task_id_fk",
"tableFrom": "assignment",
"tableTo": "task",
"columnsFrom": [
"task_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"assignment_user_id_user_id_fk": {
"name": "assignment_user_id_user_id_fk",
"tableFrom": "assignment",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.task_group_assignment_table": {
"name": "task_group_assignment_table",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"task_group_id": {
"name": "task_group_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"task_group_assignment_table_task_group_id_task_group_id_fk": {
"name": "task_group_assignment_table_task_group_id_task_group_id_fk",
"tableFrom": "task_group_assignment_table",
"tableTo": "task_group",
"columnsFrom": [
"task_group_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"task_group_assignment_table_user_id_user_id_fk": {
"name": "task_group_assignment_table_user_id_user_id_fk",
"tableFrom": "task_group_assignment_table",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.task_group": {
"name": "task_group",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"interval": {
"name": "interval",
"type": "interval",
"primaryKey": false,
"notNull": true
},
"initial_start_date": {
"name": "initial_start_date",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.task_group_user": {
"name": "task_group_user",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"task_group_id": {
"name": "task_group_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"task_group_user_task_group_id_task_group_id_fk": {
"name": "task_group_user_task_group_id_task_group_id_fk",
"tableFrom": "task_group_user",
"tableTo": "task_group",
"columnsFrom": [
"task_group_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"task_group_user_user_id_user_id_fk": {
"name": "task_group_user_user_id_user_id_fk",
"tableFrom": "task_group_user",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.task": {
"name": "task",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"task_group_id": {
"name": "task_group_id",
"type": "integer",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"task_task_group_id_task_group_id_fk": {
"name": "task_task_group_id_task_group_id_fk",
"tableFrom": "task",
"tableTo": "task_group",
"columnsFrom": [
"task_group_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.user": {
"name": "user",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true
},
"username": {
"name": "username",
"type": "text",
"primaryKey": false,
"notNull": true
},
"password": {
"name": "password",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {
"public.state": {
"name": "state",
"schema": "public",
"values": [
"pending",
"completed"
]
}
},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
Loading

0 comments on commit b6edc71

Please sign in to comment.