CREATE TABLE dewormings (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  animal_id INTEGER NOT NULL,
  medication_id INTEGER,
  administered_on TEXT NOT NULL,
  dose_text TEXT,
  weight_kg REAL,
  next_due_date TEXT,
  notes TEXT,
  source_litter_id INTEGER,
  created_by INTEGER,
  created_at TEXT NOT NULL DEFAULT(datetime('now')),
  updated_at TEXT NOT NULL DEFAULT(datetime('now')),
  FOREIGN KEY(animal_id) REFERENCES animals(id) ON DELETE CASCADE,
  FOREIGN KEY(medication_id) REFERENCES ref_medications(id) ON DELETE SET NULL,
  FOREIGN KEY(source_litter_id) REFERENCES litters(id) ON DELETE SET NULL,
  FOREIGN KEY(created_by) REFERENCES users(id) ON DELETE SET NULL
);
CREATE INDEX idx_dewormings_animal_date ON dewormings(animal_id,administered_on DESC);
CREATE INDEX idx_dewormings_next_due ON dewormings(next_due_date);
