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 (