
-----------------------------------------------------------------------------
-- FOLDER
-----------------------------------------------------------------------------

CREATE TABLE FOLDER
(
    FOLDER_ID INTEGER NOT NULL,
    PARENT_ID INTEGER,
    PATH VARCHAR(240) NOT NULL,
    NAME VARCHAR(80) NOT NULL,
    TITLE VARCHAR(100),
    SHORT_TITLE VARCHAR(40),
    IS_HIDDEN SMALLINT NOT NULL,
    SKIN VARCHAR(80),
    DEFAULT_LAYOUT_DECORATOR VARCHAR(80),
    DEFAULT_PORTLET_DECORATOR VARCHAR(80),
    DEFAULT_PAGE_NAME VARCHAR(80),
    SUBSITE VARCHAR(40),
    USER_PRINCIPAL VARCHAR(40),
    ROLE_PRINCIPAL VARCHAR(40),
    GROUP_PRINCIPAL VARCHAR(40),
    MEDIATYPE VARCHAR(15),
    LOCALE VARCHAR(20),
    EXT_ATTR_NAME VARCHAR(15),
    EXT_ATTR_VALUE VARCHAR(40),
    OWNER_PRINCIPAL VARCHAR(40),
    UNIQUE (PATH)
);

ALTER TABLE FOLDER
    ADD PRIMARY KEY (FOLDER_ID) ;

CREATE  INDEX IX_FOLDER_1 ON FOLDER (PARENT_ID);


-----------------------------------------------------------------------------
-- FOLDER_METADATA
-----------------------------------------------------------------------------

CREATE TABLE FOLDER_METADATA
(
    METADATA_ID INTEGER NOT NULL,
    FOLDER_ID INTEGER NOT NULL,
    NAME VARCHAR(15) NOT NULL,
    LOCALE VARCHAR(20) NOT NULL,
    VALUE VARCHAR(100) NOT NULL,
    UNIQUE (FOLDER_ID, NAME, LOCALE, VALUE)
);

ALTER TABLE FOLDER_METADATA
    ADD PRIMARY KEY (METADATA_ID) ;

CREATE  INDEX IX_FOLDER_METADATA_1 ON FOLDER_METADATA (FOLDER_ID);


-----------------------------------------------------------------------------
-- FOLDER_CONSTRAINT
-----------------------------------------------------------------------------

CREATE TABLE FOLDER_CONSTRAINT
(
    CONSTRAINT_ID INTEGER NOT NULL,
    FOLDER_ID INTEGER NOT NULL,
    APPLY_ORDER INTEGER NOT NULL,
    USER_PRINCIPALS_ACL VARCHAR(120),
    ROLE_PRINCIPALS_ACL VARCHAR(120),
    GROUP_PRINCIPALS_ACL VARCHAR(120),
    PERMISSIONS_ACL VARCHAR(120)
);

ALTER TABLE FOLDER_CONSTRAINT
    ADD PRIMARY KEY (CONSTRAINT_ID) ;

CREATE  INDEX IX_FOLDER_CONSTRAINT_1 ON FOLDER_CONSTRAINT (FOLDER_ID);


-----------------------------------------------------------------------------
-- FOLDER_CONSTRAINTS_REF
-----------------------------------------------------------------------------

CREATE TABLE FOLDER_CONSTRAINTS_REF
(
    CONSTRAINTS_REF_ID INTEGER NOT NULL,
    FOLDER_ID INTEGER NOT NULL,
    APPLY_ORDER INTEGER NOT NULL,
    NAME VARCHAR(40) NOT NULL,
    UNIQUE (FOLDER_ID, NAME)
);

ALTER TABLE FOLDER_CONSTRAINTS_REF
    ADD PRIMARY KEY (CONSTRAINTS_REF_ID) ;

CREATE  INDEX IX_FOLDER_CONSTRAINTS_REF_1 ON FOLDER_CONSTRAINTS_REF (FOLDER_ID);


-----------------------------------------------------------------------------
-- FOLDER_ORDER
-----------------------------------------------------------------------------

CREATE TABLE FOLDER_ORDER
(
    ORDER_ID INTEGER NOT NULL,
    FOLDER_ID INTEGER NOT NULL,
    SORT_ORDER INTEGER NOT NULL,
    NAME VARCHAR(80) NOT NULL,
    UNIQUE (FOLDER_ID, NAME)
);

