task(ids): replace remaining Date.now() auto-ids with randomUUID - fixes BUG-1 collision class across 9 entities

This commit is contained in:
Agent Zero
2026-08-28 13:42:46 +02:00
parent 7c94de1590
commit c78d8d8334
2 changed files with 78 additions and 9 deletions
+9 -9
View File
@@ -56,7 +56,7 @@ export class SqliteAdapter implements DatabaseInterface {
}
createUser(data: Partial<DBUser>): DBUser {
const id = data.id ?? `user-${Date.now()}`;
const id = data.id ?? `user-${randomUUID().slice(0, 8)}`;
this.db.prepare(
'INSERT INTO users (id, email, password_hash, name, role) VALUES (?, ?, ?, ?, ?)',
).run(id, data.email!, data.password_hash!, data.name!, data.role ?? 'planer');
@@ -110,7 +110,7 @@ export class SqliteAdapter implements DatabaseInterface {
}
createProject(data: Partial<DBProject>): DBProject {
const id = data.id ?? `proj-${Date.now()}`;
const id = data.id ?? `proj-${randomUUID().slice(0, 8)}`;
this.db.prepare(
'INSERT INTO projects (id, name, description, owner_id, folder_id) VALUES (?, ?, ?, ?, ?)',
).run(id, data.name ?? 'Unbenannt', data.description ?? null, data.owner_id ?? 'user-default', data.folder_id ?? null);
@@ -149,7 +149,7 @@ export class SqliteAdapter implements DatabaseInterface {
}
createProjectFolder(data: Partial<DBProjectFolder>): DBProjectFolder {
const id = data.id ?? `pfolder-${Date.now()}`;
const id = data.id ?? `pfolder-${randomUUID().slice(0, 8)}`;
this.db.prepare(
'INSERT INTO project_folders (id, name, parent_id, owner_id) VALUES (?, ?, ?, ?)',
).run(id, data.name ?? 'Neuer Ordner', data.parent_id ?? null, data.owner_id ?? 'user-default');
@@ -183,7 +183,7 @@ export class SqliteAdapter implements DatabaseInterface {
}
createDrawing(data: Partial<DBDrawing>): DBDrawing {
const id = data.id ?? `draw-${Date.now()}`;
const id = data.id ?? `draw-${randomUUID().slice(0, 8)}`;
this.db.prepare(
'INSERT INTO drawings (id, project_id, name, data_json) VALUES (?, ?, ?, ?)',
).run(id, data.project_id!, data.name ?? 'Unbenannt', data.data_json ?? '{}');
@@ -212,7 +212,7 @@ export class SqliteAdapter implements DatabaseInterface {
}
createLayer(data: Partial<DBLayer>): DBLayer {
const id = data.id ?? `layer-${Date.now()}`;
const id = data.id ?? `layer-${randomUUID().slice(0, 8)}`;
// Idempotent: if a layer with the same id already exists, return it.
// This prevents race conditions under React StrictMode double-render.
const existing = this.db.prepare('SELECT * FROM layers WHERE id = ?').get(id) as DBLayer | undefined;
@@ -249,7 +249,7 @@ export class SqliteAdapter implements DatabaseInterface {
}
createElement(data: Partial<DBElement>): DBElement {
const id = data.id ?? `elem-${Date.now()}`;
const id = data.id ?? `elem-${randomUUID().slice(0, 8)}`;
this.db.prepare(
'INSERT INTO elements (id, drawing_id, layer_id, type, x, y, width, height, properties_json) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
).run(id, data.drawing_id!, data.layer_id!, data.type!, data.x ?? 0, data.y ?? 0,
@@ -281,7 +281,7 @@ export class SqliteAdapter implements DatabaseInterface {
}
createBlock(data: Partial<DBBlock>): DBBlock {
const id = data.id ?? `block-${Date.now()}`;
const id = data.id ?? `block-${randomUUID().slice(0, 8)}`;
this.db.prepare(
'INSERT INTO blocks (id, drawing_id, name, description, category, elements_json, thumbnail) VALUES (?, ?, ?, ?, ?, ?, ?)',
).run(id, data.drawing_id!, data.name ?? 'Block', data.description ?? null,
@@ -352,7 +352,7 @@ export class SqliteAdapter implements DatabaseInterface {
}
createNotification(data: Partial<DBNotification>): DBNotification {
const id = data.id ?? `notif-${Date.now()}`;
const id = data.id ?? `notif-${randomUUID().slice(0, 8)}`;
this.db.prepare(
'INSERT INTO notifications (id, user_id, type, title, message, read) VALUES (?, ?, ?, ?, ?, ?)',
).run(id, data.user_id!, data.type ?? 'info', data.title!, data.message!, data.read ?? 0);
@@ -377,7 +377,7 @@ export class SqliteAdapter implements DatabaseInterface {
}
createProjectShare(data: Partial<DBProjectShare>): DBProjectShare {
const id = data.id ?? `share-${Date.now()}`;
const id = data.id ?? `share-${randomUUID().slice(0, 8)}`;
const shareToken = data.share_token ?? randomUUID();
this.db.prepare(
'INSERT INTO project_shares (id, project_id, shared_with_email, shared_by, permission, share_token) VALUES (?, ?, ?, ?, ?, ?)',