view artifact-database/doc/schema-pg.sql @ 199:face2302387c

Insert collection attribute into database, too. Fixed broken SQL schema. artifacts/trunk@1437 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 09 Mar 2011 11:14:21 +0000
parents a85d889a1b0d
children 328ef982d768
line wrap: on
line source
--
-- schema to store artifacts in PostgreSQL databases.
--

BEGIN;

-- not using AUTO_INCREMENT to be more compatible with
-- other dbms.
CREATE SEQUENCE ARTIFACTS_ID_SEQ;

CREATE TABLE artifacts (
    id          int PRIMARY KEY NOT NULL,
    gid         uuid            NOT NULL UNIQUE,
    creation    timestamp       NOT NULL,
    last_access timestamp       NOT NULL,
    ttl         bigint, -- NULL means eternal
    factory     VARCHAR(256)    NOT NULL,
    data        bytea
);

CREATE SEQUENCE USERS_ID_SEQ;

CREATE TABLE users (
    id   int PRIMARY KEY NOT NULL,
    gid  uuid            NOT NULL UNIQUE,
    name VARCHAR(256)    NOT NULL UNIQUE,
    role bytea
);

CREATE SEQUENCE COLLECTIONS_ID_SEQ;

CREATE TABLE collections (
    id          int PRIMARY KEY NOT NULL,
    gid         uuid            NOT NULL UNIQUE,
    name VARCHAR(256)           NOT NULL,
    owner_id    int             NOT NULL REFERENCES users(id),
    creation    timestamp       NOT NULL,
    last_access timestamp       NOT NULL,
    ttl         bigint, -- NULL means eternal
    attribute   bytea
);

CREATE SEQUENCE COLLECTION_ITEMS_ID_SEQ;

CREATE TABLE collection_items (
    id            int PRIMARY KEY NOT NULL,
    collection_id int             NOT NULL REFERENCES collections(id),
    artifact_id   int             NOT NULL REFERENCES artifacts(id),
    attribute     bytea,
    UNIQUE (collection_id, artifact_id)
);

COMMIT;

http://dive4elements.wald.intevation.org