import Database from 'better-sqlite3'; const db = new Database('local.db'); function seed() { console.log('Seeding database...'); // Create settings table if it doesn't exist db.exec(` CREATE TABLE IF NOT EXISTS settings ( key TEXT PRIMARY KEY, value TEXT ) `); // Create email_templates table db.exec(` CREATE TABLE IF NOT EXISTS email_templates ( id INTEGER PRIMARY KEY, subject TEXT, body TEXT ) `); // Create flows table db.exec(` CREATE TABLE IF NOT EXISTS flows ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, description TEXT, path TEXT NOT NULL, createdAt DATETIME DEFAULT CURRENT_TIMESTAMP, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP ) `); // 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.'); } // Check if default email template exists const templateStmt = db.prepare('SELECT * FROM email_templates WHERE id = ?'); const defaultTemplate = templateStmt.get(1); const defaultSubject = "Your EstimateFlow Project Estimate is Ready!"; const defaultBody = `
EstimateFlow |
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, © ${new Date().getFullYear()} EstimateFlow. All rights reserved. |