-- Licensed Materials - Property of IBM
-- 5724-I68
--
-- (C) Copyright IBM Corp. 2000, 2006
--
-- US Government Users Restricted Rights - Use, duplication, or
-- disclosure restricted by GSA ADP Schedule Contract with IBM Corp.



update command options using c off;

-- ===================================================================
--
-- Table tsec_scu_user
--
-- All users are kept in this table. Additional fields will be added
-- as needed. Currently only being used to support login and display
-- the users name. Also, the user's company is retrieved from this
-- table and the scu_company_id plays a critical role in all operations
-- in Trigo. The active field (Y/N) shows if the user is enabled or
-- disabled. An user can only login if the active field is 'Y'.
-- ===================================================================

drop table tsec_scu_user;
create table tsec_scu_user
( 
    scu_user_id                   bigint not null,
    scu_active                    char,
    scu_username                  varchar(400) not null,
    scu_password                  varchar(32),
    scu_first_name                varchar(100),
    scu_last_name                 varchar(100),
    scu_company_id                bigint not null,
    scu_user_phone                varchar(20),
    scu_user_address              varchar(200),
    scu_user_email                varchar(40),
    scu_user_title                varchar(40),
    scu_user_fax                  varchar(20),
    scu_log_flag                  bigint,
    scu_ldap_flag                 char,
    scu_notify_email              varchar(40),
    scu_ldap_entry_dn             varchar(750),
    scu_ldap_svr_url              varchar(800),
    constraint scu_0_pk
        primary key (scu_user_id),
    constraint scu_1_uk
        unique (scu_username, scu_company_id)
) 

in users index in indx;


drop synonym scu;
create synonym scu for tsec_scu_user;

drop sequence qsec_scu_user_id restrict;
create sequence qsec_scu_user_id start with 1 increment by 200 nocache;

-- ===================================================================
--
-- Table tsec_ust_user_setting
--
-- The user settings is an add-on to the security infrastructure and does not deal with
-- authentication or authorization, but with default values, user preferences, etc.
-- ===================================================================

drop table tsec_ust_user_setting;
create table tsec_ust_user_setting
( 
    ust_company_id                bigint,
    ust_user_id                   bigint,
    ust_user_settable             char,
    ust_setting                   varchar(100),
    ust_instance                  varchar(100),
    ust_value                     varchar(3000)
) 

in users index in indx;


drop synonym ust;
create synonym ust for tsec_ust_user_setting;

-- ===================================================================
--
-- Table tsec_lot_login_times
--
-- This table contains information about successful logins and subsequent logouts for
-- users. Both the login and logout times are stored as well as the logout method, saved
-- in the field 'logout_method' which can currently hold the following values:
-- T - if a session timeout occurred
-- U - if the user manually logged out of the app
-- S - if some kind of system error occurred.
-- ===================================================================

drop table tsec_lot_login_times;
create table tsec_lot_login_times
( 
    lot_session_id                bigint,
    lot_user_id                   bigint,
    lot_company_id                bigint,
    lot_login_time                timestamp,
    lot_logout_time               timestamp,
    lot_logout_method             varchar(1),
    lot_service_name              varchar(100)
) 

in users index in indx;


drop synonym lot;
create synonym lot for tsec_lot_login_times;

drop sequence qsec_lot_session_id restrict;
create sequence qsec_lot_session_id start with 1 increment by 200 nocache;

-- ===================================================================
--
-- Table tsec_cmp_company
--
-- All companies are kept in this table. This includes Trigo, all
-- marketplaces and Trigo customers.
-- The type is one of the following values:
-- 'T' Trigo
-- 'M' Marketplace
-- 'S' Supplier
-- We expect that the type will evolve since we would want to keep
-- track of the different e-commerce models that each marketplace
-- supports. We might also want to keep more information about the
-- supplier.
-- Also, the company_id is generated from two sequences so that
-- we can distinguish the company in other tables.
-- ===================================================================

drop table tsec_cmp_company;
create table tsec_cmp_company
( 
    cmp_company_id                bigint not null,
    cmp_company_name              varchar(60),
    cmp_company_code              varchar(20),
    cmp_company_type              char,
    cmp_directory                 varchar(1000),
    cmp_company_url               varchar(200),
    constraint cmp_0_pk
        primary key (cmp_company_id)
) 

in users index in indx;


drop synonym cmp;
create synonym cmp for tsec_cmp_company;

-- ===================================================================
--
-- Table tsec_lnk_mylinks
--
-- User's personnal links are kept here. The lnk_link is a string
-- the should match one of the ids on the menu.xml file
-- ===================================================================

drop table tsec_lnk_mylinks;
create table tsec_lnk_mylinks
( 
    lnk_company_id                bigint not null,
    lnk_user_id                   bigint not null,
    lnk_link                      varchar(200) not null,
    lnk_creation_date             timestamp,
    constraint lnk_0_pk
        primary key (lnk_company_id, lnk_user_id, lnk_link)
) 

in users index in indx;


drop synonym lnk;
create synonym lnk for tsec_lnk_mylinks;