ALTER TABLE FOLDER_ORDER
    ADD PRIMARY KEY (ORDER_ID) ;

CREATE  INDEX IX_FOLDER_ORDER_1 ON FOLDER_ORDER (FOLDER_ID);


-----------------------------------------------------------------------------
-- FOLDER_MENU
-----------------------------------------------------------------------------

CREATE TABLE FOLDER_MENU
(
    MENU_ID INTEGER NOT NULL,
    CLASS_NAME VARCHAR(100) NOT NULL,
    PARENT_ID INTEGER,
    FOLDER_ID INTEGER,
    ELEMENT_ORDER INTEGER,
    NAME VARCHAR(100),
    TITLE VARCHAR(100),
    SHORT_TITLE VARCHAR(40),
    TEXT VARCHAR(100),
    OPTIONS VARCHAR(255),
    DEPTH INTEGER,
    IS_PATHS SMALLINT,
    IS_REGEXP SMALLINT,
    PROFILE VARCHAR(80),
    OPTIONS_ORDER VARCHAR(255),
    SKIN VARCHAR(80),
    IS_NEST SMALLINT
);

ALTER TABLE FOLDER_MENU
    ADD PRIMARY KEY (MENU_ID) ;

CREATE  INDEX IX_FOLDER_MENU_1 ON FOLDER_MENU (PARENT_ID);
CREATE  INDEX UN_FOLDER_MENU_1 ON FOLDER_MENU (FOLDER_ID, NAME);


-----------------------------------------------------------------------------
-- FOLDER_MENU_METADATA
-----------------------------------------------------------------------------

CREATE TABLE FOLDER_MENU_METADATA
(
    METADATA_ID INTEGER NOT NULL,
    MENU_ID INTEGER NOT NULL,
    NAME VARCHAR(15) NOT NULL,
    LOCALE VARCHAR(20) NOT NULL,
    VALUE VARCHAR(100) NOT NULL,
    UNIQUE (MENU_ID, NAME, LOCALE, VALUE)
);

ALTER TABLE FOLDER_MENU_METADATA
    ADD PRIMARY KEY (METADATA_ID) ;

CREATE  INDEX IX_FOLDER_MENU_METADATA_1 ON FOLDER_MENU_METADATA (MENU_ID);


-----------------------------------------------------------------------------
-- PAGE
-----------------------------------------------------------------------------

CREATE TABLE PAGE
(
    PAGE_ID INTEGER NOT NULL,
    PARENT_ID INTEGER NOT NULL,
    PATH VARCHAR(240) NOT NULL,
    NAME VARCHAR(80) NOT NULL,
    VERSION VARCHAR(40),
    TITLE VARCHAR(100),
    SHORT_TITLE VARCHAR(40),
    IS_HIDDEN SMALLINT NOT NULL,
    SKIN VARCHAR(80),
    DEFAULT_LAYOUT_DECORATOR VARCHAR(80),
    DEFAULT_PORTLET_DECORATOR VARCHAR(80),
    SUBSITE VARCHAR(40),
    USER_PRINCIPAL VARCHAR(40),
    ROLE_PRINCIPAL VARCHAR(40),
    GROUP_PRINCIPAL VARCHAR(40),
    MEDIATYPE VARCHAR(15),
    LOCALE VARCHAR(20),
    EXT_ATTR_NAME VARCHAR(15),
    EXT_ATTR_VALUE VARCHAR(40),
    OWNER_PRINCIPAL VARCHAR(40),
    UNIQUE (PATH)
);

ALTER TABLE PAGE
    ADD PRIMARY KEY (PAGE_ID) ;

CREATE  INDEX IX_PAGE_1 ON PAGE (PARENT_ID);


-----------------------------------------------------------------------------
-- PAGE_METADATA
-----------------------------------------------------------------------------

CREATE TABLE PAGE_METADATA
(
    METADATA_ID INTEGER NOT NULL,
    PAGE_ID INTEGER NOT NULL,
    NAME VARCHAR(15) NOT NULL,
    LOCALE VARCHAR(20) NOT NULL,
    VALUE VARCHAR(100) NOT NULL,
    UNIQUE (PAGE_ID, NAME, LOCALE, VALUE)
);

