Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion apps/api/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GITHUB_APP_NAME=
# CORS Configuration
# Comma-separated list of allowed origins (optional, defaults to "*")
# Example: CORS_ORIGINS=http://localhost:3000,https://yourdomain.com
CORS_ORIGINS=
CORS_ORIGINS=http://localhost:5173

# Server Configuration
# Port for the API server (default: 1337)
Expand Down
102 changes: 60 additions & 42 deletions apps/api/drizzle/0004_curved_stingray.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,46 @@
-- and we any "pending" workspace_member is an invitation now
-- =================================================================

-- First, remove any duplicate workspace_member records before adding the unique constraint
-- Keep only the most recent record for each workspace_id, user_id combination
DELETE FROM "workspace_member"
WHERE id NOT IN (
SELECT DISTINCT ON (workspace_id, user_id) id
FROM "workspace_member"
ORDER BY workspace_id, user_id, joined_at DESC
);

-- Now add the unique constraint that will be needed for the upsert
DO $$ BEGIN
ALTER TABLE "workspace_member" ADD CONSTRAINT "workspace_member_workspace_id_user_id_unique" UNIQUE ("workspace_id", "user_id");
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

-- Create the invitation table
CREATE TABLE IF NOT EXISTS "invitation" (
"id" text PRIMARY KEY NOT NULL,
"workspace_id" text NOT NULL,
"email" text NOT NULL,
"role" text,
"status" text DEFAULT 'pending' NOT NULL,
"expires_at" timestamp NOT NULL,
"inviter_id" text NOT NULL
);

-- Add foreign key constraints for the invitation table
DO $$ BEGIN
ALTER TABLE "invitation" ADD CONSTRAINT "invitation_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

