-- Migration 002: plant registry

CREATE TABLE IF NOT EXISTS plants (
    id              INTEGER PRIMARY KEY AUTOINCREMENT,
    common_name     TEXT    NOT NULL,
    latin_binomial  TEXT,
    variety         TEXT,
    location_id     INTEGER REFERENCES locations(id) ON DELETE SET NULL,
    planting_date   TEXT,
    rootstock       TEXT,
    scion_source    TEXT,
    graft_date      TEXT,
    days_to_maturity INTEGER,
    notes           TEXT,
    created_at      TEXT NOT NULL DEFAULT (datetime('now')),
    updated_at      TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE INDEX IF NOT EXISTS idx_plants_common_name  ON plants (common_name);
CREATE INDEX IF NOT EXISTS idx_plants_location_id  ON plants (location_id);