ALTER TABLE PAGE_METADATA
    ADD PRIMARY KEY (METADATA_ID) ;

CREATE  INDEX IX_PAGE_METADATA_1 ON PAGE_METADATA (PAGE_ID);


-----------------------------------------------------------------------------
-- PAGE_CONSTRAINT
-----------------------------------------------------------------------------

CREATE TABLE PAGE_CONSTRAINT
(
    CONSTRAINT_ID INTEGER NOT NULL,
    PAGE_ID INTEGER NOT NULL,
    APPLY_ORDER INTEGER NOT NULL,
    USER_PRINCIPALS_ACL VARCHAR(120),
    ROLE_PRINCIPALS_ACL VARCHAR(120),
    GROUP_PRINCIPALS_ACL VARCHAR(120),
    PERMISSIONS_ACL VARCHAR(120)
);

ALTER TABLE PAGE_CONSTRAINT
    ADD PRIMARY KEY (CONSTRAINT_ID) ;

CREATE  INDEX IX_PAGE_CONSTRAINT_1 ON PAGE_CONSTRAINT (PAGE_ID);


-----------------------------------------------------------------------------
-- PAGE_CONSTRAINTS_REF
-----------------------------------------------------------------------------

CREATE TABLE PAGE_CONSTRAINTS_REF
(
    CONSTRAINTS_REF_ID INTEGER NOT NULL,
    PAGE_ID INTEGER NOT NULL,
    APPLY_ORDER INTEGER NOT NULL,
    NAME VARCHAR(40) NOT NULL,
    UNIQUE (PAGE_ID, NAME)
);

ALTER TABLE PAGE_CONSTRAINTS_REF
    ADD PRIMARY KEY (CONSTRAINTS_REF_ID) ;

CREATE  INDEX IX_PAGE_CONSTRAINTS_REF_1 ON PAGE_CONSTRAINTS_REF (PAGE_ID);


-----------------------------------------------------------------------------
-- PAGE_MENU
-----------------------------------------------------------------------------

CREATE TABLE PAGE_MENU
(
    MENU_ID INTEGER NOT NULL,
    CLASS_NAME VARCHAR(100) NOT NULL,
    PARENT_ID INTEGER,
    PAGE_ID INTEGER,
    ELEMENT_ORDER INTEGER,
    NAME VARCHAR(100),
    TITLE VARCHAR(100),
    SHORT_TITLE VARCHAR(40),
    TEXT VARCHAR(100),
    OPTIONS VARCHAR(255),
    DEPTH INTEGER,
    IS_PATHS SMALLINT,
    IS_REGEXP SMALLINT,
    PROFILE VARCHAR(80),
    OPTIONS_ORDER VARCHAR(255),
    SKIN VARCHAR(80),
    IS_NEST SMALLINT
);

ALTER TABLE PAGE_MENU
    ADD PRIMARY KEY (MENU_ID) ;

CREATE  INDEX IX_PAGE_MENU_1 ON PAGE_MENU (PARENT_ID);
CREATE  INDEX UN_PAGE_MENU_1 ON PAGE_MENU (PAGE_ID, NAME);


-----------------------------------------------------------------------------
-- PAGE_MENU_METADATA
-----------------------------------------------------------------------------

CREATE TABLE PAGE_MENU_METADATA
(
    METADATA_ID INTEGER NOT NULL,
    MENU_ID INTEGER NOT NULL,
    NAME VARCHAR(15) NOT NULL,
    LOCALE VARCHAR(20) NOT NULL,
    VALUE VARCHAR(100) NOT NULL,
    UNIQUE (MENU_ID, NAME, LOCALE, VALUE)
);

ALTER TABLE PAGE_MENU_METADATA
    ADD PRIMARY KEY (METADATA_ID) ;

CREATE  INDEX IX_PAGE_MENU_METADATA_1 ON PAGE_MENU_METADATA (MENU_ID);


-----------------------------------------------------------------------------
-- FRAGMENT
-----------------------------------------------------------------------------

