CREATE TABLE PUBLIC.STATE (
 ID INTEGER NOT NULL
 IDENTITY,
 TITLE VARCHAR(255),
 PRIMARY KEY (
 ID
 )
 );
 ;
-- Index SYS_PK_85 wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX SYS_PK_85 ON PUBLIC.STATE (
-- ID
-- );
--;
-- Index IDX_STATEID wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX IDX_STATEID ON PUBLIC.STATE (
-- ID
-- );
--;
CREATE TABLE PUBLIC.APPLICANT (
 ADDRESS_1 VARCHAR(255),
 ADDRESS_2 VARCHAR(255),
 GIVEN_NAME VARCHAR(255),
 ID INTEGER NOT NULL
 IDENTITY,
 NAME VARCHAR(255),
 NATIONALITY VARCHAR(255),
 PRIMARY KEY (
 ID
 )
 );
 ;
-- Index SYS_PK_98 wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX SYS_PK_98 ON PUBLIC.APPLICANT (
-- ID
-- );
--;
-- Index IDX_APPLICANTID wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX IDX_APPLICANTID ON PUBLIC.APPLICANT (
-- ID
-- );
--;
CREATE TABLE PUBLIC.APPLICATION (
 APPLICANT_ID INTEGER,
 ID INTEGER NOT NULL
 IDENTITY,
 PRIMARY KEY (
 ID
 ),
 FOREIGN KEY (APPLICANT_ID) REFERENCES APPLICANT (ID) 
 );
 ;
 CREATE INDEX SYS_IDX_99 ON PUBLIC.APPLICATION (
 APPLICANT_ID
 );
;
-- Index SYS_PK_65 wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX SYS_PK_65 ON PUBLIC.APPLICATION (
-- ID
-- );
--;
-- Index IDX_APPLICATIONID wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX IDX_APPLICATIONID ON PUBLIC.APPLICATION (
-- ID
-- );
--;
CREATE TABLE PUBLIC.PERFORMED_TRANSITION (
 APPLICATION_ID INTEGER,
 FROM_STATE INTEGER,
 ID INTEGER NOT NULL
 IDENTITY,
 TIMESTAMP TIMESTAMP,
 TO_STATE INTEGER,
 PRIMARY KEY (
 ID
 ),
 FOREIGN KEY (APPLICATION_ID) REFERENCES APPLICATION (ID) ,
 FOREIGN KEY (FROM_STATE) REFERENCES STATE (ID) ,
 FOREIGN KEY (TO_STATE) REFERENCES STATE (ID) 
 );
 ;
 CREATE INDEX SYS_IDX_95 ON PUBLIC.PERFORMED_TRANSITION (
 TO_STATE
 );
;
 CREATE INDEX SYS_IDX_91 ON PUBLIC.PERFORMED_TRANSITION (
 APPLICATION_ID
 );
;
 CREATE INDEX SYS_IDX_93 ON PUBLIC.PERFORMED_TRANSITION (
 FROM_STATE
 );
;
-- Index SYS_PK_90 wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX SYS_PK_90 ON PUBLIC.PERFORMED_TRANSITION (
-- ID
-- );
--;
-- Index IDX_PERFORMED_TRANSITIONID wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX IDX_PERFORMED_TRANSITIONID ON PUBLIC.PERFORMED_TRANSITION (
-- ID
-- );
--;
CREATE TABLE PUBLIC.LOGICAL_DOCUMENT (
 APPLICATION_ID INTEGER,
 ID INTEGER NOT NULL
 IDENTITY,
 TITLE VARCHAR(255),
 PRIMARY KEY (
 ID
 ),
 FOREIGN KEY (APPLICATION_ID) REFERENCES APPLICATION (ID) 
 );
 ;
-- Index SYS_PK_68 wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX SYS_PK_68 ON PUBLIC.LOGICAL_DOCUMENT (
-- ID
-- );
--;
 CREATE INDEX SYS_IDX_69 ON PUBLIC.LOGICAL_DOCUMENT (
 APPLICATION_ID
 );
;
-- Index IDX_LOGICAL_DOCUMENTID wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX IDX_LOGICAL_DOCUMENTID ON PUBLIC.LOGICAL_DOCUMENT (
-- ID
-- );
--;
CREATE TABLE PUBLIC.PHYSICAL_DOCUMENT (
 CONTENT VARBINARY,
 ID INTEGER NOT NULL
 IDENTITY,
 LDOC_ID INTEGER,
 TIMESTAMP TIMESTAMP,
 PRIMARY KEY (
 ID
 ),
 FOREIGN KEY (LDOC_ID) REFERENCES LOGICAL_DOCUMENT (ID) 
 );
 ;
 CREATE INDEX SYS_IDX_74 ON PUBLIC.PHYSICAL_DOCUMENT (
 LDOC_ID
 );
