-- Wave 5: Item Units Tracking
CREATE TABLE IF NOT EXISTS item_units (
  id TEXT PRIMARY KEY,
  item_id TEXT NOT NULL,
  rfid_code TEXT,
  status TEXT NOT NULL DEFAULT 'active',
  invoice_id TEXT,
  raw JSONB NOT NULL DEFAULT '{}'::jsonb,
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_item_units_item_id ON item_units (item_id);
CREATE INDEX IF NOT EXISTS idx_item_units_status ON item_units (status);
CREATE INDEX IF NOT EXISTS idx_item_units_invoice_id ON item_units (invoice_id);
