Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Remove deprecated "teamId" column from "invitation" table and update related metadata. Introduce "activeTeamId" field in session schema for improved team management.

Bill Yangff6e7c2d67e0
diff --git a/server/drizzle/0003_careful_maelstrom.sql b/server/drizzle/0003_careful_maelstrom.sql
deleted file mode 100644
index 50c0f06bd..000000000
--- a/server/drizzle/0003_careful_maelstrom.sql
+++ /dev/null
@@ -1,3 +0,0 @@
-ALTER TABLE "invitation" ADD COLUMN "teamId" text;--> statement-breakpoint
-ALTER TABLE "invitation" ADD CONSTRAINT "invitation_teamId_team_id_fk" FOREIGN KEY ("teamId") REFERENCES "public"."team"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
-ALTER TABLE "invitation" DROP COLUMN "team_ids";
\ No newline at end of file
diff --git a/server/drizzle/0003_nice_xavin.sql b/server/drizzle/0003_nice_xavin.sql
new file mode 100644
index 000000000..1dff6559c
--- /dev/null
+++ b/server/drizzle/0003_nice_xavin.sql
@@ -0,0 +1,32 @@
+DO $$ BEGIN
+ IF NOT EXISTS (
+ SELECT 1 FROM information_schema.columns
+ WHERE table_name = 'invitation' AND column_name = 'teamId'
+ ) THEN
+ ALTER TABLE "invitation" ADD COLUMN "teamId" text;
+ END IF;
+END $$;--> statement-breakpoint
+DO $$ BEGIN
+ IF NOT EXISTS (
+ SELECT 1 FROM information_schema.columns
+ WHERE table_name = 'session' AND column_name = 'activeTeamId'
+ ) THEN
+ ALTER TABLE "session" ADD COLUMN "activeTeamId" text;
+ END IF;
+END $$;--> statement-breakpoint
+DO $$ BEGIN
+ IF NOT EXISTS (
+ SELECT 1 FROM information_schema.table_constraints
+ WHERE constraint_name = 'invitation_teamId_team_id_fk'
+ ) THEN
+ ALTER TABLE "invitation" ADD CONSTRAINT "invitation_teamId_team_id_fk" FOREIGN KEY ("teamId") REFERENCES "public"."team"("id") ON DELETE set null ON UPDATE no action;
+ END IF;
+END $$;--> statement-breakpoint
+DO $$ BEGIN
+ IF EXISTS (
+ SELECT 1 FROM information_schema.columns
+ WHERE table_name = 'invitation' AND column_name = 'team_ids'
+ ) THEN
+ ALTER TABLE "invitation" DROP COLUMN "team_ids";
+ END IF;
+END $$;
diff --git a/server/drizzle/meta/0003_snapshot.json b/server/drizzle/meta/0003_snapshot.json
index 48242dee4..3e2a327c1 100644
--- a/server/drizzle/meta/0003_snapshot.json
+++ b/server/drizzle/meta/0003_snapshot.json
@@ -1,5 +1,5 @@
{
- "id": "01633710-e3a8-4cf3-96d7-5c4c9150edbd",
+ "id": "328c7e4d-157c-4d6b-b0b4-f2a1f3571518",
"prevId": "372ba8dc-511d-480e-b745-28cdc242cea8",
"version": "7",
"dialect": "postgresql",
@@ -1358,6 +1358,12 @@
"type": "text",
"primaryKey": false,
"notNull": false
+ },
+ "activeTeamId": {
+ "name": "activeTeamId",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
}
},
"indexes": {},
diff --git a/server/drizzle/meta/_journal.json b/server/drizzle/meta/_journal.json
index ffa7c96e0..9f3ae6dd6 100644
--- a/server/drizzle/meta/_journal.json
+++ b/server/drizzle/meta/_journal.json
@@ -26,8 +26,8 @@
{
"idx": 3,
"version": "7",
- "when": 1774762368551,
- "tag": "0003_careful_maelstrom",
+ "when": 1774763742452,
+ "tag": "0003_nice_xavin",
"breakpoints": true
}
]
diff --git a/server/src/db/postgres/schema.ts b/server/src/db/postgres/schema.ts
index 5acbd6f30..3f9976c4a 100644
--- a/server/src/db/postgres/schema.ts
+++ b/server/src/db/postgres/schema.ts
@@ -256,6 +256,7 @@ export const session = pgTable(
.references(() => user.id, { onDelete: "cascade" }),
impersonatedBy: text(),
activeOrganizationId: text(),
+ activeTeamId: text(),
},
table => [unique("session_token_unique").on(table.token)]
);