-- Add migration script here

CREATE TABLE IF NOT EXISTS User (
      id INTEGER PRIMARY KEY NOT NULL,
      name TEXT NOT NULL,
      role TEXT NOT NULL,
      CHECK(role = 'admin' OR role = 'editor' OR role = 'viewer')
);

CREATE TABLE IF NOT EXISTS InventoryItem (
     id INTEGER PRIMARY KEY NOT NULL,
     name TEXT NOT NULL,
     reorder_point INTEGER NOT NULL
);

CREATE TABLE IF NOT EXISTS PositiveAdjustment (
    id INTEGER PRIMARY KEY NOT NULL,
    user INTEGER NOT NULL,
    create_date TIMESTAMP NOT NULL,
    target_date TIMESTAMP NOT NULL,
    amount INTEGER NOT NULL,
    unit_price INTEGER NOT NULL,
    FOREIGN KEY(user) REFERENCES User(id)
);

CREATE TABLE IF NOT EXISTS NegativeAdjustment (
    id INTEGER PRIMARY KEY NOT NULL,
    user INTEGER NOT NULL,
    create_date TIMESTAMP NOT NULL,
    target_date TIMESTAMP NOT NULL,
    amount INTEGER NOT NULL,
    reason INTEGER NOT NULL,
    FOREIGN KEY(user) REFERENCES User(id),
    FOREIGN KEY(reason) REFERENCES NegativeAdjustmentReason(id)
);

CREATE TABLE IF NOT EXISTS NegativeAdjustmentReason (
    id INTEGER PRIMARY KEY NOT NULL,
    name TEXT NOT NULL
);