-- ===================================================================
--
-- Table tsec_log_useractivity
--

-- ===================================================================

drop table tsec_log_useractivity;
create table tsec_log_useractivity
( 
    log_user_id                   bigint,
    log_company_id                bigint,
    log_page_id                   bigint,
    log_date                      timestamp
) 

in users index in indx;


drop synonym log;
create synonym log for tsec_log_useractivity;

-- ===================================================================
--
-- Table tsec_oac_object_action
--
-- Object Actions may have company_type assigned to them, to reflect that
-- the actions on objects applies to all the companies of that type.
-- The Company type is one of the following values:
-- 'T' Trigo
-- 'M' Marketplace
-- 'S' Supplier
-- ===================================================================

drop table tsec_oac_object_action;
create table tsec_oac_object_action
( 
    oac_id                        bigint not null,
    oac_name                      varchar(60),
    oac_desc                      varchar(200),
    oac_object_type_id            bigint,
    oac_company_type              char,
    oac_default_obg               char,
    constraint oac_0_pk
        primary key (oac_id)
) 

in users index in indx;


drop synonym oac;
create synonym oac for tsec_oac_object_action;

drop sequence qsec_oac_id restrict;
create sequence qsec_oac_id start with 1 increment by 200 nocache;

-- ===================================================================
--
-- Table tsec_rol_role
--

-- ===================================================================

drop table tsec_rol_role;
create table tsec_rol_role
( 
    rol_company_id                bigint,
    rol_role_id                   bigint not null,
    rol_role_name                 varchar(100),
    rol_role_desc                 varchar(200),
    constraint rol_0_pk
        primary key (rol_role_id)
) 

in users index in indx;


drop synonym rol;
create synonym rol for tsec_rol_role;

drop sequence qsec_rol_role_id restrict;
create sequence qsec_rol_role_id start with 1 increment by 200 nocache;

-- ===================================================================
--
-- Table tsec_rat_role_attributes
--

-- ===================================================================

drop table tsec_rat_role_attributes;
create table tsec_rat_role_attributes
( 
    rat_company_id                bigint,
    rat_role_id                   bigint,
    rat_name                      varchar(100),
    rat_attr_value                varchar(900),
    rat_row_order                 bigint
) 

in users index in indx;


drop synonym rat;
create synonym rat for tsec_rat_role_attributes;

-- ===================================================================
--
-- Table tsec_urm_user_role_map
--

-- ===================================================================

drop table tsec_urm_user_role_map;
create table tsec_urm_user_role_map
( 
    urm_company_id                bigint,
    urm_user_id                   bigint,
    urm_role_id                   bigint,
    urm_role_request_flag         char
) 

in users index in indx;


drop synonym urm;
create synonym urm for tsec_urm_user_role_map;

-- ===================================================================
--
-- Table tsec_obt_object_type
--

-- ===================================================================

drop table tsec_obt_object_type;
create table tsec_obt_object_type
( 
    obt_id                        bigint,
    obt_name                      varchar(60),
    obt_desc                      varchar(200),
    obt_default_obg               char
) 

in users index in indx;


drop synonym obt;
create synonym obt for tsec_obt_object_type;

drop sequence qsec_obt_id restrict;
create sequence qsec_obt_id start with 1 increment by 200 nocache;

-- ===================================================================
--
-- Table tsec_cot_company_attrib
--
-- This table stores attributes of a company
-- ===================================================================

drop table tsec_cot_company_attrib;
create table tsec_cot_company_attrib
( 
    cot_company_id                bigint,
    cot_attrib_name               varchar(100),
    cot_attrib_value              varchar(3000)
) 

in users index in indx;


drop synonym cot;
create synonym cot for tsec_cot_company_attrib;

-- ===================================================================
--
-- Table tsec_cap_ctg_access_prv
--
-- This table stores catalog access for each node of a catalog 1:view 0:noview
-- ===================================================================

drop table tsec_cap_ctg_access_prv;
create table tsec_cap_ctg_access_prv
( 
    cap_company_id                bigint,
    cap_cap_id                    bigint not null,
    cap_attr_group_id             bigint not null,
    cap_viewable                  char,
    constraint cap_0_uk
        unique (cap_cap_id, cap_attr_group_id)
) 

in users index in indx;


drop synonym cap;
create synonym cap for tsec_cap_ctg_access_prv;

-- ===================================================================
--
-- Table tsec_cma_cap_role_object_map
--
-- This table stores the objects/role combinations for which ctg access privileges
-- are enabled.
-- ===================================================================

drop table tsec_cma_cap_role_object_map;
create table tsec_cma_cap_role_object_map
( 
    cma_company_id                bigint,
    cma_role_id                   bigint not null,
    cma_object_id                 bigint not null,
    cma_object_type               varchar(100) not null,
    cma_cap_id                    bigint not null,
    constraint cma_0_pk
        primary key (cma_role_id, cma_object_id, cma_object_type),
    constraint cma_1_uk
        unique (cma_cap_id)
) 

in users index in indx;


