# -----------------------------------------------------------------------------
# -- Copyright 2004 The Apache Software Foundation
# -- 
# -- Licensed under the Apache License, Version 2.0 (the "License");
# -- you may not use this file except in compliance with the License.
# -- You may obtain a copy of the License at
# -- 
# -- http://www.apache.org/licenses/LICENSE-2.0
# -- 
# -- Unless required by applicable law or agreed to in writing, software
# -- distributed under the License is distributed on an "AS IS" BASIS,
# -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# -- See the License for the specific language governing permissions and
# -- limitations under the License.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# -- TURBINE_PERMISSION
# -----------------------------------------------------------------------------
CREATE TABLE TURBINE_PERMISSION
(
    PERMISSION_ID integer NOT NULL PRIMARY KEY,
    PERMISSION_NAME VARCHAR (99) NOT NULL UNIQUE ,
    OBJECTDATA BLOB
);
  
# -----------------------------------------------------------------------------
# -- TURBINE_ROLE
# -----------------------------------------------------------------------------
CREATE TABLE TURBINE_ROLE
(
    ROLE_ID integer NOT NULL PRIMARY KEY ,
    ROLE_NAME VARCHAR (99) NOT NULL UNIQUE,
    OBJECTDATA BLOB
);

# -----------------------------------------------------------------------------
# -- TURBINE_GROUP
# -----------------------------------------------------------------------------
CREATE TABLE TURBINE_GROUP
(
    GROUP_ID integer NOT NULL PRIMARY KEY ,
    GROUP_NAME VARCHAR (99) NOT NULL UNIQUE,
    OBJECTDATA BLOB
);

# -----------------------------------------------------------------------------
# -- TURBINE_ROLE_PERMISSION
# -----------------------------------------------------------------------------
CREATE TABLE TURBINE_ROLE_PERMISSION
(
    ROLE_ID integer NOT NULL,
    PERMISSION_ID integer NOT NULL,
    PRIMARY KEY(ROLE_ID,PERMISSION_ID)
);

CREATE  INDEX ROLE_PERMISSION_INDEX ON TURBINE_ROLE_PERMISSION (ROLE_ID, PERMISSION_ID);

# -----------------------------------------------------------------------------
# -- TURBINE_USER
# -----------------------------------------------------------------------------
CREATE TABLE TURBINE_USER
(
    USER_ID integer NOT NULL PRIMARY KEY ,
    LOGIN_NAME VARCHAR (32) NOT NULL UNIQUE,
    PASSWORD_VALUE VARCHAR (32) NOT NULL,
    FIRST_NAME VARCHAR (99) NOT NULL,
    LAST_NAME VARCHAR (99) NOT NULL,
    EMAIL VARCHAR (99),
    CONFIRM_VALUE VARCHAR (99),
    MODIFIED timestamp,
    CREATED timestamp,
    LAST_LOGIN timestamp,
    DISABLED CHAR,
    OBJECTDATA BLOB,
    PASSWORD_CHANGED DATE
);

# -----------------------------------------------------------------------------
# -- TURBINE_USER_GROUP_ROLE
# -----------------------------------------------------------------------------
CREATE TABLE TURBINE_USER_GROUP_ROLE
(
    USER_ID integer NOT NULL,
    GROUP_ID integer NOT NULL,
    ROLE_ID integer NOT NULL,
    PRIMARY KEY(USER_ID,GROUP_ID,ROLE_ID)
);

CREATE  INDEX USER_GROUP_ROLE_INDEX ON TURBINE_USER_GROUP_ROLE (USER_ID, GROUP_ID, ROLE_ID);

# -----------------------------------------------------------------------------
# -- TURBINE_SCHEDULED_JOB
# -----------------------------------------------------------------------------
CREATE TABLE TURBINE_SCHEDULED_JOB
(
    JOB_ID integer NOT NULL,
    SECOND integer default -1 NOT NULL,
    MINUTE integer default -1 NOT NULL,
    HOUR integer default -1 NOT NULL,
    WEEK_DAY integer default -1 NOT NULL,
    DAY_OF_MONTH integer default -1 NOT NULL,
    TASK VARCHAR (99) NOT NULL,
    EMAIL VARCHAR (99),
    PRIMARY KEY(JOB_ID)
);

# -----------------------------------------------------------------------------
# -- COFFEES
# -----------------------------------------------------------------------------
CREATE TABLE COFFEES
(
    COFFEE_ID integer PRIMARY KEY,
    COFFEE_NAME VARCHAR (50),
    SUPPLIER_ID integer,
    PRICE FLOAT,
    SALES integer,
    TOTAL integer
);

# -----------------------------------------------------------------------------
# -- EMAIL
# -----------------------------------------------------------------------------
drop table if exists EMAIL_INBOX;

