Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(migration): rename active_workspace_id to active_organization_id

Andrej Acevskib89ae8325ffe
diff --git a/apps/api/drizzle/0006_rename_active_workspace_to_organization.sql b/apps/api/drizzle/0006_rename_active_workspace_to_organization.sql
new file mode 100644
index 000000000..ce013cb45
--- /dev/null
+++ b/apps/api/drizzle/0006_rename_active_workspace_to_organization.sql
@@ -0,0 +1,13 @@
+-- Rename active_workspace_id to active_organization_id in session table
+DO $$
+BEGIN
+ IF EXISTS (
+ SELECT 1 FROM information_schema.columns
+ WHERE table_name = 'session'
+ AND column_name = 'active_workspace_id'
+ ) THEN
+ ALTER TABLE "session" RENAME COLUMN "active_workspace_id" TO "active_organization_id";
+ END IF;
+END $$;
+
+
diff --git a/apps/api/drizzle/meta/_journal.json b/apps/api/drizzle/meta/_journal.json
index 3b4ce1a84..13b87575e 100644
--- a/apps/api/drizzle/meta/_journal.json
+++ b/apps/api/drizzle/meta/_journal.json
@@ -43,6 +43,13 @@
"when": 1759234332200,
"tag": "0005_jittery_monster_badoon",
"breakpoints": true
+ },
+ {
+ "idx": 6,
+ "version": "7",
+ "when": 1733703124000,
+ "tag": "0006_rename_active_workspace_to_organization",
+ "breakpoints": true
}
]
}
diff --git a/apps/api/src/database/index.ts b/apps/api/src/database/index.ts
index cecacf465..7df89a0d4 100644
--- a/apps/api/src/database/index.ts
+++ b/apps/api/src/database/index.ts
@@ -5,11 +5,14 @@ import {
accountTableRelations,
activityTableRelations,
githubIntegrationTableRelations,
+ invitationTableRelations,
labelTableRelations,
notificationTableRelations,
projectTableRelations,
sessionTableRelations,
taskTableRelations,
+ teamMemberTableRelations,
+ teamTableRelations,
timeEntryTableRelations,
userTableRelations,
verificationTableRelations,
@@ -66,6 +69,8 @@ export const schema = {
verificationTableRelations,
workspaceTableRelations,
workspaceUserTableRelations,
+ teamTableRelations,
+ teamMemberTableRelations,
projectTableRelations,
taskTableRelations,
timeEntryTableRelations,
@@ -73,6 +78,7 @@ export const schema = {
labelTableRelations,
notificationTableRelations,
githubIntegrationTableRelations,
+ invitationTableRelations,
};
const db = drizzle(pool, {
diff --git a/apps/api/src/database/relations.ts b/apps/api/src/database/relations.ts
index ea0b195f3..eb71f5b29 100644
--- a/apps/api/src/database/relations.ts
+++ b/apps/api/src/database/relations.ts
@@ -9,6 +9,8 @@ import {
projectTable,
sessionTable,
taskTable,
+ teamMemberTable,
+ teamTable,
timeEntryTable,
userTable,
verificationTable,
@@ -19,6 +21,7 @@ import {
export const userTableRelations = relations(userTable, ({ many }) => ({
sessions: many(sessionTable),
accounts: many(accountTable),
+ teamMembers: many(teamMemberTable),
workspaces: many(workspaceTable),
workspaceMemberships: many(workspaceUserTable),
assignedTasks: many(taskTable),
@@ -50,6 +53,7 @@ export const verificationTableRelations = relations(
export const workspaceTableRelations = relations(
workspaceTable,
({ many }) => ({
+ teams: many(teamTable),
members: many(workspaceUserTable),
projects: many(projectTable),
invitations: many(invitationTable),
@@ -145,6 +149,28 @@ export const githubIntegrationTableRelations = relations(
}),
);
+export const teamTableRelations = relations(teamTable, ({ one, many }) => ({
+ workspace: one(workspaceTable, {
+ fields: [teamTable.workspaceId],
+ references: [workspaceTable.id],
+ }),
+ teamMembers: many(teamMemberTable),
+}));
+
+export const teamMemberTableRelations = relations(
+ teamMemberTable,
+ ({ one }) => ({
+ team: one(teamTable, {
+ fields: [teamMemberTable.teamId],
+ references: [teamTable.id],
+ }),
+ user: one(userTable, {
+ fields: [teamMemberTable.userId],
+ references: [userTable.id],
+ }),
+ }),
+);
+
export const invitationTableRelations = relations(
invitationTable,
({ one }) => ({
diff --git a/apps/api/src/database/schema.ts b/apps/api/src/database/schema.ts
index e94e68133..339cf59b3 100644
--- a/apps/api/src/database/schema.ts
+++ b/apps/api/src/database/schema.ts
@@ -1,11 +1,11 @@
import { createId } from "@paralleldrive/cuid2";
import {
boolean,
+ index,
integer,
pgTable,
text,
timestamp,
- unique,
} from "drizzle-orm/pg-core";
export const userTable = pgTable("user", {
@@ -19,70 +19,92 @@ export const userTable = pgTable("user", {
.notNull(),
image: text("image"),
createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
- updatedAt: timestamp("updated_at", { mode: "date" }).defaultNow().notNull(),
- isAnonymous: boolean("is_anonymous"),
+ updatedAt: timestamp("updated_at", { mode: "date" })
+ .defaultNow()
+ .$onUpdate(() => /* @__PURE__ */ new Date())
+ .notNull(),
+ isAnonymous: boolean("is_anonymous").default(false),
});
-export const sessionTable = pgTable("session", {
- id: text("id").primaryKey(),
- expiresAt: timestamp("expires_at", { mode: "date" }).notNull(),
- token: text("token").notNull().unique(),
- createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
- updatedAt: timestamp("updated_at", { mode: "date" }).defaultNow().notNull(),
- ipAddress: text("ip_address"),
- userAgent: text("user_agent"),
- userId: text("user_id")
- .notNull()
- .references(() => userTable.id, { onDelete: "cascade" }),
- activeOrganizationId: text("active_workspace_id"),
- activeTeamId: text("active_team_id"),
-});
+export const sessionTable = pgTable(
+ "session",
+ {
+ id: text("id").primaryKey(),
+ expiresAt: timestamp("expires_at", { mode: "date" }).notNull(),
+ token: text("token").notNull().unique(),
+ createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
+ updatedAt: timestamp("updated_at", { mode: "date" })
+ .$onUpdate(() => /* @__PURE__ */ new Date())
+ .notNull(),
+ ipAddress: text("ip_address"),
+ userAgent: text("user_agent"),
+ userId: text("user_id")
+ .notNull()
+ .references(() => userTable.id, { onDelete: "cascade" }),
+ activeOrganizationId: text("active_organization_id"),
+ activeTeamId: text("active_team_id"),
+ },
+ (table) => [index("session_userId_idx").on(table.userId)],
+);
-export const accountTable = pgTable("account", {
- id: text("id")
- .$defaultFn(() => createId())
- .primaryKey(),
- accountId: text("account_id").notNull(),
- providerId: text("provider_id").notNull(),
- userId: text("user_id")
- .notNull()
- .references(() => userTable.id, { onDelete: "cascade" }),
- accessToken: text("access_token"),
- refreshToken: text("refresh_token"),
- idToken: text("id_token"),
- accessTokenExpiresAt: timestamp("access_token_expires_at", {
- mode: "date",
- }),
- refreshTokenExpiresAt: timestamp("refresh_token_expires_at", {
- mode: "date",
- }),
- scope: text("scope"),
- password: text("password"),
- createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
- updatedAt: timestamp("updated_at", { mode: "date" }).defaultNow().notNull(),
-});
+export const accountTable = pgTable(
+ "account",
+ {
+ id: text("id")
+ .$defaultFn(() => createId())
+ .primaryKey(),
+ accountId: text("account_id").notNull(),
+ providerId: text("provider_id").notNull(),
+ userId: text("user_id")
+ .notNull()
+ .references(() => userTable.id, { onDelete: "cascade" }),
+ accessToken: text("access_token"),
+ refreshToken: text("refresh_token"),
+ idToken: text("id_token"),
+ accessTokenExpiresAt: timestamp("access_token_expires_at", {
+ mode: "date",
+ }),
+ refreshTokenExpiresAt: timestamp("refresh_token_expires_at", {
+ mode: "date",
+ }),
+ scope: text("scope"),
+ password: text("password"),
+ createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
+ updatedAt: timestamp("updated_at", { mode: "date" })
+ .$onUpdate(() => /* @__PURE__ */ new Date())
+ .notNull(),
+ },
+ (table) => [index("account_userId_idx").on(table.userId)],
+);
-export const verificationTable = pgTable("verification", {
- id: text("id")
- .$defaultFn(() => createId())
- .primaryKey(),
- identifier: text("identifier").notNull(),
- value: text("value").notNull(),
- expiresAt: timestamp("expires_at", { mode: "date" }).notNull(),
- createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
- updatedAt: timestamp("updated_at", { mode: "date" }).defaultNow().notNull(),
-});
+export const verificationTable = pgTable(
+ "verification",
+ {
+ id: text("id")
+ .$defaultFn(() => createId())
+ .primaryKey(),
+ identifier: text("identifier").notNull(),
+ value: text("value").notNull(),
+ expiresAt: timestamp("expires_at", { mode: "date" }).notNull(),
+ createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
+ updatedAt: timestamp("updated_at", { mode: "date" })
+ .defaultNow()
+ .$onUpdate(() => /* @__PURE__ */ new Date())
+ .notNull(),
+ },
+ (table) => [index("verification_identifier_idx").on(table.identifier)],
+);
export const workspaceTable = pgTable("workspace", {
id: text("id")
.$defaultFn(() => createId())
.primaryKey(),
name: text("name").notNull(),
- slug: text("slug").unique(),
+ slug: text("slug").notNull().unique(),
logo: text("logo"),
metadata: text("metadata"),
description: text("description"),
- createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
+ createdAt: timestamp("created_at", { mode: "date" }).notNull(),
});
export const workspaceUserTable = pgTable(
@@ -91,59 +113,83 @@ export const workspaceUserTable = pgTable(
id: text("id")
.$defaultFn(() => createId())
.primaryKey(),
- workspaceId: text("workspace_id").references(() => workspaceTable.id, {
- onDelete: "cascade",
- }),
+ workspaceId: text("workspace_id")
+ .notNull()
+ .references(() => workspaceTable.id, {
+ onDelete: "cascade",
+ }),
userId: text("user_id")
.notNull()
.references(() => userTable.id, {
onDelete: "cascade",
}),
role: text("role").default("member").notNull(),
- joinedAt: timestamp("joined_at", { mode: "date" }).defaultNow().notNull(),
+ joinedAt: timestamp("joined_at", { mode: "date" }).notNull(),
},
- (table) => ({
- workspaceUserUnique: unique().on(table.workspaceId, table.userId),
- }),
+ (table) => [
+ index("workspace_member_workspaceId_idx").on(table.workspaceId),
+ index("workspace_member_userId_idx").on(table.userId),
+ ],
);
-export const teamTable = pgTable("team", {
- id: text("id").primaryKey(),
- name: text("name").notNull(),
- workspaceId: text("workspace_id")
- .notNull()
- .references(() => workspaceTable.id, { onDelete: "cascade" }),
- createdAt: timestamp("created_at").notNull(),
- updatedAt: timestamp("updated_at"),
-});
+export const teamTable = pgTable(
+ "team",
+ {
+ id: text("id").primaryKey(),
+ name: text("name").notNull(),
+ workspaceId: text("workspace_id")
+ .notNull()
+ .references(() => workspaceTable.id, { onDelete: "cascade" }),
+ createdAt: timestamp("created_at").notNull(),
+ updatedAt: timestamp("updated_at").$onUpdate(
+ () => /* @__PURE__ */ new Date(),
+ ),
+ },
+ (table) => [index("team_workspaceId_idx").on(table.workspaceId)],
+);
-export const teamMemberTable = pgTable("team_member", {
- id: text("id").primaryKey(),
- teamId: text("team_id")
- .notNull()
- .references(() => teamTable.id, { onDelete: "cascade" }),
- userId: text("user_id")
- .notNull()
- .references(() => userTable.id, { onDelete: "cascade" }),
- createdAt: timestamp("created_at"),
-});
+export const teamMemberTable = pgTable(
+ "team_member",
+ {
+ id: text("id").primaryKey(),
+ teamId: text("team_id")
+ .notNull()
+ .references(() => teamTable.id, { onDelete: "cascade" }),
+ userId: text("user_id")
+ .notNull()
+ .references(() => userTable.id, { onDelete: "cascade" }),
+ createdAt: timestamp("created_at"),
+ },
+ (table) => [
+ index("teamMember_teamId_idx").on(table.teamId),
+ index("teamMember_userId_idx").on(table.userId),
+ ],
+);
-export const invitationTable = pgTable("invitation", {
- id: text("id")
- .$defaultFn(() => createId())
- .primaryKey(),
- workspaceId: text("workspace_id")
- .notNull()
- .references(() => workspaceTable.id, { onDelete: "cascade" }),
- email: text("email").notNull(),
- role: text("role"),
- teamId: text("team_id"),
- status: text("status").default("pending").notNull(),
- expiresAt: timestamp("expires_at").notNull(),
- inviterId: text("inviter_id")
- .notNull()
- .references(() => userTable.id, { onDelete: "cascade" }),
-});
+export const invitationTable = pgTable(
+ "invitation",
+ {
+ id: text("id")
+ .$defaultFn(() => createId())
+ .primaryKey(),
+ workspaceId: text("workspace_id")
+ .notNull()
+ .references(() => workspaceTable.id, { onDelete: "cascade" }),
+ email: text("email").notNull(),
+ role: text("role"),
+ teamId: text("team_id"),
+ status: text("status").default("pending").notNull(),
+ expiresAt: timestamp("expires_at").notNull(),
+ createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull(),
+ inviterId: text("inviter_id")
+ .notNull()
+ .references(() => userTable.id, { onDelete: "cascade" }),
+ },
+ (table) => [
+ index("invitation_workspaceId_idx").on(table.workspaceId),
+ index("invitation_email_idx").on(table.email),
+ ],
+);
export const projectTable = pgTable("project", {
id: text("id")
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index ab1d62550..5b6e32a56 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -17,6 +17,7 @@ import { getPublicProject } from "./project/controllers/get-public-project";
import search from "./search";
import task from "./task";
import timeEntry from "./time-entry";
+import { migrateSessionColumn } from "./utils/migrate-session-column";
import { migrateWorkspaceUserEmail } from "./utils/migrate-workspace-user-email";
const app = new Hono<{
@@ -109,6 +110,7 @@ app.route("/api", api);
(async () => {
try {
await migrateWorkspaceUserEmail();
+ await migrateSessionColumn();
console.log("🔄 Migrating database...");
await migrate(db, {
diff --git a/apps/api/src/utils/migrate-session-column.ts b/apps/api/src/utils/migrate-session-column.ts
new file mode 100644
index 000000000..1d36ca89d
--- /dev/null
+++ b/apps/api/src/utils/migrate-session-column.ts
@@ -0,0 +1,115 @@
+import { sql } from "drizzle-orm";
+import db from "../database";
+
+/**
+ * Migration script to:
+ * 1. Rename active_workspace_id to active_organization_id in session table
+ * 2. Add created_at column to invitation table if it doesn't exist
+ * This runs before Drizzle migrations to ensure the column names match the schema.
+ */
+export async function migrateSessionColumn() {
+ console.log(
+ "🔄 Checking session table for active_workspace_id to active_organization_id migration...",
+ );
+
+ try {
+ // Migrate session table column
+ const sessionTableExists = await db.execute(sql`
+ SELECT EXISTS (
+ SELECT 1
+ FROM information_schema.tables
+ WHERE table_name = 'session'
+ ) AS exists;
+ `);
+
+ const sessionExists =
+ sessionTableExists.rows[0]?.exists === true ||
+ sessionTableExists.rows[0]?.exists === "t";
+ if (sessionExists) {
+ // Check if active_workspace_id column exists
+ const hasOldColumn = await db.execute(sql`
+ SELECT column_name
+ FROM information_schema.columns
+ WHERE table_name = 'session'
+ AND column_name = 'active_workspace_id'
+ `);
+
+ // Check if active_organization_id column already exists
+ const hasNewColumn = await db.execute(sql`
+ SELECT column_name
+ FROM information_schema.columns
+ WHERE table_name = 'session'
+ AND column_name = 'active_organization_id'
+ `);
+
+ if (hasOldColumn.rows.length > 0 && hasNewColumn.rows.length === 0) {
+ console.log(
+ "📝 Found active_workspace_id column, renaming to active_organization_id...",
+ );
+ await db.execute(sql`
+ ALTER TABLE "session"
+ RENAME COLUMN "active_workspace_id" TO "active_organization_id";
+ `);
+ console.log(
+ "✅ Successfully renamed active_workspace_id to active_organization_id",
+ );
+ } else if (hasNewColumn.rows.length > 0) {
+ console.log(
+ "✅ active_organization_id column already exists — skipping migration.",
+ );
+ } else if (hasOldColumn.rows.length === 0) {
+ console.log(
+ "🛈 active_workspace_id column does not exist — skipping migration.",
+ );
+ }
+ } else {
+ console.log("🛈 session table does not exist — skipping migration.");
+ }
+
+ // Migrate invitation table - add created_at column
+ console.log(
+ "🔄 Checking invitation table for created_at column migration...",
+ );
+
+ const invitationTableExists = await db.execute(sql`
+ SELECT EXISTS (
+ SELECT 1
+ FROM information_schema.tables
+ WHERE table_name = 'invitation'
+ ) AS exists;
+ `);
+
+ const invitationExists =
+ invitationTableExists.rows[0]?.exists === true ||
+ invitationTableExists.rows[0]?.exists === "t";
+
+ if (invitationExists) {
+ const hasCreatedAt = await db.execute(sql`
+ SELECT column_name
+ FROM information_schema.columns
+ WHERE table_name = 'invitation'
+ AND column_name = 'created_at'
+ `);
+
+ if (hasCreatedAt.rows.length === 0) {
+ console.log("📝 Adding created_at column to invitation table...");
+ await db.execute(sql`
+ ALTER TABLE "invitation"
+ ADD COLUMN "created_at" timestamp DEFAULT NOW() NOT NULL;
+ `);
+ console.log(
+ "✅ Successfully added created_at column to invitation table",
+ );
+ } else {
+ console.log(
+ "✅ created_at column already exists in invitation table — skipping migration.",
+ );
+ }
+ } else {
+ console.log("🛈 invitation table does not exist — skipping migration.");
+ }
+ } catch (error) {
+ console.error("❌ Error during migration:", error);
+ throw error;
+ }
+}
diff --git a/apps/docs/source.config.ts b/apps/docs/source.config.ts
index 93d8353b2..fb47a95e3 100644
--- a/apps/docs/source.config.ts
+++ b/apps/docs/source.config.ts
@@ -1,28 +1,18 @@
-import { rehypeCodeDefaultOptions } from "fumadocs-core/mdx-plugins";
import { defineConfig, defineDocs } from "fumadocs-mdx/config";
-import lastModified from "fumadocs-mdx/plugins/last-modified";
-import { transformerTwoslash } from "fumadocs-twoslash";
export const docs = defineDocs({
dir: "content/docs",
- docs: {
- // postprocess: {
- // extractLinkReferences: true,
- // },
- },
+ docs: {},
});
export default defineConfig({
- // plugins: [lastModified()],
mdxOptions: {
rehypeCodeOptions: {
themes: {
light: "github-light",
dark: "github-dark",
},
- transformers: [
- // ...(rehypeCodeDefaultOptions.transformers ?? []),
- ],
+ transformers: [],
},
},
});