drop synonym cma;
create synonym cma for tsec_cma_cap_role_object_map;

drop sequence qsec_cma_cap_id restrict;
create sequence qsec_cma_cap_id start with 1 increment by 200 nocache;

-- ===================================================================
--
-- Table tsec_cvd_ctg_view_detail
--
-- This table stores the details of a catalog view for each attribute group of a catalog 1:view 0:noview
-- ===================================================================

drop table tsec_cvd_ctg_view_detail;
create table tsec_cvd_ctg_view_detail
( 
    cvd_company_id                bigint,
    cvd_view_id                   bigint,
    cvd_attr_group_id             bigint,
    cvd_sub_view_type             varchar(100),
    cvd_sub_view_id               bigint,
    cvd_viewable                  char,
    cvd_order                     bigint
) 

in users index in indx;


drop synonym cvd;
create synonym cvd for tsec_cvd_ctg_view_detail;

-- ===================================================================
--
-- Table tsec_cvi_ctg_view
--
-- This table stores the list of catalog views
-- ===================================================================

drop table tsec_cvi_ctg_view;
create table tsec_cvi_ctg_view
( 
    cvi_company_id                bigint not null,
    cvi_object_id                 bigint not null,
    cvi_object_type               varchar(100) not null,
    cvi_view_name                 varchar(256) not null,
    cvi_view_id                   bigint,
    constraint cvi_0_uk
        unique (cvi_company_id, cvi_object_id, cvi_object_type, cvi_view_name)
) 

in users index in indx;


drop synonym cvi;
create synonym cvi for tsec_cvi_ctg_view;

drop sequence qsec_cvi_view_id restrict;
create sequence qsec_cvi_view_id start with 1 increment by 200 nocache;

-- ===================================================================
--
-- Table tsec_cdu_default_view_user
--
-- This table stores the default views for each user
-- ===================================================================

drop table tsec_cdu_default_view_user;
create table tsec_cdu_default_view_user
( 
    cdu_company_id                bigint not null,
    cdu_user_id                   bigint not null,
    cdu_object_id                 bigint not null,
    cdu_object_type               varchar(900) not null,
    cdu_view_id                   bigint,
    constraint cdu_0_uk
        unique (cdu_company_id, cdu_user_id, cdu_object_id, cdu_object_type)
) 

in users index in indx;


drop synonym cdu;
create synonym cdu for tsec_cdu_default_view_user;

-- ===================================================================
--
-- Table tsec_obg_object_group
--

-- ===================================================================

drop table tsec_obg_object_group;
create table tsec_obg_object_group
( 
    obg_company_id                bigint,
    obg_id                        bigint not null,
    obg_name                      varchar(100),
    obg_description               varchar(200),
    constraint obg_0_pk
        primary key (obg_id)
) 

in users index in indx;


drop synonym obg;
create synonym obg for tsec_obg_object_group;

drop sequence qsec_obg_id restrict;
create sequence qsec_obg_id start with 1 increment by 200 nocache;

-- ===================================================================
--
-- Table tsec_ogm_object_group_map
--

-- ===================================================================

drop table tsec_ogm_object_group_map;
create table tsec_ogm_object_group_map
( 
    ogm_company_id                bigint,
    ogm_object_group_id           bigint,
    ogm_object_type_id            bigint
) 

in users index in indx;


drop synonym ogm;
create synonym ogm for tsec_ogm_object_group_map;

-- ===================================================================
--
-- Table tsec_orm_object_group_role_map
--
-- 'access' is a bitmap of all the object actions in the system. 'access_order' determines the order of the
-- 'access' sequence for a whole list of actions for a role. This helps to have an unlimited
-- size for the actions bitmap 'access' using 'access_order' (similar to a multi-dimensional array).
-- However, in the object_group_role_map table, 'access' only has the bits corresponding to the
-- actions of the current object_group active!
-- ===================================================================

drop table tsec_orm_object_group_role_map;
create table tsec_orm_object_group_role_map
( 
    orm_company_id                bigint,
    orm_object_group_id           bigint,
    orm_role_id                   bigint,
    orm_access                    varchar(4000),
    orm_access_order              bigint
) 

in users index in indx;


drop synonym orm;
create synonym orm for tsec_orm_object_group_role_map;

-- ===================================================================
--
-- Table tsec_rsm_role_to_script_map
--
-- Tables that maps role id to script names that the particular role has access to.
-- ===================================================================

drop table tsec_rsm_role_to_script_map;
create table tsec_rsm_role_to_script_map
( 
    rsm_company_id                bigint,
    rsm_role_id                   bigint,
    rsm_script_name               varchar(500)
) 

in users index in indx;


drop synonym rsm;
create synonym rsm for tsec_rsm_role_to_script_map;

drop sequence qsec_cmp_mkt_company_id restrict;
create sequence qsec_cmp_mkt_company_id start with 101 increment by 1 nocache;
drop sequence qsec_cmp_sup_company_id restrict;
create sequence qsec_cmp_sup_company_id start with 1 increment by 1 nocache;

commit;

update command options using c on;

terminate;