DO $$ BEGIN
ALTER TABLE "invitation" ADD CONSTRAINT "invitation_inviter_id_user_id_fk" FOREIGN KEY ("inviter_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

-- Part A: Migrate existing workspace owners from the `owner_id` column
-- into the `workspace_member` table with the role of "owner".
-- This uses an UPSERT to safely handle cases where the owner might already be a member.
Expand All @@ -12,15 +52,13 @@ INSERT INTO "workspace_member" (
workspace_id,
user_id,
role,
status,
joined_at
)
SELECT
gen_random_uuid()::text,
w.id,
w.owner_id,
'owner',
'active',
NOW()
FROM
"workspace" w
Expand Down Expand Up @@ -60,18 +98,8 @@ WHERE


-- =================================================================
-- Step 2: SCHEMA CHANGES (Generated by Drizzle, placed after data migration)
-- Step 2: REMAINING SCHEMA CHANGES (Generated by Drizzle)
-- =================================================================

CREATE TABLE IF NOT EXISTS "invitation" (
"id" text PRIMARY KEY NOT NULL,
"workspace_id" text NOT NULL,
"email" text NOT NULL,
"role" text,
"status" text DEFAULT 'pending' NOT NULL,
"expires_at" timestamp NOT NULL,
"inviter_id" text NOT NULL
);
--> statement-breakpoint
ALTER TABLE "session" ADD COLUMN "active_workspace_id" text;
--> statement-breakpoint
Expand All @@ -88,37 +116,27 @@ ALTER TABLE "workspace" DROP COLUMN IF EXISTS "owner_id";
ALTER TABLE "workspace_member" DROP COLUMN IF EXISTS "status";
--> statement-breakpoint
ALTER TABLE "workspace" ADD CONSTRAINT "workspace_slug_unique" UNIQUE("slug");
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "invitation" ADD CONSTRAINT "invitation_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "invitation" ADD CONSTRAINT "invitation_inviter_id_user_id_fk" FOREIGN KEY ("inviter_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

CREATE TABLE "invitation" (
-- =================================================================
-- Step 3: TEAM FUNCTIONALITY
-- =================================================================
CREATE TABLE "team_member" (
"id" text PRIMARY KEY NOT NULL,
"workspace_id" text NOT NULL,
"email" text NOT NULL,
"role" text,
"status" text DEFAULT 'pending' NOT NULL,
"expires_at" timestamp NOT NULL,
"inviter_id" text NOT NULL
"team_id" text NOT NULL,
"user_id" text NOT NULL,
"created_at" timestamp
);
--> statement-breakpoint
ALTER TABLE "workspace" DROP CONSTRAINT "workspace_owner_id_user_id_fk";
CREATE TABLE "team" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"workspace_id" text NOT NULL,
"created_at" timestamp NOT NULL,
"updated_at" timestamp
);
--> statement-breakpoint
ALTER TABLE "session" ADD COLUMN "active_workspace_id" text;--> statement-breakpoint
ALTER TABLE "workspace" ADD COLUMN "slug" text;--> statement-breakpoint
ALTER TABLE "workspace" ADD COLUMN "logo" text;--> statement-breakpoint
ALTER TABLE "workspace" ADD COLUMN "metadata" text;--> statement-breakpoint
ALTER TABLE "invitation" ADD CONSTRAINT "invitation_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "invitation" ADD CONSTRAINT "invitation_inviter_id_user_id_fk" FOREIGN KEY ("inviter_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "workspace" DROP COLUMN "owner_id";--> statement-breakpoint
ALTER TABLE "workspace_member" DROP COLUMN "status";--> statement-breakpoint
ALTER TABLE "workspace" ADD CONSTRAINT "workspace_slug_unique" UNIQUE("slug");
ALTER TABLE "invitation" ADD COLUMN "team_id" text;--> statement-breakpoint
ALTER TABLE "session" ADD COLUMN "active_team_id" text;--> statement-breakpoint
ALTER TABLE "team_member" ADD CONSTRAINT "team_member_team_id_team_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."team"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "team_member" ADD CONSTRAINT "team_member_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "team" ADD CONSTRAINT "team_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
8 changes: 5 additions & 3 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@
"name": "@kaneo/api",
"type": "module",
"main": "./dist/index.js",
"types": "./src/index.ts",
"types": "./dist/app.d.ts",
"exports": {
".": {
"types": "./src/index.ts",
"types": "./dist/app.d.ts",
"default": "./dist/index.js"
}
},
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --packages=external --external:fs --external:path --external:crypto --external:os --external:util --external:stream --external:buffer --external:events --external:url --external:querystring --external:http --external:https --external:net --external:tls --external:zlib",
"build": "tsc --emitDeclarationOnly && esbuild src/index.ts --bundle --platform=node --outdir=dist --format=esm --packages=external --external:fs --external:path --external:crypto --external:os --external:util --external:stream --external:buffer --external:events --external:url --external:querystring --external:http --external:https --external:net --external:tls --external:zlib",
"lint": "biome check --write .",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:studio": "drizzle-kit studio"
},
"dependencies": {
"@hono/node-server": "^1.18.1",
"@hono/trpc-server": "^0.4.0",
"@hono/zod-validator": "^0.7.2",
"@octokit/webhooks": "^14.1.3",
"@oslojs/crypto": "^1.0.1",
"@oslojs/encoding": "^1.1.0",
"@paralleldrive/cuid2": "^2.2.2",
"@trpc/server": "^11.5.0",
"bcrypt": "^6.0.0",
"better-auth": "^1.3.5",
"croner": "^9.1.0",
Expand Down
19 changes: 0 additions & 19 deletions apps/api/src/activity/controllers/create-activity.ts

This file was deleted.

14 changes: 0 additions & 14 deletions apps/api/src/activity/controllers/create-comment.ts

This file was deleted.

11 changes: 0 additions & 11 deletions apps/api/src/activity/controllers/delete-comment.ts

This file was deleted.

13 changes: 0 additions & 13 deletions apps/api/src/activity/controllers/get-activities.ts

This file was deleted.

12 changes: 0 additions & 12 deletions apps/api/src/activity/controllers/update-comment.ts

This file was deleted.

116 changes: 0 additions & 116 deletions apps/api/src/activity/index.ts

This file was deleted.

Loading