
sascha@38: --
sascha@38: -- schema to store artifacts in PostgreSQL databases.
sascha@38: --
sascha@38: 
sascha@38: BEGIN;
sascha@38: 
sascha@38: -- not using AUTO_INCREMENT to be more compatible with
sascha@38: -- other dbms.
sascha@38: CREATE SEQUENCE ARTIFACTS_ID_SEQ;
sascha@38: 
sascha@38: CREATE TABLE artifacts (
sascha@38:     id          int PRIMARY KEY NOT NULL,
sascha@38:     gid         uuid            NOT NULL UNIQUE,
sascha@38:     creation    timestamp       NOT NULL,
sascha@38:     last_access timestamp       NOT NULL,
sascha@38:     ttl         bigint, -- NULL means eternal
sascha@41:     factory     VARCHAR(256)    NOT NULL,
sascha@38:     data        bytea
sascha@38: );
sascha@38: 
sascha@121: CREATE SEQUENCE USERS_ID_SEQ;
sascha@121: 
sascha@121: CREATE TABLE users (
sascha@121:     id   int PRIMARY KEY NOT NULL,
sascha@124:     gid  uuid            NOT NULL UNIQUE,
sascha@121:     name VARCHAR(256)    NOT NULL UNIQUE,
sascha@121:     role BINARY
sascha@121: );
sascha@121: 
sascha@121: CREATE SEQUENCE COLLECTIONS_ID_SEQ;
sascha@121: 
sascha@121: CREATE TABLE collections (
sascha@121:     id          int PRIMARY KEY NOT NULL,
sascha@124:     gid         uuid            NOT NULL UNIQUE,
sascha@121:     name VARCHAR(256)           NOT NULL,
sascha@121:     owner_id    int             NOT NULL REFERENCES users(id),
sascha@121:     creation    timestamp       NOT NULL,
sascha@121:     last_access timestamp       NOT NULL,
sascha@121:     ttl         bigint, -- NULL means eternal
sascha@121: );
sascha@121: 
sascha@121: CREATE SEQUENCE COLLECTION_ITEMS_SEQ;
sascha@121: 
sascha@121: CREATE TABLE collection_items (
sascha@121:     id            int PRIMARY KEY NOT NULL,
sascha@121:     collection_id int             NOT NULL REFERENCES collections(id),
sascha@121:     artifact_id   int             NOT NULL REFERENCES artifacts(id),
sascha@156:     attribute     BINARY,
sascha@121:     UNIQUE (collection_id, artifact_id)
sascha@121: );
sascha@121: 
sascha@38: COMMIT;




