Fix up frontend for update/import/reset scripts

This commit is contained in:
2025-01-12 01:08:32 -05:00
parent 03ad15c731
commit 6e1a8cf17d
2 changed files with 294 additions and 118 deletions

View File

@@ -1061,12 +1061,30 @@ async function main() {
// Check if tables exist, if not create them
outputProgress({
operation: 'Checking database schema',
message: 'Creating tables if needed...'
message: 'Verifying tables exist...'
});
const schemaSQL = fs.readFileSync(path.join(__dirname, '../db/schema.sql'), 'utf8');
await pool.query(schemaSQL);
const connection = await pool.getConnection();
try {
// Check if products table exists as a proxy for schema being initialized
const [tables] = await connection.query(
'SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = ? AND table_name = ?',
[dbConfig.database, 'products']
);
if (tables[0].count === 0) {
outputProgress({
operation: 'Creating database schema',
message: 'Tables not found, creating schema...'
});
const schemaSQL = fs.readFileSync(path.join(__dirname, '../db/schema.sql'), 'utf8');
await connection.query(schemaSQL);
}
} finally {
connection.release();
}
// Step 1: Import all data first
try {
// Import products first since they're referenced by other tables