Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Teams refactor #70

Merged
merged 5 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions apps/api/Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM --platform=$BUILDPLATFORM oven/bun:1
WORKDIR /app

RUN apt-get update && apt-get install -y \
python3 \
make \
g++ \
&& rm -rf /var/lib/apt/lists/*

COPY package.json .
COPY bun.lockb .
COPY apps/api/package.json ./apps/api/package.json
COPY packages/typescript-config/package.json ./packages/typescript-config/package.json

RUN bun install --no-frozen-lockfile

COPY packages/typescript-config ./packages/typescript-config
COPY apps/api ./apps/api

RUN mkdir -p /app/apps/api/data && chmod 777 /app/apps/api/data

RUN touch /app/apps/api/data/kaneo.db && chmod 666 /app/apps/api/data/kaneo.db

RUN mkdir -p /app/apps/api/drizzle/meta && chmod -R 777 /app/apps/api/drizzle

EXPOSE 1337

CMD ["bun", "--watch", "/app/apps/api/src/index.ts"]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE `project` (
`icon` text DEFAULT 'Layout',
`name` text NOT NULL,
`description` text,
`created_at` integer DEFAULT '"2025-02-09T21:03:20.815Z"' NOT NULL,
`created_at` integer DEFAULT '"2025-02-18T21:46:28.196Z"' NOT NULL,
FOREIGN KEY (`workspace_id`) REFERENCES `workspace`(`id`) ON UPDATE cascade ON DELETE cascade
);
--> statement-breakpoint
Expand All @@ -20,13 +20,13 @@ CREATE TABLE `task` (
`id` text PRIMARY KEY NOT NULL,
`project_id` text NOT NULL,
`number` integer DEFAULT 1,
`assignee_email` text NOT NULL,
`assignee_email` text,
`title` text NOT NULL,
`description` text,
`status` text DEFAULT 'to-do' NOT NULL,
`priority` text DEFAULT 'low',
`due_date` integer,
`created_at` integer DEFAULT '"2025-02-09T21:03:20.815Z"' NOT NULL,
`created_at` integer DEFAULT '"2025-02-18T21:46:28.196Z"' NOT NULL,
FOREIGN KEY (`project_id`) REFERENCES `project`(`id`) ON UPDATE cascade ON DELETE cascade,
FOREIGN KEY (`assignee_email`) REFERENCES `user`(`email`) ON UPDATE cascade ON DELETE cascade
);
Expand All @@ -36,7 +36,7 @@ CREATE TABLE `user` (
`name` text NOT NULL,
`password` text NOT NULL,
`email` text NOT NULL,
`created_at` integer DEFAULT '"2025-02-09T21:03:20.814Z"' NOT NULL
`created_at` integer DEFAULT '"2025-02-18T21:46:28.196Z"' NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `user_email_unique` ON `user` (`email`);--> statement-breakpoint
Expand All @@ -45,16 +45,17 @@ CREATE TABLE `workspace` (
`name` text NOT NULL,
`description` text,
`owner_email` text NOT NULL,
`created_at` integer DEFAULT '"2025-02-09T21:03:20.815Z"' NOT NULL,
`created_at` integer DEFAULT '"2025-02-18T21:46:28.196Z"' NOT NULL,
FOREIGN KEY (`owner_email`) REFERENCES `user`(`email`) ON UPDATE cascade ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `workspace_member` (
`id` text PRIMARY KEY NOT NULL,
`workspace_id` text NOT NULL,
`user_email` text NOT NULL,
`role` text,
`joined_at` integer DEFAULT '"2025-02-09T21:03:20.815Z"' NOT NULL,
`role` text DEFAULT 'member' NOT NULL,
`joined_at` integer DEFAULT '"2025-02-18T21:46:28.196Z"' NOT NULL,
`status` text DEFAULT 'active' NOT NULL,
FOREIGN KEY (`workspace_id`) REFERENCES `workspace`(`id`) ON UPDATE cascade ON DELETE cascade,
FOREIGN KEY (`user_email`) REFERENCES `user`(`email`) ON UPDATE cascade ON DELETE cascade
);
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE TABLE `__new_project` (
`icon` text DEFAULT 'Layout',
`name` text NOT NULL,
`description` text,
`created_at` integer DEFAULT '"2025-02-11T18:12:00.369Z"' NOT NULL,
`created_at` integer DEFAULT '"2025-02-18T21:46:39.855Z"' NOT NULL,
FOREIGN KEY (`workspace_id`) REFERENCES `workspace`(`id`) ON UPDATE cascade ON DELETE cascade
);
--> statement-breakpoint
Expand All @@ -24,7 +24,7 @@ CREATE TABLE `__new_task` (
`status` text DEFAULT 'to-do' NOT NULL,
`priority` text DEFAULT 'low',
`due_date` integer,
`created_at` integer DEFAULT '"2025-02-11T18:12:00.369Z"' NOT NULL,
`created_at` integer DEFAULT '"2025-02-18T21:46:39.856Z"' NOT NULL,
FOREIGN KEY (`project_id`) REFERENCES `project`(`id`) ON UPDATE cascade ON DELETE cascade,
FOREIGN KEY (`assignee_email`) REFERENCES `user`(`email`) ON UPDATE cascade ON DELETE cascade
);
Expand All @@ -37,7 +37,7 @@ CREATE TABLE `__new_user` (
`name` text NOT NULL,
`password` text NOT NULL,
`email` text NOT NULL,
`created_at` integer DEFAULT '"2025-02-11T18:12:00.368Z"' NOT NULL
`created_at` integer DEFAULT '"2025-02-18T21:46:39.855Z"' NOT NULL
);
--> statement-breakpoint
INSERT INTO `__new_user`("id", "name", "password", "email", "created_at") SELECT "id", "name", "password", "email", "created_at" FROM `user`;--> statement-breakpoint
Expand All @@ -49,7 +49,7 @@ CREATE TABLE `__new_workspace` (
`name` text NOT NULL,
`description` text,
`owner_email` text NOT NULL,
`created_at` integer DEFAULT '"2025-02-11T18:12:00.368Z"' NOT NULL,
`created_at` integer DEFAULT '"2025-02-18T21:46:39.855Z"' NOT NULL,
FOREIGN KEY (`owner_email`) REFERENCES `user`(`email`) ON UPDATE cascade ON DELETE cascade
);
--> statement-breakpoint
Expand All @@ -60,12 +60,13 @@ CREATE TABLE `__new_workspace_member` (
`id` text PRIMARY KEY NOT NULL,
`workspace_id` text NOT NULL,
`user_email` text NOT NULL,
`role` text,
`joined_at` integer DEFAULT '"2025-02-11T18:12:00.369Z"' NOT NULL,
`role` text DEFAULT 'member' NOT NULL,
`joined_at` integer DEFAULT '"2025-02-18T21:46:39.855Z"' NOT NULL,
`status` text DEFAULT 'active' NOT NULL,
FOREIGN KEY (`workspace_id`) REFERENCES `workspace`(`id`) ON UPDATE cascade ON DELETE cascade,
FOREIGN KEY (`user_email`) REFERENCES `user`(`email`) ON UPDATE cascade ON DELETE cascade
);
--> statement-breakpoint
INSERT INTO `__new_workspace_member`("id", "workspace_id", "user_email", "role", "joined_at") SELECT "id", "workspace_id", "user_email", "role", "joined_at" FROM `workspace_member`;--> statement-breakpoint
INSERT INTO `__new_workspace_member`("id", "workspace_id", "user_email", "role", "joined_at", "status") SELECT "id", "workspace_id", "user_email", "role", "joined_at", "status" FROM `workspace_member`;--> statement-breakpoint
DROP TABLE `workspace_member`;--> statement-breakpoint
ALTER TABLE `__new_workspace_member` RENAME TO `workspace_member`;
27 changes: 18 additions & 9 deletions apps/api/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "6",
"dialect": "sqlite",
"id": "49787b32-4e2b-4274-a0e2-d2784a178329",
"id": "b293274e-7c85-4fc2-b89c-16dc01c10984",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"project": {
Expand Down Expand Up @@ -56,7 +56,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'\"2025-02-09T21:03:20.815Z\"'"
"default": "'\"2025-02-18T21:46:28.196Z\"'"
}
},
"indexes": {},
Expand Down Expand Up @@ -145,7 +145,7 @@
"name": "assignee_email",
"type": "text",
"primaryKey": false,
"notNull": true,
"notNull": false,
"autoincrement": false
},
"title": {
Expand Down Expand Up @@ -191,7 +191,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'\"2025-02-09T21:03:20.815Z\"'"
"default": "'\"2025-02-18T21:46:28.196Z\"'"
}
},
"indexes": {},
Expand Down Expand Up @@ -256,7 +256,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'\"2025-02-09T21:03:20.814Z\"'"
"default": "'\"2025-02-18T21:46:28.196Z\"'"
}
},
"indexes": {
Expand Down Expand Up @@ -308,7 +308,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'\"2025-02-09T21:03:20.815Z\"'"
"default": "'\"2025-02-18T21:46:28.196Z\"'"
}
},
"indexes": {},
Expand Down Expand Up @@ -355,16 +355,25 @@
"name": "role",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
"notNull": true,
"autoincrement": false,
"default": "'member'"
},
"joined_at": {
"name": "joined_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'\"2025-02-09T21:03:20.815Z\"'"
"default": "'\"2025-02-18T21:46:28.196Z\"'"
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'active'"
}
},
"indexes": {},
Expand Down
27 changes: 18 additions & 9 deletions apps/api/drizzle/meta/0001_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"version": "6",
"dialect": "sqlite",
"id": "e2e57331-358c-4168-862a-fcbeb44be8b0",
"prevId": "49787b32-4e2b-4274-a0e2-d2784a178329",
"id": "6058e5ae-5394-46de-b3a1-edd4f121bb0d",
"prevId": "b293274e-7c85-4fc2-b89c-16dc01c10984",
"tables": {
"project": {
"name": "project",
Expand Down Expand Up @@ -56,7 +56,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'\"2025-02-11T18:12:00.369Z\"'"
"default": "'\"2025-02-18T21:46:39.855Z\"'"
}
},
"indexes": {},
Expand Down Expand Up @@ -191,7 +191,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'\"2025-02-11T18:12:00.369Z\"'"
"default": "'\"2025-02-18T21:46:39.856Z\"'"
}
},
"indexes": {},
Expand Down Expand Up @@ -256,7 +256,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'\"2025-02-11T18:12:00.368Z\"'"
"default": "'\"2025-02-18T21:46:39.855Z\"'"
}
},
"indexes": {
Expand Down Expand Up @@ -308,7 +308,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'\"2025-02-11T18:12:00.368Z\"'"
"default": "'\"2025-02-18T21:46:39.855Z\"'"
}
},
"indexes": {},
Expand Down Expand Up @@ -355,16 +355,25 @@
"name": "role",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
"notNull": true,
"autoincrement": false,
"default": "'member'"
},
"joined_at": {
"name": "joined_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'\"2025-02-11T18:12:00.369Z\"'"
"default": "'\"2025-02-18T21:46:39.855Z\"'"
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'active'"
}
},
"indexes": {},
Expand Down
8 changes: 4 additions & 4 deletions apps/api/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
{
"idx": 0,
"version": "6",
"when": 1739135000822,
"tag": "0000_conscious_golden_guardian",
"when": 1739915188203,
"tag": "0000_colorful_leech",
"breakpoints": true
},
{
"idx": 1,
"version": "6",
"when": 1739297520379,
"tag": "0001_safe_green_goblin",
"when": 1739915199865,
"tag": "0001_sparkling_jane_foster",
"breakpoints": true
}
]
Expand Down
2 changes: 2 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
"@oslojs/crypto": "^1.0.1",
"@oslojs/encoding": "^1.1.0",
"@paralleldrive/cuid2": "^2.2.2",
"amqplib": "^0.10.5",
"better-sqlite3": "^11.8.1",
"drizzle-kit": "^0.30.2",
"drizzle-orm": "^0.39.1",
"drizzle-typebox": "^0.2.0",
"elysia": "1.2.14"
},
"devDependencies": {
"@types/amqplib": "^0.10.6",
"bun-types": "latest"
},
"override": {
Expand Down
3 changes: 0 additions & 3 deletions apps/api/src/database/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Database } from "bun:sqlite";
import { join } from "node:path";
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
import { drizzle } from "drizzle-orm/bun-sqlite";
import * as schema from "./schema";

Expand All @@ -11,6 +10,4 @@ const sqlite = new Database(dbPath);

const db = drizzle(sqlite, { schema });

void migrate(db, { migrationsFolder: "drizzle" });

export default db;
3 changes: 2 additions & 1 deletion apps/api/src/database/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ export const workspaceUserTable = sqliteTable("workspace_member", {
onDelete: "cascade",
onUpdate: "cascade",
}),
role: text("role"),
role: text("role").default("member").notNull(),
joinedAt: integer("joined_at", { mode: "timestamp" })
.default(new Date())
.notNull(),
status: text("status").default("pending").notNull(),
});

export const projectTable = sqliteTable("project", {
Expand Down
Loading