
CREATE SEQUENCE ATTACHMENTS_seq;
CREATE TABLE Attachments (
        id              NUMBER(19,0) 
                        CONSTRAINT Attachments_Key PRIMARY KEY,
        TransactionId   NUMBER(19,0) NOT NULL,
        Parent          NUMBER(19,0) DEFAULT 0 NOT NULL, 
        MessageId       VARCHAR2(160),
        Subject         VARCHAR2(255),
        Filename        VARCHAR2(255),
        ContentType     VARCHAR2(80),
        ContentEncoding VARCHAR2(80),
        Content         CLOB,
        Headers         CLOB,
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE
);
CREATE INDEX Attachments2 ON Attachments (TransactionId);
CREATE INDEX Attachments3 ON Attachments (Parent, TransactionId);
CREATE INDEX Attachments4 ON Attachments (Filename);


CREATE SEQUENCE QUEUES_seq;
CREATE TABLE Queues (
        id                      NUMBER(11,0) 
                CONSTRAINT Queues_Key PRIMARY KEY,
        Name                    VARCHAR2(200) CONSTRAINT Queues_Name_Unique UNIQUE NOT NULL,
        Description             VARCHAR2(255),
        CorrespondAddress       VARCHAR2(120),
        CommentAddress          VARCHAR2(120),
        Lifecycle               VARCHAR2(32),
        SubjectTag              VARCHAR2(120),
        SortOrder               NUMBER(11,0) DEFAULT 0 NOT NULL,
        Creator                 NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created                 DATE,
        LastUpdatedBy           NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated             DATE,
        SLADisabled             NUMBER(11,0) DEFAULT 1 NOT NULL,
        Disabled                NUMBER(11,0) DEFAULT 0 NOT NULL
);
CREATE UNIQUE INDEX Queues1 ON Queues (LOWER(Name));
CREATE INDEX Queues2 ON Queues (Disabled);


CREATE SEQUENCE LINKS_seq;
CREATE TABLE Links (
        id              NUMBER(11,0) 
                CONSTRAINT Links_Key PRIMARY KEY,
        Base            VARCHAR2(240),
        Target          VARCHAR2(240),
        Type            VARCHAR2(20) NOT NULL,
        LocalTarget     NUMBER(11,0) DEFAULT 0 NOT NULL,
        LocalBase       NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated     DATE,
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE
);

CREATE INDEX Links1 ON Links (Base);
CREATE INDEX Links2 ON Links (Target);
CREATE INDEX Links3 ON Links (LocalBase);
CREATE INDEX Links4 ON Links (LocalTarget);
CREATE INDEX Links5 ON Links (Type);


CREATE SEQUENCE PRINCIPALS_seq;
CREATE TABLE Principals (
        id              NUMBER(11,0) 
                CONSTRAINT Principals_Key PRIMARY KEY,
        PrincipalType   VARCHAR2(16),
        Disabled        NUMBER(11,0) DEFAULT 0 NOT NULL
);

CREATE SEQUENCE GROUPS_seq;
CREATE TABLE Groups (
        id              NUMBER(11,0) 
                CONSTRAINT Groups_Key PRIMARY KEY,
        Name            VARCHAR2(200),
        Description     VARCHAR2(255),
        Domain          VARCHAR2(64),
        Instance        NUMBER(11,0) DEFAULT 0, -- NOT NULL
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated     DATE
--      Instance        VARCHAR2(64)
);
CREATE INDEX Groups1 ON Groups (LOWER(Domain), LOWER(Name), Instance);
CREATE INDEX Groups2 ON Groups (Instance);


CREATE SEQUENCE SCRIPCONDITIONS_seq;
CREATE TABLE ScripConditions (
        id                      NUMBER(11, 0) 
                CONSTRAINT ScripConditions_Key PRIMARY KEY,
        Name                    VARCHAR2(200),
        Description             VARCHAR2(255),
        ExecModule              VARCHAR2(60),
        Argument                VARCHAR2(255),
        ApplicableTransTypes    VARCHAR2(60),
        Creator                 NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created                 DATE,
        LastUpdatedBy           NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated             DATE
);


