Files
cmdb-insight/backend/src/services/database/normalized-schema-init.ts
Bert Hausmans cdee0e8819 UI styling improvements: dashboard headers and navigation
- Restore blue PageHeader on Dashboard (/app-components)
- Update homepage (/) with subtle header design without blue bar
- Add uniform PageHeader styling to application edit page
- Fix Rapporten link on homepage to point to /reports overview
- Improve header descriptions spacing for better readability
2026-01-21 03:24:56 +01:00

44 lines
1.2 KiB
TypeScript

/**
* Database Schema Initialization
*
* Ensures normalized EAV schema is initialized before services use it.
*/
import { getDatabaseAdapter } from './singleton.js';
import { NORMALIZED_SCHEMA_POSTGRES, NORMALIZED_SCHEMA_SQLITE } from './normalized-schema.js';
import { logger } from '../logger.js';
let initialized = false;
let initializationPromise: Promise<void> | null = null;
/**
* Ensure database schema is initialized
*/
export async function ensureSchemaInitialized(): Promise<void> {
if (initialized) return;
if (initializationPromise) {
await initializationPromise;
return;
}
initializationPromise = (async () => {
try {
// Use shared database adapter singleton
const db = getDatabaseAdapter();
const isPostgres = db.isPostgres === true;
// Execute schema
const schema = isPostgres ? NORMALIZED_SCHEMA_POSTGRES : NORMALIZED_SCHEMA_SQLITE;
await db.exec(schema);
logger.info(`Database schema initialized (${isPostgres ? 'PostgreSQL' : 'SQLite'})`);
initialized = true;
} catch (error) {
logger.error('Failed to initialize database schema', error);
throw error;
}
})();
await initializationPromise;
}