Fix: Remove UNIQUE constraint from microchip field to allow NULL values

This commit is contained in:
2026-03-08 23:39:22 -05:00
parent 4696f2d47a
commit bb0f5dd9b8

View File

@@ -26,7 +26,7 @@ function initDatabase(dbPath) {
sex TEXT NOT NULL CHECK(sex IN ('male', 'female')), sex TEXT NOT NULL CHECK(sex IN ('male', 'female')),
birth_date DATE, birth_date DATE,
color TEXT, color TEXT,
microchip TEXT UNIQUE, microchip TEXT,
photo_urls TEXT, -- JSON array of photo URLs photo_urls TEXT, -- JSON array of photo URLs
notes TEXT, notes TEXT,
is_active INTEGER DEFAULT 1, 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 // Parents table - Relationship mapping
db.exec(` db.exec(`
CREATE TABLE IF NOT EXISTS parents ( CREATE TABLE IF NOT EXISTS parents (