CREATE SEQUENCE TRANSACTIONS_seq;
CREATE TABLE Transactions (
        id                      NUMBER(19,0) 
                CONSTRAINT Transactions_Key PRIMARY KEY,
        ObjectType              VARCHAR2(255),
        ObjectId                NUMBER(11,0) DEFAULT 0 NOT NULL,
        TimeTaken               NUMBER(11,0) DEFAULT 0 NOT NULL,
        Type                    VARCHAR2(20),
        Field                   VARCHAR2(255),
        OldValue                VARCHAR2(255),
        NewValue                VARCHAR2(255),
        ReferenceType           VARCHAR2(255),
        OldReference            NUMBER(11,0),
        NewReference            NUMBER(11,0),
        Data                    VARCHAR2(255),
        Creator                 NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created                 DATE
);
CREATE INDEX Transactions1 ON Transactions (ObjectType, ObjectId);


CREATE SEQUENCE SCRIPS_seq;
CREATE TABLE Scrips (
        id              NUMBER(11,0) 
                CONSTRAINT Scrips_Key PRIMARY KEY,      
        Description     VARCHAR2(255),
        ScripCondition  NUMBER(11,0) DEFAULT 0 NOT NULL,
        ScripAction     NUMBER(11,0) DEFAULT 0 NOT NULL,
        CustomIsApplicableCode  CLOB,
        CustomPrepareCode       CLOB,
        CustomCommitCode        CLOB,
        Disabled        NUMBER(11,0) DEFAULT 0 NOT NULL,
        Template        VARCHAR2(200) NOT NULL,
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated     DATE  
);

CREATE SEQUENCE OBJECTSCRIPS_seq;
CREATE TABLE ObjectScrips (
        id              NUMBER(11,0)
                 CONSTRAINT ObjectScrips_Key PRIMARY KEY,
        Scrip       NUMBER(11,0)  NOT NULL,
        Stage           VARCHAR2(32) DEFAULT 'TransactionCreate' NOT NULL,
        ObjectId              NUMBER(11,0)  NOT NULL,
        SortOrder       NUMBER(11,0) DEFAULT 0 NOT NULL,
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated     DATE
);
CREATE UNIQUE INDEX ObjectScrips1 ON ObjectScrips (ObjectId, Scrip);

CREATE SEQUENCE ACL_seq;
CREATE TABLE ACL (
        id              NUMBER(11,0) 
                CONSTRAINT ACL_Key PRIMARY KEY,
        PrincipalType   VARCHAR2(25) NOT NULL,
        PrincipalId     NUMBER(11,0) NOT NULL,
        RightName       VARCHAR2(25) NOT NULL,
        ObjectType      VARCHAR2(25) NOT NULL,
        ObjectId        NUMBER(11,0) DEFAULT 0 NOT NULL,
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated     DATE
);
CREATE INDEX ACL1 ON ACL(RightName, ObjectType, ObjectId, PrincipalType, PrincipalId);


CREATE SEQUENCE GROUPMEMBERS_seq;
CREATE TABLE GroupMembers (
        id              NUMBER(11,0) 
                CONSTRAINT GroupMembers_Key PRIMARY KEY,
        GroupId         NUMBER(11,0) DEFAULT 0 NOT NULL,
        MemberId        NUMBER(11,0) DEFAULT 0 NOT NULL,
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated     DATE
);
CREATE UNIQUE INDEX GroupMembers1 ON GroupMembers (GroupId, MemberId);


CREATE SEQUENCE CachedGroupMembers_seq;
CREATE TABLE CachedGroupMembers (
        id              NUMBER(11,0) 
                CONSTRAINT CachedGroupMembers_Key PRIMARY KEY,
        GroupId         NUMBER(11,0),
        MemberId        NUMBER(11,0),
        Via             NUMBER(11,0),
        ImmediateParentId       NUMBER(11,0),
        Disabled        NUMBER(11,0) DEFAULT 0 NOT NULL
);
CREATE INDEX DisGrouMem ON CachedGroupMembers (GroupId, MemberId, Disabled);
CREATE INDEX CachedGroupMembers2 ON CachedGroupMembers (MemberId, GroupId, Disabled);
CREATE INDEX CachedGroupMembers3 on CachedGroupMembers (MemberId, ImmediateParentId);


