feat(db): add is_external flag to dogs table with safe ALTER TABLE migration

This commit is contained in:
2026-03-10 15:23:35 -05:00
parent 01a5db10c0
commit 0c84b83e75

View File

@@ -13,7 +13,7 @@ function initDatabase() {
db.pragma('foreign_keys = ON');
db.pragma('journal_mode = WAL');
// ── Dogs ────────────────────────────────────────────────────────────
// ── Dogs ────────────────────────────────────────────────────────────────
db.exec(`
CREATE TABLE IF NOT EXISTS dogs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -27,6 +27,7 @@ function initDatabase() {
litter_id INTEGER,
is_active INTEGER DEFAULT 1,
is_champion INTEGER DEFAULT 0,
is_external INTEGER DEFAULT 0,
chic_number TEXT,
age_at_death TEXT,
cause_of_death TEXT,
@@ -40,6 +41,7 @@ function initDatabase() {
// migrate: add columns if missing (safe on existing DBs)
const dogMigrations = [
['is_champion', 'INTEGER DEFAULT 0'],
['is_external', 'INTEGER DEFAULT 0'],
['chic_number', 'TEXT'],
['age_at_death', 'TEXT'],
['cause_of_death', 'TEXT'],
@@ -48,7 +50,7 @@ function initDatabase() {
try { db.exec(`ALTER TABLE dogs ADD COLUMN ${col} ${def}`); } catch (_) { /* already exists */ }
}
// ── Parents ─────────────────────────────────────────────────────────
// ── Parents ──────────────────────────────────────────────────────────────
db.exec(`
CREATE TABLE IF NOT EXISTS parents (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -60,7 +62,7 @@ function initDatabase() {
)
`);
// ── Breeding Records ─────────────────────────────────────────────────
// ── Breeding Records ─────────────────────────────────────────────────────
db.exec(`
CREATE TABLE IF NOT EXISTS breeding_records (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -77,7 +79,7 @@ function initDatabase() {
)
`);
// ── Litters ──────────────────────────────────────────────────────────
// ── Litters ──────────────────────────────────────────────────────────────
db.exec(`
CREATE TABLE IF NOT EXISTS litters (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -98,13 +100,7 @@ function initDatabase() {
)
`);
// ── Health Records (OFA-extended) ────────────────────────────────────
// test_type values: hip_ofa | hip_pennhip | elbow_ofa | heart_ofa |
// heart_echo | eye_caer | thyroid_ofa | dna_panel | vaccination |
// other
// ofa_result values: excellent | good | fair | borderline | mild |
// moderate | severe | normal | abnormal | pass | fail | carrier |
// clear | affected | n/a
// ── Health Records (OFA-extended) ─────────────────────────────────────────
db.exec(`
CREATE TABLE IF NOT EXISTS health_records (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -144,10 +140,7 @@ function initDatabase() {
try { db.exec(`ALTER TABLE health_records ADD COLUMN ${col} ${def}`); } catch (_) { /* already exists */ }
}
// ── Genetic Tests (DNA Panel) ─────────────────────────────────────────
// result values: clear | carrier | affected | not_tested
// marker examples: PRA1, PRA2, prcd-PRA, GR-PRA1, GR-PRA2, ICH1,
// ICH2, NCL, DM, MD
// ── Genetic Tests (DNA Panel) ──────────────────────────────────────────────
db.exec(`
CREATE TABLE IF NOT EXISTS genetic_tests (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -164,7 +157,7 @@ function initDatabase() {
)
`);
// ── Cancer History ───────────────────────────────────────────────────
// ── Cancer History ────────────────────────────────────────────────────────
db.exec(`
CREATE TABLE IF NOT EXISTS cancer_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -180,7 +173,7 @@ function initDatabase() {
)
`);
// ── Settings ─────────────────────────────────────────────────────────
// ── Settings ──────────────────────────────────────────────────────────────
db.exec(`
CREATE TABLE IF NOT EXISTS settings (
id INTEGER PRIMARY KEY AUTOINCREMENT,