Integrate config tables into existing scripts, add new config tables and settings pages

This commit is contained in:
2025-01-12 15:40:27 -05:00
parent b815062525
commit 8172323954
13 changed files with 1671 additions and 126 deletions

View File

@@ -24,6 +24,11 @@ const METRICS_TABLES = [
'vendor_metrics'
];
// Config tables that must exist
const CONFIG_TABLES = [
'stock_thresholds'
];
// Core tables that must exist
const REQUIRED_CORE_TABLES = [
'products',
@@ -129,10 +134,23 @@ async function resetMetrics() {
// the metrics tables and indexes in one shot
await connection.query(schemaSQL);
// Read and execute config schema
outputProgress({
status: 'running',
operation: 'Creating configuration tables',
percentage: '60'
});
const configSchemaPath = path.join(__dirname, '../db/config-schema.sql');
const configSchemaSQL = fs.readFileSync(configSchemaPath, 'utf8');
// Run the config schema
await connection.query(configSchemaSQL);
// Verify all tables were actually created using SHOW TABLES
const [verifyTables] = await connection.query('SHOW TABLES');
const tablesAfterCreation = verifyTables.map(t => Object.values(t)[0]);
// First verify metrics tables
outputProgress({
status: 'running',
operation: 'Verifying metrics tables',
@@ -142,13 +160,33 @@ async function resetMetrics() {
}
});
const missingTables = METRICS_TABLES.filter(
const missingMetricsTables = METRICS_TABLES.filter(
t => !tablesAfterCreation.includes(t)
);
if (missingTables.length > 0) {
if (missingMetricsTables.length > 0) {
throw new Error(
`Failed to create tables: ${missingTables.join(', ')}`
`Failed to create metrics tables: ${missingMetricsTables.join(', ')}`
);
}
// Then verify config tables
outputProgress({
status: 'running',
operation: 'Verifying config tables',
message: {
found: tablesAfterCreation,
required: CONFIG_TABLES
}
});
const missingConfigTables = CONFIG_TABLES.filter(
t => !tablesAfterCreation.includes(t)
);
if (missingConfigTables.length > 0) {
throw new Error(
`Failed to create config tables: ${missingConfigTables.join(', ')}`
);
}
@@ -157,7 +195,7 @@ async function resetMetrics() {
outputProgress({
status: 'complete',
operation: 'Metrics tables have been reset',
operation: 'Metrics and config tables have been reset',
percentage: '100'
});