CREATE TABLE EMAIL_INBOX (
  EMAIL_INBOX_ID integer(11) NOT NULL auto_increment,
  MESSAGE_ID varchar(255) default NULL,
  FILENAME varchar(255) default NULL,
  ATTACHMENT longblob,
  READFLAG int(11) default NULL,
  PRIMARY KEY  (EMAIL_INBOX_ID)
);



# -----------------------------------------------------------------------
# portlet
# -----------------------------------------------------------------------
drop table if exists portlet;

CREATE TABLE portlet
(
                    ID BIGINT NOT NULL AUTO_INCREMENT,
                    NAME VARCHAR (128) NOT NULL,
                    HIDDEN INTEGER default 0,
                    CLASSNAME VARCHAR (255),
                    TYPE VARCHAR (32) NOT NULL,
                    APPLICATION INTEGER default 0,
                    PARENT VARCHAR (128),
                    URL VARCHAR (255),
                    CACHED_ON_URL INTEGER default 1,
                    TITLE VARCHAR (128),
                    DESCRIPTION VARCHAR (255),
                    IMAGE VARCHAR (128),
                    SECURITY VARCHAR (128),
    PRIMARY KEY(ID),
    UNIQUE (NAME)
);

# -----------------------------------------------------------------------
# portlet_category
# -----------------------------------------------------------------------
drop table if exists portlet_category;

CREATE TABLE portlet_category
(
                    ID BIGINT NOT NULL AUTO_INCREMENT,
                    NAME VARCHAR (128) NOT NULL,
                    GROUPE VARCHAR (128) NOT NULL,
                    PORTLET_ID BIGINT,
    PRIMARY KEY(ID),
    FOREIGN KEY (PORTLET_ID) REFERENCES portlet (ID)
        ON DELETE CASCADE 
  
);

# -----------------------------------------------------------------------
# portlet_parameter
# -----------------------------------------------------------------------
drop table if exists portlet_parameter;

CREATE TABLE portlet_parameter
(
                    ID BIGINT NOT NULL AUTO_INCREMENT,
                    NAME VARCHAR (128) NOT NULL,
                    VALUE VARCHAR (255) default '0',
                    TYPE VARCHAR (64),
                    HIDDEN INTEGER default 0,
                    CACHED_ON_VALUE INTEGER default 1,
                    CACHED_ON_NAME INTEGER default 1,
                    TITLE VARCHAR (128),
                    DESCRIPTION VARCHAR (255),
                    IMAGE VARCHAR (128),
                    PORTLET_ID BIGINT,
                    SECURITY VARCHAR (128),
    PRIMARY KEY(ID),
    FOREIGN KEY (PORTLET_ID) REFERENCES portlet (ID)
        ON DELETE CASCADE 
  
);

# -----------------------------------------------------------------------
# portlet_mediatype
# -----------------------------------------------------------------------
drop table if exists portlet_mediatype;

CREATE TABLE portlet_mediatype
(
                    ID BIGINT NOT NULL AUTO_INCREMENT,
                    NAME VARCHAR (128) NOT NULL,
                    PORTLET_ID BIGINT,
    PRIMARY KEY(ID),
    FOREIGN KEY (PORTLET_ID) REFERENCES portlet (ID)
        ON DELETE CASCADE 
  
);

# -----------------------------------------------------------------------
# security_entry
# -----------------------------------------------------------------------
drop table if exists security_entry;

CREATE TABLE security_entry
(
                    ID BIGINT NOT NULL AUTO_INCREMENT,
                    NAME VARCHAR (128) NOT NULL,
                    TITLE VARCHAR (128),
                    DESCRIPTION VARCHAR (255),
    PRIMARY KEY(ID),
    UNIQUE (NAME)
);

# -----------------------------------------------------------------------
# security_access
# -----------------------------------------------------------------------
drop table if exists security_access;

CREATE TABLE security_access
(
                    ID BIGINT NOT NULL AUTO_INCREMENT,
                    ACTION VARCHAR (32) NOT NULL,
                    ENTRY_ID BIGINT,
    PRIMARY KEY(ID),
    FOREIGN KEY (ENTRY_ID) REFERENCES security_entry (ID)
        ON DELETE CASCADE 
  
);

# -----------------------------------------------------------------------
# security_allow
# -----------------------------------------------------------------------
drop table if exists security_allow;

CREATE TABLE security_allow
(
                    ID BIGINT NOT NULL AUTO_INCREMENT,
                    ALLOW_TYPE VARCHAR (32) NOT NULL,
                    ALLOW_VALUE VARCHAR (32) NOT NULL,
                    ALLOW_GROUP VARCHAR (32),
                    ACCESS_ID BIGINT,
    PRIMARY KEY(ID),
    FOREIGN KEY (ACCESS_ID) REFERENCES security_access (ID)
        ON DELETE CASCADE 
  
);
  
  