CREATE TABLE FRAGMENT
(
    FRAGMENT_ID INTEGER NOT NULL,
    PARENT_ID INTEGER,
    PAGE_ID INTEGER,
    NAME VARCHAR(100),
    TITLE VARCHAR(100),
    SHORT_TITLE VARCHAR(40),
    TYPE VARCHAR(40),
    SKIN VARCHAR(80),
    DECORATOR VARCHAR(80),
    STATE VARCHAR(10),
    PMODE VARCHAR(10),
    LAYOUT_ROW INTEGER,
    LAYOUT_COLUMN INTEGER,
    LAYOUT_SIZES VARCHAR(20),
    LAYOUT_X REAL,
    LAYOUT_Y REAL,
    LAYOUT_Z REAL,
    LAYOUT_WIDTH REAL,
    LAYOUT_HEIGHT REAL,
    EXT_PROP_NAME_1 VARCHAR(40),
    EXT_PROP_VALUE_1 VARCHAR(80),
    EXT_PROP_NAME_2 VARCHAR(40),
    EXT_PROP_VALUE_2 VARCHAR(80),
    OWNER_PRINCIPAL VARCHAR(40)
);

ALTER TABLE FRAGMENT
    ADD PRIMARY KEY (FRAGMENT_ID) ;

CREATE  INDEX IX_FRAGMENT_1 ON FRAGMENT (PARENT_ID);
CREATE  INDEX UN_FRAGMENT_1 ON FRAGMENT (PAGE_ID);


-----------------------------------------------------------------------------
-- FRAGMENT_CONSTRAINT
-----------------------------------------------------------------------------

CREATE TABLE FRAGMENT_CONSTRAINT
(
    CONSTRAINT_ID INTEGER NOT NULL,
    FRAGMENT_ID INTEGER NOT NULL,
    APPLY_ORDER INTEGER NOT NULL,
    USER_PRINCIPALS_ACL VARCHAR(120),
    ROLE_PRINCIPALS_ACL VARCHAR(120),
    GROUP_PRINCIPALS_ACL VARCHAR(120),
    PERMISSIONS_ACL VARCHAR(120)
);

ALTER TABLE FRAGMENT_CONSTRAINT
    ADD PRIMARY KEY (CONSTRAINT_ID) ;

CREATE  INDEX IX_FRAGMENT_CONSTRAINT_1 ON FRAGMENT_CONSTRAINT (FRAGMENT_ID);


-----------------------------------------------------------------------------
-- FRAGMENT_CONSTRAINTS_REF
-----------------------------------------------------------------------------

CREATE TABLE FRAGMENT_CONSTRAINTS_REF
(
    CONSTRAINTS_REF_ID INTEGER NOT NULL,
    FRAGMENT_ID INTEGER NOT NULL,
    APPLY_ORDER INTEGER NOT NULL,
    NAME VARCHAR(40) NOT NULL,
    UNIQUE (FRAGMENT_ID, NAME)
);

ALTER TABLE FRAGMENT_CONSTRAINTS_REF
    ADD PRIMARY KEY (CONSTRAINTS_REF_ID) ;

CREATE  INDEX IX_FRAGMENT_CONSTRAINTS_REF_1 ON FRAGMENT_CONSTRAINTS_REF (FRAGMENT_ID);


-----------------------------------------------------------------------------
-- FRAGMENT_PREF
-----------------------------------------------------------------------------

CREATE TABLE FRAGMENT_PREF
(
    PREF_ID INTEGER NOT NULL,
    FRAGMENT_ID INTEGER NOT NULL,
    NAME VARCHAR(40) NOT NULL,
    IS_READ_ONLY SMALLINT NOT NULL,
    UNIQUE (FRAGMENT_ID, NAME)
);

ALTER TABLE FRAGMENT_PREF
    ADD PRIMARY KEY (PREF_ID) ;

CREATE  INDEX IX_FRAGMENT_PREF_1 ON FRAGMENT_PREF (FRAGMENT_ID);


-----------------------------------------------------------------------------
-- FRAGMENT_PREF_VALUE
-----------------------------------------------------------------------------

CREATE TABLE FRAGMENT_PREF_VALUE
(
    PREF_VALUE_ID INTEGER NOT NULL,
    PREF_ID INTEGER NOT NULL,
    VALUE_ORDER INTEGER NOT NULL,
    VALUE VARCHAR(100) NOT NULL
);

ALTER TABLE FRAGMENT_PREF_VALUE
    ADD PRIMARY KEY (PREF_VALUE_ID) ;

