diff --git a/src/db.ts b/src/db.ts index 08e827b..a418f78 100644 --- a/src/db.ts +++ b/src/db.ts @@ -22,6 +22,12 @@ if (isNewDb) { db.exec(schema); } +// Lightweight migration for DBs created before internal_note existed on customers. +const customerColumns = db.prepare(`PRAGMA table_info(customers)`).all() as { name: string }[]; +if (!customerColumns.some((c) => c.name === 'internal_note')) { + db.exec(`ALTER TABLE customers ADD COLUMN internal_note TEXT`); +} + const FIRST_ORDER_NUMBER = 8246; /** Allocates the next order number inside the caller's transaction. */ diff --git a/src/routes/customers.ts b/src/routes/customers.ts index 5845207..2916419 100644 --- a/src/routes/customers.ts +++ b/src/routes/customers.ts @@ -36,7 +36,7 @@ router.post('/:id/edit', (req, res) => { .prepare( `UPDATE customers SET name = ?, phone = ?, alt_phone = ?, email = ?, - address_line1 = ?, address_line2 = ?, city = ?, state = ?, zip = ? + address_line1 = ?, address_line2 = ?, city = ?, state = ?, zip = ?, internal_note = ? WHERE id = ?` ) .run( @@ -49,6 +49,7 @@ router.post('/:id/edit', (req, res) => { b.city || null, b.state || null, b.zip || null, + b.internal_note || null, req.params.id ); diff --git a/src/schema.sql b/src/schema.sql index cee5af7..4e7f81a 100644 --- a/src/schema.sql +++ b/src/schema.sql @@ -9,6 +9,7 @@ CREATE TABLE customers ( phone TEXT, alt_phone TEXT, email TEXT, + internal_note TEXT, -- staff-only; never printed on the invoice created_at TEXT DEFAULT (datetime('now')) ); diff --git a/src/views/customers/edit.njk b/src/views/customers/edit.njk index 370e1c7..b0fa64e 100644 --- a/src/views/customers/edit.njk +++ b/src/views/customers/edit.njk @@ -19,6 +19,11 @@ + +