CREATE SEQUENCE USERS_seq;
CREATE TABLE Users (
        id                      NUMBER(11,0) 
                CONSTRAINT Users_Key PRIMARY KEY,
        Name                    VARCHAR2(200) CONSTRAINT Users_Name_Unique 
                unique  NOT NULL,
        Password                VARCHAR2(256),
        AuthToken               VARCHAR2(16),
        Comments                CLOB,
        Signature               CLOB,
        EmailAddress            VARCHAR2(120),
        FreeFormContactInfo     CLOB,
        Organization            VARCHAR2(200),
        RealName                VARCHAR2(120),
        NickName                VARCHAR2(16),
        Lang                    VARCHAR2(16),
        Gecos                   VARCHAR2(16),
        HomePhone               VARCHAR2(30),
        WorkPhone               VARCHAR2(30),
        MobilePhone             VARCHAR2(30),
        PagerPhone              VARCHAR2(30),
        Address1                VARCHAR2(200),
        Address2                VARCHAR2(200),
        City                    VARCHAR2(100),
        State                   VARCHAR2(100),
        Zip                     VARCHAR2(16),
        Country                 VARCHAR2(50),
        Timezone                VARCHAR2(50),
        SMIMECertificate        CLOB,
        Creator                 NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created                 DATE,
        LastUpdatedBy           NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated             DATE
);

CREATE UNIQUE INDEX Users1 ON Users (LOWER(Name));
CREATE INDEX Users4 ON Users (LOWER(EmailAddress));


CREATE SEQUENCE TICKETS_seq;
CREATE TABLE Tickets (
       id                      NUMBER(11, 0) 
               CONSTRAINT Tickets_Key PRIMARY KEY,
        EffectiveId             NUMBER(11,0) DEFAULT 0 NOT NULL,
        IsMerged                NUMBER(11,0) DEFAULT NULL NULL,
        Queue                   NUMBER(11,0) DEFAULT 0 NOT NULL,
        Type                    VARCHAR2(16),           
        Owner                   NUMBER(11,0) DEFAULT 0 NOT NULL,
        Subject                 VARCHAR2(200) DEFAULT '[no subject]', 
        InitialPriority         NUMBER(11,0) DEFAULT 0 NOT NULL,
        FinalPriority           NUMBER(11,0) DEFAULT 0 NOT NULL,
        Priority                NUMBER(11,0) DEFAULT 0 NOT NULL,
        TimeEstimated           NUMBER(11,0) DEFAULT 0 NOT NULL,
        TimeWorked              NUMBER(11,0) DEFAULT 0 NOT NULL,
        Status                  VARCHAR2(64),           
        SLA                     VARCHAR2(64),
        TimeLeft                NUMBER(11,0) DEFAULT 0 NOT NULL,
        Told                    DATE,
        Starts                  DATE,
        Started                 DATE,
        Due                     DATE,
        Resolved                DATE,
        LastUpdatedBy           NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated             DATE,
        Creator                 NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created                 DATE
);
CREATE INDEX Tickets1 ON Tickets (Queue, Status);
CREATE INDEX Tickets2 ON Tickets (Owner);
CREATE INDEX Tickets6 ON Tickets (EffectiveId, Type);


CREATE SEQUENCE SCRIPACTIONS_seq;
CREATE TABLE ScripActions (
  id            NUMBER(11,0) 
                CONSTRAINT ScripActions_Key PRIMARY KEY,
  Name          VARCHAR2(200),
  Description   VARCHAR2(255),
  ExecModule    VARCHAR2(60),
  Argument      VARCHAR2(255),
  Creator       NUMBER(11,0) DEFAULT 0 NOT NULL,
  Created       DATE,
  LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL,
  LastUpdated   DATE
);


CREATE SEQUENCE TEMPLATES_seq;
CREATE TABLE Templates (
        id              NUMBER(11,0) 
                CONSTRAINT Templates_Key PRIMARY KEY,
        Queue           NUMBER(11,0) DEFAULT 0 NOT NULL,
        Name            VARCHAR2(200) NOT NULL,
        Description     VARCHAR2(255),
        Type            VARCHAR2(16),
        Content         CLOB,
        LastUpdated     DATE,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE
);