CREATE  INDEX IX_FRAGMENT_PREF_VALUE_1 ON FRAGMENT_PREF_VALUE (PREF_ID);


-----------------------------------------------------------------------------
-- LINK
-----------------------------------------------------------------------------

CREATE TABLE LINK
(
    LINK_ID INTEGER NOT NULL,
    PARENT_ID INTEGER NOT NULL,
    PATH VARCHAR(240) NOT NULL,
    NAME VARCHAR(80) NOT NULL,
    VERSION VARCHAR(40),
    TITLE VARCHAR(100),
    SHORT_TITLE VARCHAR(40),
    IS_HIDDEN SMALLINT NOT NULL,
    SKIN VARCHAR(80),
    TARGET VARCHAR(80),
    URL VARCHAR(255),
    SUBSITE VARCHAR(40),
    USER_PRINCIPAL VARCHAR(40),
    ROLE_PRINCIPAL VARCHAR(40),
    GROUP_PRINCIPAL VARCHAR(40),
    MEDIATYPE VARCHAR(15),
    LOCALE VARCHAR(20),
    EXT_ATTR_NAME VARCHAR(15),
    EXT_ATTR_VALUE VARCHAR(40),
    OWNER_PRINCIPAL VARCHAR(40),
    UNIQUE (PATH)
);

ALTER TABLE LINK
    ADD PRIMARY KEY (LINK_ID) ;

CREATE  INDEX IX_LINK_1 ON LINK (PARENT_ID);


-----------------------------------------------------------------------------
-- LINK_METADATA
-----------------------------------------------------------------------------

CREATE TABLE LINK_METADATA
(
    METADATA_ID INTEGER NOT NULL,
    LINK_ID INTEGER NOT NULL,
    NAME VARCHAR(15) NOT NULL,
    LOCALE VARCHAR(20) NOT NULL,
    VALUE VARCHAR(100) NOT NULL,
    UNIQUE (LINK_ID, NAME, LOCALE, VALUE)
);

ALTER TABLE LINK_METADATA
    ADD PRIMARY KEY (METADATA_ID) ;

CREATE  INDEX IX_LINK_METADATA_1 ON LINK_METADATA (LINK_ID);


-----------------------------------------------------------------------------
-- LINK_CONSTRAINT
-----------------------------------------------------------------------------

CREATE TABLE LINK_CONSTRAINT
(
    CONSTRAINT_ID INTEGER NOT NULL,
    LINK_ID INTEGER NOT NULL,
    APPLY_ORDER INTEGER NOT NULL,
    USER_PRINCIPALS_ACL VARCHAR(120),
    ROLE_PRINCIPALS_ACL VARCHAR(120),
    GROUP_PRINCIPALS_ACL VARCHAR(120),
    PERMISSIONS_ACL VARCHAR(120)
);

ALTER TABLE LINK_CONSTRAINT
    ADD PRIMARY KEY (CONSTRAINT_ID) ;

CREATE  INDEX IX_LINK_CONSTRAINT_1 ON LINK_CONSTRAINT (LINK_ID);


-----------------------------------------------------------------------------
-- LINK_CONSTRAINTS_REF
-----------------------------------------------------------------------------

CREATE TABLE LINK_CONSTRAINTS_REF
(
    CONSTRAINTS_REF_ID INTEGER NOT NULL,
    LINK_ID INTEGER NOT NULL,
    APPLY_ORDER INTEGER NOT NULL,
    NAME VARCHAR(40) NOT NULL,
    UNIQUE (LINK_ID, NAME)
);

ALTER TABLE LINK_CONSTRAINTS_REF
    ADD PRIMARY KEY (CONSTRAINTS_REF_ID) ;

CREATE  INDEX IX_LINK_CONSTRAINTS_REF_1 ON LINK_CONSTRAINTS_REF (LINK_ID);


-----------------------------------------------------------------------------
-- PAGE_SECURITY
-----------------------------------------------------------------------------

