DROP TABLE AlienItem; 
DROP SEQUENCE "alienitem_id_seq";

CREATE TABLE AlienItem (
    id bigserial PRIMARY KEY,
    discount numeric(12,4),
    bonus numeric(12,4),
    account_plan int,
    entry int,
    alien_document bigint
);
CREATE TABLE AlienProdItem (
    id bigserial PRIMARY KEY,
    unit_price numeric(12,4),
    qty numeric(12,4),
    product int,
    account_plan int,
    entry int,
    alien_item bigint
);
CREATE TABLE AlienServItem (
    id bigserial PRIMARY KEY,
    description varchar(255),
    amount numeric(12,4),
    account_plan int,
    entry int,
    alien_item bigint
);

ALTER TABLE AlienItemTax ADD FOREIGN KEY (alien_item) REFERENCES AlienItem;

ALTER TABLE AlienProdItem ADD FOREIGN KEY (alien_item) REFERENCES AlienItem;

ALTER TABLE AlienItem ADD FOREIGN KEY (account_plan) REFERENCES AccountPlan;

ALTER TABLE AlienItem ADD FOREIGN KEY (entry) REFERENCES Entry;

ALTER TABLE AlienItem ADD FOREIGN KEY (alien_document) REFERENCES AlienDocument;

ALTER TABLE AlienServItem ADD FOREIGN KEY (alien_item) REFERENCES AlienItem;

ALTER TABLE AlienProdItem ADD FOREIGN KEY (product) REFERENCES Product;

ALTER TABLE AlienProdItem ADD FOREIGN KEY (account_plan) REFERENCES AccountPlan;

ALTER TABLE AlienProdItem ADD FOREIGN KEY (entry) REFERENCES Entry;

ALTER TABLE AlienProdItem ADD FOREIGN KEY (alien_item) REFERENCES AlienItem;

ALTER TABLE AlienServItem ADD FOREIGN KEY (account_plan) REFERENCES AccountPlan;

ALTER TABLE AlienServItem ADD FOREIGN KEY (entry) REFERENCES Entry;

ALTER TABLE AlienServItem ADD FOREIGN KEY (alien_item) REFERENCES AlienItem;