CREATE SEQUENCE OBJECTCUSTOMFIELDS_seq;
CREATE TABLE ObjectCustomFields (
        id              NUMBER(11,0)
                 CONSTRAINT ObjectCustomFields_Key PRIMARY KEY,
        CustomField       NUMBER(11,0)  NOT NULL,
        ObjectId              NUMBER(11,0)  NOT NULL,
        SortOrder       NUMBER(11,0) DEFAULT 0 NOT NULL,
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated     DATE
);

CREATE INDEX ObjectCustomFields1 ON ObjectCustomFields (ObjectId);


CREATE SEQUENCE OBJECTCUSTOMFIELDVALUES_seq;
CREATE TABLE ObjectCustomFieldValues (
        id              NUMBER(11,0) 
                CONSTRAINT ObjectCustomFieldValues_Key PRIMARY KEY,
        CustomField     NUMBER(11,0) NOT NULL,
        ObjectType      VARCHAR2(25) NOT NULL,
        ObjectId        NUMBER(19,0) DEFAULT 0 NOT NULL,
        SortOrder       NUMBER(11,0) DEFAULT 0 NOT NULL,
        Content         VARCHAR2(255),
        LargeContent    CLOB,
        ContentType     VARCHAR2(80),
        ContentEncoding VARCHAR2(80),
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated     DATE,
        Disabled        NUMBER(11,0) DEFAULT 0 NOT NULL
);

CREATE INDEX ObjectCustomFieldValues1 ON ObjectCustomFieldValues (Content); 
CREATE INDEX ObjectCustomFieldValues2 ON ObjectCustomFieldValues (CustomField,ObjectType,ObjectId); 
CREATE INDEX ObjectCustomFieldValues3 ON ObjectCustomFieldValues (SortOrder);

CREATE SEQUENCE CUSTOMFIELDS_seq;
CREATE TABLE CustomFields (
        id                NUMBER(11,0) 
                CONSTRAINT CustomFields_Key PRIMARY KEY,
        Name              VARCHAR2(200),
        Type              VARCHAR2(200),
        RenderType        VARCHAR2(64),
        MaxValues         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Pattern           CLOB,
        ValuesClass       VARCHAR2(64),
        BasedOn           NUMBER(11,0) NULL,
        Description       VARCHAR2(255),
        SortOrder         NUMBER(11,0) DEFAULT 0 NOT NULL,
        LookupType        VARCHAR2(255),
        EntryHint         VARCHAR2(255) NULL,
        ValidationHint    VARCHAR2(255) NULL,
        UniqueValues      NUMBER(11,0) DEFAULT 0 NOT NULL,
        CanonicalizeClass VARCHAR2(64),
        Creator           NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created           DATE,
        LastUpdatedBy     NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated       DATE,
        Disabled          NUMBER(11,0) DEFAULT 0 NOT NULL
);


CREATE SEQUENCE CUSTOMFIELDVALUES_seq;
CREATE TABLE CustomFieldValues (
        id              NUMBER(11,0) 
                CONSTRAINT CustomFieldValues_Key PRIMARY KEY,
        CustomField     NUMBER(11,0),
        Name            VARCHAR2(200),
        Description     VARCHAR2(255),
        SortOrder       NUMBER(11,0) DEFAULT 0 NOT NULL,
    Category    VARCHAR2(255),
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated     DATE
);

CREATE INDEX CustomFieldValues1 ON CustomFieldValues (CustomField);

CREATE SEQUENCE ATTRIBUTES_seq;
CREATE TABLE Attributes (
        id                      NUMBER(11,0) PRIMARY KEY,
        Name                    VARCHAR2(255) NOT NULL,
        Description             VARCHAR2(255),
        Content         CLOB,
    ContentType VARCHAR(16),
        ObjectType      VARCHAR2(25) NOT NULL,
        ObjectId        NUMBER(11,0) DEFAULT 0 NOT NULL,
        Creator                 NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created                 DATE,
        LastUpdatedBy           NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated             DATE
);

CREATE INDEX Attributes1 on Attributes(Name);
CREATE INDEX Attributes2 on Attributes(ObjectType, ObjectId);