CREATE TABLE PAGE_SECURITY
(
    PAGE_SECURITY_ID INTEGER NOT NULL,
    PARENT_ID INTEGER NOT NULL,
    PATH VARCHAR(240) NOT NULL,
    NAME VARCHAR(80) NOT NULL,
    VERSION VARCHAR(40),
    SUBSITE VARCHAR(40),
    USER_PRINCIPAL VARCHAR(40),
    ROLE_PRINCIPAL VARCHAR(40),
    GROUP_PRINCIPAL VARCHAR(40),
    MEDIATYPE VARCHAR(15),
    LOCALE VARCHAR(20),
    EXT_ATTR_NAME VARCHAR(15),
    EXT_ATTR_VALUE VARCHAR(40),
    UNIQUE (PARENT_ID),
    UNIQUE (PATH)
);

ALTER TABLE PAGE_SECURITY
    ADD PRIMARY KEY (PAGE_SECURITY_ID) ;



-----------------------------------------------------------------------------
-- PAGE_SEC_CONSTRAINTS_DEF
-----------------------------------------------------------------------------

CREATE TABLE PAGE_SEC_CONSTRAINTS_DEF
(
    CONSTRAINTS_DEF_ID INTEGER NOT NULL,
    PAGE_SECURITY_ID INTEGER NOT NULL,
    NAME VARCHAR(40) NOT NULL,
    UNIQUE (PAGE_SECURITY_ID, NAME)
);

ALTER TABLE PAGE_SEC_CONSTRAINTS_DEF
    ADD PRIMARY KEY (CONSTRAINTS_DEF_ID) ;

CREATE  INDEX IX_PAGE_SEC_CONSTRAINTS_DEF_1 ON PAGE_SEC_CONSTRAINTS_DEF (PAGE_SECURITY_ID);


-----------------------------------------------------------------------------
-- PAGE_SEC_CONSTRAINT_DEF
-----------------------------------------------------------------------------

CREATE TABLE PAGE_SEC_CONSTRAINT_DEF
(
    CONSTRAINT_DEF_ID INTEGER NOT NULL,
    CONSTRAINTS_DEF_ID INTEGER NOT NULL,
    APPLY_ORDER INTEGER NOT NULL,
    USER_PRINCIPALS_ACL VARCHAR(120),
    ROLE_PRINCIPALS_ACL VARCHAR(120),
    GROUP_PRINCIPALS_ACL VARCHAR(120),
    PERMISSIONS_ACL VARCHAR(120)
);

ALTER TABLE PAGE_SEC_CONSTRAINT_DEF
    ADD PRIMARY KEY (CONSTRAINT_DEF_ID) ;

CREATE  INDEX IX_PAGE_SEC_CONSTRAINT_DEF_1 ON PAGE_SEC_CONSTRAINT_DEF (CONSTRAINTS_DEF_ID);


-----------------------------------------------------------------------------
-- PAGE_SEC_CONSTRAINTS_REF
-----------------------------------------------------------------------------

CREATE TABLE PAGE_SEC_CONSTRAINTS_REF
(
    CONSTRAINTS_REF_ID INTEGER NOT NULL,
    PAGE_SECURITY_ID INTEGER NOT NULL,
    APPLY_ORDER INTEGER NOT NULL,
    NAME VARCHAR(40) NOT NULL,
    UNIQUE (PAGE_SECURITY_ID, NAME)
);

ALTER TABLE PAGE_SEC_CONSTRAINTS_REF
    ADD PRIMARY KEY (CONSTRAINTS_REF_ID) ;

CREATE  INDEX IX_PAGE_SEC_CONSTRAINTS_REF_1 ON PAGE_SEC_CONSTRAINTS_REF (PAGE_SECURITY_ID);


-----------------------------------------------------------------------------
-- PROFILING_RULE
-----------------------------------------------------------------------------

CREATE TABLE PROFILING_RULE
(
    RULE_ID VARCHAR(80) NOT NULL,
    CLASS_NAME VARCHAR(100) NOT NULL,
    TITLE VARCHAR(100)
);

ALTER TABLE PROFILING_RULE
    ADD PRIMARY KEY (RULE_ID) ;



-----------------------------------------------------------------------------
-- RULE_CRITERION
-----------------------------------------------------------------------------

CREATE TABLE RULE_CRITERION
(
    CRITERION_ID VARCHAR(80) NOT NULL,
    RULE_ID VARCHAR(80) NOT NULL,
    FALLBACK_ORDER INTEGER NOT NULL,
    REQUEST_TYPE VARCHAR(40) NOT NULL,
    NAME VARCHAR(80) NOT NULL,
    COLUMN_VALUE VARCHAR(128),
    FALLBACK_TYPE INTEGER default 1
);

