create table AAssociation ( createdBy integer, --* the creator of the association creation timestamp with time zone default 'now' --* creation timestamp with time zone ); create table AObjAssociation ( privilege integer not null references SysPrivilege(privilege), --* the privilege used to create the association insteadOf integer references DPerson(person) --* instead of whom is the action taken ) inherits (AAssociation); create table AAttachment ( ownerID bigint references DObject(object), --* owner object bodyID bigint references DObject(object) --* attached object ) inherits (AObjAssociation); create table DPerson ( person serial primary key, --* person row id# login varchar(16) not null unique, --* login name passwd varchar(16) not null, --* password aname varchar not null, --* name surname varchar not null, --* surname isAdmin boolean default false, --* is the person an admin? unique (aname, surname) ) inherits (DOrgEntity); create table DOrgEntity ( who integer not null, --* record author createdAt timestamp with time zone default 'now', --* creation timestamp with time zone isActive boolean default true --* is the entity active? ); create table SysObjTypes ( objectType integer unique not null primary key, --* object type aname text, --* name isAttachment boolean, --* is attachment of other objects hasAttachment boolean --* has attachments ); create table SysStatus ( status integer unique not null primary key, --* id# addAttachment boolean, --* allow adding new attachments dropAttachment boolean, --* allow dropping existing attachments aname text not null, --* status name description text --* status description ); create table DObject ( object bigserial primary key, --* id# revision integer not null default 0, --* ordinal number of the commited change aname text not null, --* object name description text default '', --* object description objectType integer not null references SysObjTypes(objectType), --* the object type status integer not null references SysStatus(status), --* the object status unique (aname, description, objectType) ) inherits (DRecord); create table SysPrivilege ( privilege integer unique not null primary key, --* id# aname text not null, --* privilege name description text --* privilege description );