the flow we just created is not showing up

This commit is contained in:
Leon Serfaty G
2025-07-18 04:52:21 +00:00
parent 6954cf4364
commit 80aa0f32ba
3 changed files with 58 additions and 14 deletions
+28 -2
View File
@@ -4,7 +4,7 @@ import Database from 'better-sqlite3';
// Use a file-based database in development
const db = new Database('local.db');
// Create the tables if they don't exist
// --- SCHEMA CREATION ---
db.exec(`
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -44,11 +44,37 @@ db.exec(`
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT,
path TEXT NOT NULL,
path TEXT NOT NULL UNIQUE,
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
// --- SEEDING LOGIC ---
console.log('Running database checks and seeding if necessary...');
// Seed default user
const userStmt = db.prepare('SELECT id FROM users WHERE id = ?');
const defaultUser = userStmt.get(1);
if (!defaultUser) {
const insertUser = db.prepare(
"INSERT INTO users (id, email, password, name) VALUES (?, ?, ?, ?)"
);
insertUser.run(1, 'admin@example.com', 'password', 'Admin User');
console.log('Default user created.');
}
// Seed default flow
const flowStmt = db.prepare("SELECT id FROM flows WHERE path = ?");
const defaultFlow = flowStmt.get('/');
if (!defaultFlow) {
const insertFlow = db.prepare(
"INSERT INTO flows (name, description, path) VALUES (?, ?, ?)"
);
insertFlow.run('Cost Estimator', 'The main cost estimation tool for clients.', '/');
console.log('Default flow created.');
}
console.log('Database setup complete.');
export default db;