CREATE TABLE sessions (
        id              VARCHAR2(32) 
                CONSTRAINT Sessions_Key PRIMARY KEY,
        a_session       CLOB,
        LastUpdated     DATE
);

CREATE SEQUENCE Classes_seq;
CREATE TABLE Classes (
id NUMBER(11,0)
  CONSTRAINT Classes_key PRIMARY KEY,
Name varchar2(255) DEFAULT '',
Description varchar2(255) DEFAULT '',
SortOrder NUMBER(11,0) DEFAULT 0 NOT NULL,
Disabled NUMBER(11,0) DEFAULT 0 NOT NULL,
Creator NUMBER(11,0) DEFAULT 0 NOT NULL,
Created DATE,
LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL,
LastUpdated DATE
);

CREATE SEQUENCE Articles_seq;
CREATE TABLE Articles (
id NUMBER(11,0)
  CONSTRAINT Articles_key PRIMARY KEY,
Name varchar2(255) DEFAULT '',
Summary varchar2(255) DEFAULT '',
SortOrder NUMBER(11,0) DEFAULT 0 NOT NULL,
Class NUMBER(11,0) DEFAULT 0 NOT NULL,
Parent NUMBER(11,0) DEFAULT 0 NOT NULL,
URI varchar2(255),
Disabled NUMBER(11,0) DEFAULT 0 NOT NULL,
Creator NUMBER(11,0) DEFAULT 0 NOT NULL,
Created DATE,
LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL,
LastUpdated DATE
);


CREATE SEQUENCE Topics_seq;
CREATE TABLE Topics (
id NUMBER(11,0)
  CONSTRAINT Topics_key PRIMARY KEY,
Parent NUMBER(11,0) DEFAULT 0 NOT NULL,
Name varchar2(255) DEFAULT '',
Description varchar2(255) DEFAULT '',
ObjectType varchar2(64) DEFAULT '' NOT NULL,
ObjectId NUMBER(11,0) NOT NULL
);


CREATE SEQUENCE ObjectTopics_seq;
CREATE TABLE ObjectTopics (
id NUMBER(11,0)
  CONSTRAINT ObjectTopics_key PRIMARY KEY,
Topic NUMBER(11,0) NOT NULL,
ObjectType varchar2(64) DEFAULT '' NOT NULL,
ObjectId NUMBER(11,0) NOT NULL
);

CREATE SEQUENCE ObjectClasses_seq;
CREATE TABLE ObjectClasses (
id NUMBER(11,0)
  CONSTRAINT ObjectClasses_key PRIMARY KEY,
Class NUMBER(11,0) NOT NULL,
ObjectType varchar2(255) DEFAULT '' NOT NULL,
ObjectId NUMBER(11,0) NOT NULL,
Creator NUMBER(11,0) DEFAULT 0 NOT NULL,
Created DATE,
LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL,
LastUpdated DATE
);

CREATE SEQUENCE Assets_seq;
CREATE TABLE Assets (
    id              NUMBER(11,0)    CONSTRAINT Assets_key PRIMARY KEY,
    Name            varchar2(255)   DEFAULT '',
    Catalog         NUMBER(11,0)    DEFAULT 0 NOT NULL,
    Status          varchar2(64)    DEFAULT '',
    Description     varchar2(255)   DEFAULT '',
    Creator         NUMBER(11,0)    DEFAULT 0 NOT NULL,
    Created         DATE,
    LastUpdatedBy   NUMBER(11,0)    DEFAULT 0 NOT NULL,
    LastUpdated     DATE
);

CREATE INDEX AssetsName ON Assets (LOWER(Name));
CREATE INDEX AssetsStatus ON Assets (Status);
CREATE INDEX AssetsCatalog ON Assets (Catalog);

CREATE SEQUENCE Catalogs_seq;
CREATE TABLE Catalogs (
    id              NUMBER(11,0)    CONSTRAINT Catalogs_key PRIMARY KEY,
    Name            varchar2(255)   DEFAULT '',
    Lifecycle       varchar2(32)    DEFAULT 'assets',
    Description     varchar2(255)   DEFAULT '',
    Disabled        NUMBER(11,0)    DEFAULT 0 NOT NULL,
    Creator         NUMBER(11,0)    DEFAULT 0 NOT NULL,
    Created         DATE,
    LastUpdatedBy   NUMBER(11,0)    DEFAULT 0 NOT NULL,
    LastUpdated     DATE
);

