CREATE TABLE IF NOT EXISTS habit_item_costs (
  habit_id INT NOT NULL,
  item_id INT NOT NULL,
  qty INT NOT NULL DEFAULT 1,
  PRIMARY KEY (habit_id, item_id),
  CONSTRAINT fk_hic_habit FOREIGN KEY (habit_id) REFERENCES habits(id) ON DELETE CASCADE,
  CONSTRAINT fk_hic_item FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE RESTRICT
);

CREATE INDEX idx_hic_item_id ON habit_item_costs(item_id);