Fix up frontend for update/import/reset scripts
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user