drop sequence SEQ_GEN_SEQUENCE;
create sequence SEQ_GEN_SEQUENCE INCREMENT BY 50;

DROP TABLE attribute_group CASCADE;
CREATE TABLE attribute_group (
    id int8 PRIMARY KEY
);

DROP TABLE attribute CASCADE;
CREATE TABLE attribute (
    id int8 PRIMARY KEY,
    name varchar(255),
    type varchar(255),
    value varchar(255),
    group_id int8 REFERENCES attribute_group (id),
    mandatory boolean
);

DROP TABLE file CASCADE;
CREATE TABLE file (
    id int8 PRIMARY KEY,
    name varchar(255),
    length int8,
    checksum varchar(255),
    creation_date timestamp,
    update_date timestamp,
    valid boolean,
    deleted boolean,
    deletion_date timestamp,
    group_id int8 REFERENCES attribute_group (id)
);

DROP TABLE chunk CASCADE;
CREATE TABLE chunk (
    id int8 PRIMARY KEY,
    file_id int8 REFERENCES file (id),
    rank int8,
    checksum varchar(255),
    size int8,
    data bytea
);
/*
DROP TABLE data CASCADE;
CREATE TABLE data (
    file_id int8 REFERENCES file (id),
    metadata_id int8 REFERENCES attribute_group (id),
    PRIMARY KEY (file_id, metadata_id)
);
*/
DROP TABLE profile CASCADE;
CREATE TABLE profile (
    id int8 PRIMARY KEY,
    name varchar(255)
);

DROP TABLE profile_attribute CASCADE;
CREATE TABLE profile_attribute (
    id int8 PRIMARY KEY,
    name varchar(255),
    type varchar(255),
    mandatory boolean,
    profile_id int8 REFERENCES profile (id)
);
