-- Add migration script here
CREATE TABLE origin
(
    id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 0 MINVALUE 0 ),
    name text NOT NULL,
    CONSTRAINT origin_id PRIMARY KEY (id)
        INCLUDE(id)
);

CREATE TABLE article
(
    id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 ),
    name text NOT NULL,
    bio boolean NOT NULL,
    origin bigint NOT NULL,
    description text,
    ingredients text,
    CONSTRAINT article_id PRIMARY KEY (id)
        INCLUDE(id),
    FOREIGN KEY (origin)
        REFERENCES origin (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID

);

CREATE TABLE variant
(
    id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 ),
    article_id bigint NOT NULL,
    weight text NOT NULL,
    ean text NOT NULL,
    name text NOT NULL,
    description text NOT NULL,
    ingredients text NOT NULL,
    CONSTRAINT variant_id PRIMARY KEY (id)
        INCLUDE(id),
    FOREIGN KEY (article_id)
        REFERENCES article (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID
);

-- Insert origin options
INSERT INTO origin (name) VALUES ('EU');
INSERT INTO origin (name) VALUES ('Nicht EU');
INSERT INTO origin (name) VALUES ('EU / Nicht EU');
