#!/usr/bin/env node const sqlite3 = require('sqlite3').verbose(); const fs = require('fs'); // Read JSON files const users = JSON.parse(fs.readFileSync('user.json')); const apikeys = JSON.parse(fs.readFileSync('apikey.json')); const colors = JSON.parse(fs.readFileSync('color.json')); const categories = JSON.parse(fs.readFileSync('category.json')); // Connect to SQLite const db = new sqlite3.Database('/home/ryan/Notes/lifetracker/lifetracker.db'); // Helper function to insert data const insertData = (table, columns, values) => { const placeholders = columns.map(() => '?').join(', '); const sql = `INSERT INTO ${table} (${columns.join(', ')}) VALUES (${placeholders})`; db.run(sql, values, (err) => { if (err) { console.error(`Error inserting into ${table}:`, err.message); } }); }; // Insert users users.forEach(user => { insertData( 'user', ['id', 'name', 'email', 'emailVerified', 'image', 'password', 'role'], [ user.id, user.name, user.email, user.emailVerified || null, user.image || null, user.password, user.role || 'user' ] ); }); // Insert API keys apiKeys.forEach(apiKey => { insertData( 'apiKey', ['id', 'keyHash', 'keyId', 'name', 'userId', 'createdAt'], [ apiKey.id, apiKey.keyHash, apiKey.keyId, apiKey.name, apiKey.userId, apiKey.createdAt || new Date().toISOString() ] ); }); categories.forEach(category => { insertData( 'category', ['id', 'code', 'colorId', 'createdAt', 'description', 'name', 'parentId', 'userId'], [ category.id, category.code, category.colorId || null, category.createdAt || new Date().toISOString(), category.description || null, category.name, category.parentId || null, category.userId ] ); }); colors.forEach(color => { insertData( 'color', ['id', 'name', 'hexcode', 'inverse', 'userId', 'createdAt'], [ color.id, color.name, color.hexcode, color.inverse || null, color.userId, color.createdAt || new Date().toISOString() ] ); }); // Close the connection db.close(() => { console.log('Database population completed!'); });