ALTER TABLE RULE_CRITERION
    ADD PRIMARY KEY (CRITERION_ID) ;

CREATE  INDEX IX_RULE_CRITERION_1 ON RULE_CRITERION (RULE_ID, FALLBACK_ORDER);


-----------------------------------------------------------------------------
-- PRINCIPAL_RULE_ASSOC
-----------------------------------------------------------------------------

CREATE TABLE PRINCIPAL_RULE_ASSOC
(
    PRINCIPAL_NAME VARCHAR(80) NOT NULL,
    LOCATOR_NAME VARCHAR(80) NOT NULL,
    RULE_ID VARCHAR(80) NOT NULL
);

ALTER TABLE PRINCIPAL_RULE_ASSOC
    ADD PRIMARY KEY (PRINCIPAL_NAME,LOCATOR_NAME) ;



-----------------------------------------------------------------------------
-- PROFILE_PAGE_ASSOC
-----------------------------------------------------------------------------

CREATE TABLE PROFILE_PAGE_ASSOC
(
    LOCATOR_HASH VARCHAR(40) NOT NULL,
    PAGE_ID VARCHAR(80) NOT NULL,
    UNIQUE (LOCATOR_HASH, PAGE_ID)
);




-----------------------------------------------------------------------------
-- CLUBS
-----------------------------------------------------------------------------

CREATE TABLE CLUBS
(
    NAME VARCHAR(80) NOT NULL,
    COUNTRY VARCHAR(40) NOT NULL,
    CITY VARCHAR(40) NOT NULL,
    STADIUM VARCHAR(80) NOT NULL,
    CAPACITY INTEGER,
    FOUNDED INTEGER,
    PITCH VARCHAR(40),
    NICKNAME VARCHAR(40)
);

ALTER TABLE CLUBS
    ADD PRIMARY KEY (NAME) ;


ALTER TABLE FOLDER
    FOREIGN KEY FK_FOLDER_1 (PARENT_ID)
    REFERENCES FOLDER (FOLDER_ID)
;


ALTER TABLE FOLDER_METADATA
    FOREIGN KEY FK_FOLDER_METADATA_1 (FOLDER_ID)
    REFERENCES FOLDER (FOLDER_ID)
;


ALTER TABLE FOLDER_CONSTRAINT
    FOREIGN KEY FK_FOLDER_CONSTRAINT_1 (FOLDER_ID)
    REFERENCES FOLDER (FOLDER_ID)
;


ALTER TABLE FOLDER_CONSTRAINTS_REF
    FOREIGN KEY FK_FOLDER_CONSTRAINTS_REF_1 (FOLDER_ID)
    REFERENCES FOLDER (FOLDER_ID)
;


ALTER TABLE FOLDER_ORDER
    FOREIGN KEY FK_FOLDER_ORDER_1 (FOLDER_ID)
    REFERENCES FOLDER (FOLDER_ID)
;


ALTER TABLE FOLDER_MENU
    FOREIGN KEY FK_FOLDER_MENU_1 (PARENT_ID)
    REFERENCES FOLDER_MENU (MENU_ID)
;

ALTER TABLE FOLDER_MENU
    FOREIGN KEY FK_FOLDER_MENU_2 (FOLDER_ID)
    REFERENCES FOLDER (FOLDER_ID)
;


ALTER TABLE FOLDER_MENU_METADATA
    FOREIGN KEY FK_FOLDER_MENU_METADATA_1 (MENU_ID)
    REFERENCES FOLDER_MENU (MENU_ID)
;


ALTER TABLE PAGE
    FOREIGN KEY FK_PAGE_1 (PARENT_ID)
    REFERENCES FOLDER (FOLDER_ID)
;


ALTER TABLE PAGE_METADATA
    FOREIGN KEY FK_PAGE_METADATA_1 (PAGE_ID)
    REFERENCES PAGE (PAGE_ID)
;


ALTER TABLE PAGE_CONSTRAINT
    FOREIGN KEY FK_PAGE_CONSTRAINT_1 (PAGE_ID)
    REFERENCES PAGE (PAGE_ID)
;


