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...');
|
|
|
|
|
|
2025-07-17 11:21:35 +00:00
|
|
|
// Create settings table if it doesn't exist
|
|
|
|
|
db.exec(`
|
|
|
|
|
CREATE TABLE IF NOT EXISTS settings (
|
|
|
|
|
key TEXT PRIMARY KEY,
|
|
|
|
|
value TEXT
|
|
|
|
|
)
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
// Check if the hourly_rate setting already exists
|
|
|
|
|
const settingStmt = db.prepare('SELECT * FROM settings WHERE key = ?');
|
|
|
|
|
const hourlyRateSetting = settingStmt.get('hourly_rate');
|
|
|
|
|
|
|
|
|
|
if (!hourlyRateSetting) {
|
|
|
|
|
// Insert the default hourly rate
|
|
|
|
|
const insertSetting = db.prepare(
|
|
|
|
|
"INSERT INTO settings (key, value) VALUES (?, ?)"
|
|
|
|
|
);
|
|
|
|
|
insertSetting.run("hourly_rate", "100");
|
|
|
|
|
console.log('Default hourly rate set.');
|
|
|
|
|
} else {
|
|
|
|
|
console.log('Hourly rate setting already exists.');
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-17 11:12:35 +00:00
|
|
|
console.log('Seeding complete.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
seed();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Seeding failed:');
|
|
|
|
|
console.error(e);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
} finally {
|
|
|
|
|
db.close();
|
|
|
|
|
}
|