Meal Tracker - full feature set with auth, favorites, admin panel
This commit is contained in:
22
server/scripts/update-db.cjs
Normal file
22
server/scripts/update-db.cjs
Normal file
@@ -0,0 +1,22 @@
|
||||
const Database = require("better-sqlite3");
|
||||
const db = new Database("/root/meal-tracker/data/meal-tracker.db");
|
||||
|
||||
// Add user_id to entries
|
||||
db.exec("ALTER TABLE entries ADD COLUMN user_id INTEGER DEFAULT 1");
|
||||
|
||||
// Create users table
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT UNIQUE NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
created_at TEXT DEFAULT (datetime('now'))
|
||||
)
|
||||
`);
|
||||
|
||||
const bcrypt = require("bcryptjs");
|
||||
const hash = bcrypt.hashSync("meal123", 10);
|
||||
db.prepare("INSERT OR IGNORE INTO users (username, password) VALUES (?, ?)").run("rob", hash);
|
||||
|
||||
console.log("Database updated with users table - default user: rob / meal123");
|
||||
db.close();
|
||||
Reference in New Issue
Block a user