add build profiles

This commit is contained in:
KingKDot
2026-04-23 22:54:49 -05:00
parent 666bbfac4d
commit 5f1501c5ef
4 changed files with 546 additions and 90 deletions
+63
View File
@@ -193,6 +193,18 @@ try { db.run(`ALTER TABLE builds ADD COLUMN build_tag TEXT`); } catch {}
try { db.run(`ALTER TABLE builds ADD COLUMN built_by_user_id INTEGER`); } catch {}
db.run(`CREATE INDEX IF NOT EXISTS idx_builds_build_tag ON builds(build_tag);`);
db.run(`
CREATE TABLE IF NOT EXISTS build_profiles (
user_id INTEGER NOT NULL,
name TEXT NOT NULL,
profile_json TEXT NOT NULL,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
PRIMARY KEY (user_id, name)
);
`);
db.run(`CREATE INDEX IF NOT EXISTS idx_build_profiles_user_updated ON build_profiles(user_id, updated_at DESC);`);
db.run(`
CREATE TABLE IF NOT EXISTS notification_screenshots (
id TEXT PRIMARY KEY,
@@ -1460,6 +1472,57 @@ export function getClientBookmark(id: string): boolean {
return row?.bookmarked === 1;
}
export interface BuildProfileRecord {
userId: number;
name: string;
profileJson: string;
createdAt: number;
updatedAt: number;
}
export function listBuildProfilesForUser(userId: number): BuildProfileRecord[] {
return db
.query<any>(
`SELECT user_id, name, profile_json, created_at, updated_at
FROM build_profiles
WHERE user_id = ?
ORDER BY updated_at DESC, name ASC`,
)
.all(userId)
.map((row: any) => ({
userId: row.user_id,
name: row.name,
profileJson: row.profile_json,
createdAt: row.created_at,
updatedAt: row.updated_at,
}));
}
export function saveBuildProfileForUser(userId: number, name: string, profileJson: string): void {
const now = Date.now();
db.run(
`INSERT INTO build_profiles (user_id, name, profile_json, created_at, updated_at)
VALUES (?, ?, ?, ?, ?)
ON CONFLICT(user_id, name) DO UPDATE SET
profile_json = excluded.profile_json,
updated_at = excluded.updated_at`,
userId,
name,
profileJson,
now,
now,
);
}
export function deleteBuildProfileForUser(userId: number, name: string): boolean {
const result = db.run(
`DELETE FROM build_profiles WHERE user_id = ? AND name = ?`,
userId,
name,
);
return ((result as any)?.changes || 0) > 0;
}
export interface BuildRecord {
id: string;
status: string;