-- Deploy kakeibo:items to pg
-- requires: appschema
-- requires: transactions

BEGIN;

CREATE TABLE kakeibo.items (
  id SERIAL PRIMARY KEY,
  transaction_id INTEGER NOT NULL REFERENCES kakeibo.transactions(id) ON DELETE RESTRICT ON UPDATE RESTRICT,
  category TEXT NOT NULL,
  subcategory TEXT,
  amount INTEGER NOT NULL CHECK (amount > 0),
  note TEXT,
  created_at TIMESTAMP NOT NULL DEFAULT NOW(),
  updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

COMMIT;
