Skip to content

Commit 3776fd0

Browse files
committed
feat: refactor database schema management by consolidating schema definitions and removing legacy schema file
1 parent 3e42403 commit 3776fd0

File tree

3 files changed

+20
-141
lines changed

3 files changed

+20
-141
lines changed

services/backend/src/db/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { type Plugin, type DatabaseExtension } from '../plugin-system/types'; //
66
import { getDbConfig, saveDbConfig, type DbConfig, type SQLiteConfig } from './config';
77

88
// Schema Definitions
9-
import { /* baseTableDefinitions, */ pluginTableDefinitions as inputPluginTableDefinitions } from './schema';
9+
import { pluginTableDefinitions as inputPluginTableDefinitions } from './schema.sqlite';
1010

1111
// Drizzle SQLite
1212
import { drizzle as drizzleSqliteAdapter, type BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';

services/backend/src/db/schema.sqlite.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
// This file is specifically for drizzle-kit when generating SQLite migrations.
2-
// It defines the actual SQLite tables with proper foreign key relationships.
1+
// SINGLE SOURCE OF TRUTH FOR DATABASE SCHEMA
2+
// This file is the definitive schema definition for the SQLite database.
3+
// It is used by:
4+
// - Drizzle Kit for generating migrations (npm run db:generate)
5+
// - The application runtime for table definitions and type safety
6+
// - All database operations and queries
7+
//
8+
// IMPORTANT: When making schema changes:
9+
// 1. Edit this file (schema.sqlite.ts) ONLY
10+
// 2. Run `npm run db:generate` to create migrations
11+
// 3. The changes will be automatically applied on next server start
12+
//
13+
// DO NOT create or edit schema.ts - this file has been removed to avoid confusion.
314

415
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
516

@@ -96,3 +107,9 @@ export const passwordResetTokens = sqliteTable('passwordResetTokens', {
96107
expires_at: integer('expires_at', { mode: 'timestamp' }).notNull(),
97108
created_at: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
98109
});
110+
111+
// Plugin table definitions - populated dynamically by the plugin system
112+
// This object will hold definitions for plugin tables, to be populated dynamically.
113+
// Key: Table name (e.g., 'myPlugin_myTable')
114+
// Value: Column definitions object (e.g., { id: (b:any)=>b('id'), name: (b:any)=>b('name') })
115+
export const pluginTableDefinitions: Record<string, Record<string, (columnBuilder: any) => any>> = {};

services/backend/src/db/schema.ts

Lines changed: 0 additions & 138 deletions
This file was deleted.

0 commit comments

Comments
 (0)