CREATE INDEX CatalogsName ON Catalogs (LOWER(Name));
CREATE INDEX CatalogsDisabled ON Catalogs (Disabled);

CREATE SEQUENCE CUSTOMROLES_seq;
CREATE TABLE CustomRoles (
        id              NUMBER(11,0)
                CONSTRAINT CustomRoles_Key PRIMARY KEY,
        Name            VARCHAR2(200),
        Description     VARCHAR2(255),
        MaxValues       NUMBER(11,0) DEFAULT 0 NOT NULL,
        EntryHint       VARCHAR2(255),
        LookupType      VARCHAR2(255),
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated     DATE,
        Disabled        NUMBER(11,0) DEFAULT 0 NOT NULL
);

CREATE SEQUENCE OBJECTCUSTOMROLES_seq;
CREATE TABLE ObjectCustomRoles (
        id              NUMBER(11,0)
                 CONSTRAINT ObjectCustomRoles_Key PRIMARY KEY,
        CustomRole       NUMBER(11,0)  NOT NULL,
        ObjectId              NUMBER(11,0)  NOT NULL,
        SortOrder       NUMBER(11,0) DEFAULT 0 NOT NULL,
        Creator         NUMBER(11,0) DEFAULT 0 NOT NULL,
        Created         DATE,
        LastUpdatedBy   NUMBER(11,0) DEFAULT 0 NOT NULL,
        LastUpdated     DATE
);
CREATE UNIQUE INDEX ObjectCustomRoles1 ON ObjectCustomRoles (ObjectId, CustomRole);

CREATE SEQUENCE Configurations_seq;
CREATE TABLE Configurations (
    id              NUMBER(11,0)    CONSTRAINT Configurations_key PRIMARY KEY,
    Name            VARCHAR2(255) NOT NULL,
    Content         CLOB,
    ContentType     VARCHAR2(80),
    Disabled        NUMBER(11,0) DEFAULT 0 NOT NULL,
    Creator         NUMBER(11,0)    DEFAULT 0 NOT NULL,
    Created         DATE,
    LastUpdatedBy   NUMBER(11,0)    DEFAULT 0 NOT NULL,
    LastUpdated     DATE
);

CREATE INDEX Configurations1 ON Configurations (LOWER(Name), Disabled);
CREATE INDEX Configurations2 ON Configurations (Disabled);

CREATE SEQUENCE AuthTokens_seq;
CREATE TABLE AuthTokens (
    id              NUMBER(11,0)    CONSTRAINT AuthTokens_key PRIMARY KEY,
    Owner           NUMBER(11,0)    DEFAULT 0 NOT NULL,
    Token           VARCHAR2(256),
    Description     varchar2(255)   DEFAULT '',
    LastUsed        DATE,
    Creator         NUMBER(11,0)    DEFAULT 0 NOT NULL,
    Created         DATE,
    LastUpdatedBy   NUMBER(11,0)    DEFAULT 0 NOT NULL,
    LastUpdated     DATE,
    Expires         DATE
);

CREATE INDEX AuthTokensOwner ON AuthTokens (Owner);

CREATE SEQUENCE SHORTENERS_seq;
CREATE TABLE Shorteners (
  id                NUMBER(19,0)
                    CONSTRAINT SHORTENERS_seq PRIMARY KEY,
  Code              VARCHAR2(40)    NOT NULL,
  Content           CLOB            NOT NULL,
  Permanent         NUMBER(11,0)    DEFAULT 0 NOT NULL,
  Creator           NUMBER(11,0)    DEFAULT 0 NOT NULL,
  Created           DATE,
  LastUpdatedBy     NUMBER(11,0)    DEFAULT 0 NOT NULL,
  LastUpdated       DATE,
  LastAccessedBy    NUMBER(11,0)    DEFAULT 0 NOT NULL,
  LastAccessed      DATE
);

CREATE UNIQUE INDEX Shorteners1 ON Shorteners(Code);