ALTER TABLE PAGE_CONSTRAINTS_REF
    FOREIGN KEY FK_PAGE_CONSTRAINTS_REF_1 (PAGE_ID)
    REFERENCES PAGE (PAGE_ID)
;


ALTER TABLE PAGE_MENU
    FOREIGN KEY FK_PAGE_MENU_1 (PARENT_ID)
    REFERENCES PAGE_MENU (MENU_ID)
;

ALTER TABLE PAGE_MENU
    FOREIGN KEY PM_M_FK_PAGE_ID_PAGE (PAGE_ID)
    REFERENCES PAGE (PAGE_ID)
;


ALTER TABLE PAGE_MENU_METADATA
    FOREIGN KEY FK_PAGE_MENU_METADATA_1 (MENU_ID)
    REFERENCES PAGE_MENU (MENU_ID)
;


ALTER TABLE FRAGMENT
    FOREIGN KEY FK_FRAGMENT_1 (PARENT_ID)
    REFERENCES FRAGMENT (FRAGMENT_ID)
;

ALTER TABLE FRAGMENT
    FOREIGN KEY FK_FRAGMENT_2 (PAGE_ID)
    REFERENCES PAGE (PAGE_ID)
;


ALTER TABLE FRAGMENT_CONSTRAINT
    FOREIGN KEY FK_FRAGMENT_CONSTRAINT_1 (FRAGMENT_ID)
    REFERENCES FRAGMENT (FRAGMENT_ID)
;


ALTER TABLE FRAGMENT_CONSTRAINTS_REF
    FOREIGN KEY FK_FRAGMENT_CONSTRAINTS_REF_1 (FRAGMENT_ID)
    REFERENCES FRAGMENT (FRAGMENT_ID)
;


ALTER TABLE FRAGMENT_PREF
    FOREIGN KEY FK_FRAGMENT_PREF_1 (FRAGMENT_ID)
    REFERENCES FRAGMENT (FRAGMENT_ID)
;


ALTER TABLE FRAGMENT_PREF_VALUE
    FOREIGN KEY FK_FRAGMENT_PREF_VALUE_1 (PREF_ID)
    REFERENCES FRAGMENT_PREF (PREF_ID)
;


ALTER TABLE LINK
    FOREIGN KEY FK_LINK_1 (PARENT_ID)
    REFERENCES FOLDER (FOLDER_ID)
;


ALTER TABLE LINK_METADATA
    FOREIGN KEY FK_LINK_METADATA_1 (LINK_ID)
    REFERENCES LINK (LINK_ID)
;


ALTER TABLE LINK_CONSTRAINT
    FOREIGN KEY FK_LINK_CONSTRAINT_1 (LINK_ID)
    REFERENCES LINK (LINK_ID)
;


ALTER TABLE LINK_CONSTRAINTS_REF
    FOREIGN KEY FK_LINK_CONSTRAINTS_REF_1 (LINK_ID)
    REFERENCES LINK (LINK_ID)
;


ALTER TABLE PAGE_SECURITY
    FOREIGN KEY FK_PAGE_SECURITY_1 (PARENT_ID)
    REFERENCES FOLDER (FOLDER_ID)
;


ALTER TABLE PAGE_SEC_CONSTRAINTS_DEF
    FOREIGN KEY FK_PAGE_SEC_CONSTRAINTS_DEF_1 (PAGE_SECURITY_ID)
    REFERENCES PAGE_SECURITY (PAGE_SECURITY_ID)
;


ALTER TABLE PAGE_SEC_CONSTRAINT_DEF
    FOREIGN KEY FK_PAGE_SEC_CONSTRAINT_DEF_1 (CONSTRAINTS_DEF_ID)
    REFERENCES PAGE_SEC_CONSTRAINTS_DEF (CONSTRAINTS_DEF_ID)
;


ALTER TABLE PAGE_SEC_CONSTRAINTS_REF
    FOREIGN KEY FK_PAGE_SEC_CONSTRAINTS_REF_1 (PAGE_SECURITY_ID)
    REFERENCES PAGE_SECURITY (PAGE_SECURITY_ID)
;



ALTER TABLE RULE_CRITERION
    FOREIGN KEY FK_RULE_CRITERION_1 (RULE_ID)
    REFERENCES PROFILING_RULE (RULE_ID)
;