;
-- Index SYS_PK_73 wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX SYS_PK_73 ON PUBLIC.PHYSICAL_DOCUMENT (
-- ID
-- );
--;
-- Index IDX_PHYSICAL_DOCUMENTID wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX IDX_PHYSICAL_DOCUMENTID ON PUBLIC.PHYSICAL_DOCUMENT (
-- ID
-- );
--;
CREATE TABLE PUBLIC.USER (
 ID INTEGER NOT NULL
 IDENTITY,
 NAME VARCHAR(255),
 PRIMARY KEY (
 ID
 )
 );
 ;
-- Index SYS_PK_USER wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX SYS_PK_USER ON PUBLIC.USER (
-- ID
-- );
--;
CREATE TABLE PUBLIC.NOTE (
 AUTHOR INTEGER,
 ID INTEGER NOT NULL
 IDENTITY,
 TEXT VARCHAR(255),
 TIMESTAMP TIMESTAMP,
 PRIMARY KEY (
 ID
 ),
 FOREIGN KEY (AUTHOR) REFERENCES USER (ID) 
 );
 ;
-- Index SYS_PK_60 wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX SYS_PK_60 ON PUBLIC.NOTE (
-- ID
-- );
--;
 CREATE INDEX SYS_IDX_61 ON PUBLIC.NOTE (
 AUTHOR
 );
;
CREATE TABLE PUBLIC.DOCUMENT_NOTE (
 ID INTEGER NOT NULL
 IDENTITY,
 NOTE_ID INTEGER,
 PDOC_ID INTEGER,
 PRIMARY KEY (
 ID
 ),
 FOREIGN KEY (NOTE_ID) REFERENCES NOTE (ID) ,
 FOREIGN KEY (PDOC_ID) REFERENCES PHYSICAL_DOCUMENT (ID) 
 );
 ;
-- Index SYS_PK_79 wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX SYS_PK_79 ON PUBLIC.DOCUMENT_NOTE (
-- ID
-- );
--;
-- Index IDX_DOCUMENT_NOTEID wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX IDX_DOCUMENT_NOTEID ON PUBLIC.DOCUMENT_NOTE (
-- ID
-- );
--;
 CREATE INDEX SYS_IDX_80 ON PUBLIC.DOCUMENT_NOTE (
 NOTE_ID
 );
;
 CREATE INDEX SYS_IDX_82 ON PUBLIC.DOCUMENT_NOTE (
 PDOC_ID
 );
;
CREATE TABLE PUBLIC.ROLE (
 ID INTEGER NOT NULL
 IDENTITY,
 TITLE VARCHAR(255),
 USER_ID INTEGER,
 PRIMARY KEY (
 ID
 ),
 FOREIGN KEY (USER_ID) REFERENCES USER (ID) 
 );
 ;
 CREATE INDEX IDX_ROLEUSER_ID ON PUBLIC.ROLE (
 USER_ID
 );
;
-- Index IDX_ROLEID wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX IDX_ROLEID ON PUBLIC.ROLE (
-- ID
-- );
--;
 CREATE INDEX SYS_IDX_104 ON PUBLIC.ROLE (
 USER_ID
 );
;
-- Index SYS_PK_103 wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX SYS_PK_103 ON PUBLIC.ROLE (
-- ID
-- );
--;
CREATE TABLE PUBLIC.TRANSITION (
 FROM_STATE INTEGER,
 ID INTEGER NOT NULL
 IDENTITY,
 ROLE_ID INTEGER,
 TO_STATE INTEGER,
 PRIMARY KEY (
 ID
 ),
 FOREIGN KEY (FROM_STATE) REFERENCES STATE (ID) ,
 FOREIGN KEY (ROLE_ID) REFERENCES ROLE (ID) ,
 FOREIGN KEY (TO_STATE) REFERENCES STATE (ID) 
 );
 ;
-- Index SYS_PK_110 wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX SYS_PK_110 ON PUBLIC.TRANSITION (
-- ID
-- );
--;
-- Index IDX_TRANSITIONID wird automatisch erzeugt (Primärschlüssel)
-- CREATE INDEX IDX_TRANSITIONID ON PUBLIC.TRANSITION (
-- ID
-- );
--;
 CREATE INDEX SYS_IDX_115 ON PUBLIC.TRANSITION (
 ROLE_ID
 );
;
 CREATE INDEX IDX_TRANSITIONFROM_STATE ON PUBLIC.TRANSITION (
 FROM_STATE
 );
;
 CREATE INDEX SYS_IDX_113 ON PUBLIC.TRANSITION (
 TO_STATE
 );
;
 CREATE INDEX SYS_IDX_111 ON PUBLIC.TRANSITION (
 FROM_STATE
 );
;
