Files
estimation-flow/scripts/seed.ts
T

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-07-17 11:12:35 +00:00
import Database from 'better-sqlite3';
const db = new Database('local.db');
function seed() {
console.log('Seeding database...');
// Create users table if it doesn't exist
db.exec(`
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
name TEXT NOT NULL
)
`);
// Check if the admin user already exists
const stmt = db.prepare('SELECT * FROM users WHERE email = ?');
const adminUser = stmt.get('admin@example.com');
if (!adminUser) {
// Insert the default admin user
// In a real application, you should hash the password!
const insert = db.prepare(
"INSERT INTO users (email, password, name) VALUES (?, ?, ?)"
);
insert.run("admin@example.com", "password", "Admin User");
console.log('Admin user created.');
} else {
console.log('Admin user already exists.');
}
console.log('Seeding complete.');
}
try {
seed();
} catch (e) {
console.error('Seeding failed:');
console.error(e);
process.exit(1);
} finally {
db.close();
}