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
|
|
|
|
|
)
|
|
|
|
|
`);
|
|
|
|
|
|
2025-07-18 03:21:13 +00:00
|
|
|
// Create email_templates table
|
|
|
|
|
db.exec(`
|
|
|
|
|
CREATE TABLE IF NOT EXISTS email_templates (
|
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
|
subject TEXT,
|
|
|
|
|
body TEXT
|
|
|
|
|
)
|
|
|
|
|
`);
|
|
|
|
|
|
2025-07-17 11:21:35 +00:00
|
|
|
// 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-18 03:21:13 +00:00
|
|
|
// Check if default email template exists
|
|
|
|
|
const templateStmt = db.prepare('SELECT * FROM email_templates WHERE id = ?');
|
|
|
|
|
const defaultTemplate = templateStmt.get(1);
|
|
|
|
|
|
|
|
|
|
if (!defaultTemplate) {
|
|
|
|
|
const insertTemplate = db.prepare(
|
|
|
|
|
"INSERT INTO email_templates (id, subject, body) VALUES (?, ?, ?)"
|
|
|
|
|
);
|
|
|
|
|
const defaultSubject = "Your Project Estimate is Ready!";
|
|
|
|
|
const defaultBody = `Hello, [User Name],
|
|
|
|
|
|
|
|
|
|
Thank you for using EstimateFlow. We've prepared a rough estimate for your project based on your selections.
|
|
|
|
|
|
|
|
|
|
[EstimateDetails]
|
|
|
|
|
|
|
|
|
|
Please note that this is a preliminary estimate. For a more detailed quote and to discuss your project further, please don't hesitate to contact us.
|
|
|
|
|
|
|
|
|
|
Best regards,
|
|
|
|
|
The EstimateFlow Team`;
|
|
|
|
|
insertTemplate.run(1, defaultSubject, defaultBody);
|
|
|
|
|
console.log('Default email template created.');
|
|
|
|
|
} else {
|
|
|
|
|
console.log('Default email template 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();
|
|
|
|
|
}
|