mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-01 01:45:33 +08:00
feat(db): add custom workspace name
This commit is contained in:
@@ -2,28 +2,29 @@ import { Database } from "better-sqlite3";
|
|||||||
import { APP_CONFIG_TABLE_SCHEMA_SQL, LAST_SCANNED_AT_SQL, SESSIONS_TABLE_SCHEMA_SQL, WORK_SPACE_PATH_SQL } from "@/shared/database/schema.js";
|
import { APP_CONFIG_TABLE_SCHEMA_SQL, LAST_SCANNED_AT_SQL, SESSIONS_TABLE_SCHEMA_SQL, WORK_SPACE_PATH_SQL } from "@/shared/database/schema.js";
|
||||||
import { logger } from "@/shared/utils/logger.js";
|
import { logger } from "@/shared/utils/logger.js";
|
||||||
|
|
||||||
const addColumnToUsersTableIfNotExists = (
|
const addColumnToTableIfNotExists = (
|
||||||
db: Database,
|
db: Database,
|
||||||
|
tableName: string,
|
||||||
columnNames: string[],
|
columnNames: string[],
|
||||||
columnName: string,
|
columnName: string,
|
||||||
columnType: string,
|
columnType: string,
|
||||||
) => {
|
) => {
|
||||||
if (!columnNames.includes(columnName)) {
|
if (!columnNames.includes(columnName)) {
|
||||||
logger.info(
|
logger.info(
|
||||||
`Running migration: Adding ${columnName} column to users table`,
|
`Running migration: Adding ${columnName} column to ${tableName} table`,
|
||||||
);
|
);
|
||||||
db.exec(`ALTER TABLE users ADD COLUMN ${columnName} ${columnType}`);
|
db.exec(`ALTER TABLE ${tableName} ADD COLUMN ${columnName} ${columnType}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const runMigrations = (db: Database) => {
|
export const runMigrations = (db: Database) => {
|
||||||
try {
|
try {
|
||||||
const tableInfo = db.prepare("PRAGMA table_info(users)").all() as { name: string }[];
|
const usersTableInfo = db.prepare("PRAGMA table_info(users)").all() as { name: string }[];
|
||||||
const columnNames = tableInfo.map((col) => col.name);
|
const userColumnNames = usersTableInfo.map((col) => col.name);
|
||||||
|
|
||||||
addColumnToUsersTableIfNotExists(db, columnNames, "git_name", "TEXT");
|
addColumnToTableIfNotExists(db, "users", userColumnNames, "git_name", "TEXT");
|
||||||
addColumnToUsersTableIfNotExists(db, columnNames, "git_email", "TEXT");
|
addColumnToTableIfNotExists(db, "users", userColumnNames, "git_email", "TEXT");
|
||||||
addColumnToUsersTableIfNotExists(db, columnNames, "has_completed_onboarding", "BOOLEAN DEFAULT 0",
|
addColumnToTableIfNotExists(db, "users", userColumnNames, "has_completed_onboarding", "BOOLEAN DEFAULT 0",
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create app_config table if it doesn't exist (for existing installations)
|
// Create app_config table if it doesn't exist (for existing installations)
|
||||||
@@ -36,6 +37,15 @@ export const runMigrations = (db: Database) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
db.exec(WORK_SPACE_PATH_SQL);
|
db.exec(WORK_SPACE_PATH_SQL);
|
||||||
|
const workspaceOriginalPathsTableInfo = db.prepare("PRAGMA table_info(workspace_original_paths)").all() as { name: string }[];
|
||||||
|
const workspaceOriginalPathsColumnNames = workspaceOriginalPathsTableInfo.map((col) => col.name);
|
||||||
|
addColumnToTableIfNotExists(
|
||||||
|
db,
|
||||||
|
"workspace_original_paths",
|
||||||
|
workspaceOriginalPathsColumnNames,
|
||||||
|
"custom_workspace_name",
|
||||||
|
"TEXT DEFAULT NULL",
|
||||||
|
);
|
||||||
|
|
||||||
db.exec(LAST_SCANNED_AT_SQL);
|
db.exec(LAST_SCANNED_AT_SQL);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { getConnection } from '@/shared/database/connection.js';
|
import { getConnection } from '@/shared/database/connection.js';
|
||||||
|
import type { WorkspaceOriginalPathRow } from '@/shared/database/types.js';
|
||||||
|
|
||||||
export const workspaceOriginalPathsDb = {
|
export const workspaceOriginalPathsDb = {
|
||||||
createWorkspacePath(workspacePath: string): void {
|
createWorkspacePath(workspacePath: string): void {
|
||||||
@@ -9,4 +10,24 @@ export const workspaceOriginalPathsDb = {
|
|||||||
ON CONFLICT(workspace_path) DO NOTHING
|
ON CONFLICT(workspace_path) DO NOTHING
|
||||||
`).run(workspacePath);
|
`).run(workspacePath);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getCustomWorkspaceName(workspacePath: string): string | null {
|
||||||
|
const db = getConnection();
|
||||||
|
const row = db.prepare(`
|
||||||
|
SELECT custom_workspace_name
|
||||||
|
FROM workspace_original_paths
|
||||||
|
WHERE workspace_path = ?
|
||||||
|
`).get(workspacePath) as Pick<WorkspaceOriginalPathRow, 'custom_workspace_name'> | undefined;
|
||||||
|
|
||||||
|
return row?.custom_workspace_name ?? null;
|
||||||
|
},
|
||||||
|
|
||||||
|
updateCustomWorkspaceName(workspacePath: string, customWorkspaceName: string | null): void {
|
||||||
|
const db = getConnection();
|
||||||
|
db.prepare(`
|
||||||
|
INSERT INTO workspace_original_paths (workspace_path, custom_workspace_name)
|
||||||
|
VALUES (?, ?)
|
||||||
|
ON CONFLICT(workspace_path) DO UPDATE SET custom_workspace_name = excluded.custom_workspace_name
|
||||||
|
`).run(workspacePath, customWorkspaceName);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,8 @@ CREATE TABLE IF NOT EXISTS sessions (
|
|||||||
|
|
||||||
export const WORK_SPACE_PATH_SQL = `
|
export const WORK_SPACE_PATH_SQL = `
|
||||||
CREATE TABLE IF NOT EXISTS workspace_original_paths (
|
CREATE TABLE IF NOT EXISTS workspace_original_paths (
|
||||||
workspace_path TEXT PRIMARY KEY NOT NULL
|
workspace_path TEXT PRIMARY KEY NOT NULL,
|
||||||
|
custom_workspace_name TEXT DEFAULT NULL
|
||||||
);
|
);
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,11 @@ export type SessionWithSummary = {
|
|||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type WorkspaceOriginalPathRow = {
|
||||||
|
workspace_path: string;
|
||||||
|
custom_workspace_name: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user