Set up change tracking in core tables
This commit is contained in:
@@ -41,7 +41,10 @@ const CONFIG_TABLES = [
|
||||
'abc_classification_config',
|
||||
'safety_stock_config',
|
||||
'sales_seasonality',
|
||||
'turnover_config'
|
||||
'turnover_config',
|
||||
'sync_status',
|
||||
'metric_calculation_config',
|
||||
'product_metric_status'
|
||||
];
|
||||
|
||||
// Split SQL into individual statements
|
||||
@@ -175,7 +178,7 @@ async function resetDatabase() {
|
||||
DROP TABLE IF EXISTS
|
||||
${tables[0].tables
|
||||
.split(',')
|
||||
.filter(table => table !== 'users')
|
||||
.filter(table => !['users', 'import_history'].includes(table))
|
||||
.map(table => '`' + table + '`')
|
||||
.join(', ')}
|
||||
`;
|
||||
@@ -436,34 +439,7 @@ async function resetDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
// Verify config tables were created
|
||||
const [showConfigTables] = await connection.query('SHOW TABLES');
|
||||
const existingConfigTables = showConfigTables.map(t => Object.values(t)[0]);
|
||||
|
||||
outputProgress({
|
||||
operation: 'Config tables verification',
|
||||
message: {
|
||||
found: existingConfigTables,
|
||||
expected: CONFIG_TABLES
|
||||
}
|
||||
});
|
||||
|
||||
const missingConfigTables = CONFIG_TABLES.filter(
|
||||
t => !existingConfigTables.includes(t)
|
||||
);
|
||||
|
||||
if (missingConfigTables.length > 0) {
|
||||
throw new Error(
|
||||
`Failed to create config tables: ${missingConfigTables.join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
outputProgress({
|
||||
operation: 'Config tables created',
|
||||
message: `Successfully created tables: ${CONFIG_TABLES.join(', ')}`
|
||||
});
|
||||
|
||||
// Read and execute metrics schema (metrics tables)
|
||||
// Read and execute metrics schema
|
||||
outputProgress({
|
||||
operation: 'Running metrics setup',
|
||||
message: 'Creating metrics tables...'
|
||||
@@ -525,6 +501,29 @@ async function resetDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
// Verify triggers exist
|
||||
const [triggers] = await connection.query('SHOW TRIGGERS');
|
||||
const expectedTriggers = [
|
||||
'orders_after_insert_update',
|
||||
'purchase_orders_after_insert_update',
|
||||
'products_after_insert_update'
|
||||
];
|
||||
|
||||
const missingTriggers = expectedTriggers.filter(
|
||||
triggerName => !triggers.some(t => t.Trigger === triggerName)
|
||||
);
|
||||
|
||||
if (missingTriggers.length > 0) {
|
||||
throw new Error(
|
||||
`Missing required triggers: ${missingTriggers.join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
outputProgress({
|
||||
operation: 'Triggers verified',
|
||||
message: `Successfully verified triggers: ${expectedTriggers.join(', ')}`
|
||||
});
|
||||
|
||||
outputProgress({
|
||||
status: 'complete',
|
||||
operation: 'Database reset complete',
|
||||
|
||||
Reference in New Issue
Block a user