From bb0f5dd9b854c25019de8811316adc882f0217f6 Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 8 Mar 2026 23:39:22 -0500 Subject: [PATCH] Fix: Remove UNIQUE constraint from microchip field to allow NULL values --- server/db/init.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/db/init.js b/server/db/init.js index 42bfcd6..b6aefb6 100644 --- a/server/db/init.js +++ b/server/db/init.js @@ -26,7 +26,7 @@ function initDatabase(dbPath) { sex TEXT NOT NULL CHECK(sex IN ('male', 'female')), birth_date DATE, color TEXT, - microchip TEXT UNIQUE, + microchip TEXT, photo_urls TEXT, -- JSON array of photo URLs notes TEXT, is_active INTEGER DEFAULT 1, @@ -35,6 +35,13 @@ function initDatabase(dbPath) { ) `); + // Create unique index for microchip that allows NULL values + db.exec(` + CREATE UNIQUE INDEX IF NOT EXISTS idx_dogs_microchip + ON dogs(microchip) + WHERE microchip IS NOT NULL + `); + // Parents table - Relationship mapping db.exec(` CREATE TABLE IF NOT EXISTS parents (