// ---------------------------------------------------------------------
// ------------------------------ PFC MESSAGES -------------------------
// MESSAGES
create table messages
(
  msgid                         char    ( 40)        not null,
  msgtitle                      char    (255)        not null,
  msgtext                       char    (255)        not null,
  msgicon                       char    ( 12)        not null,
  msgbutton                     char    ( 17)        not null,
  msgdefaultbutton              integer              not null,
  msgseverity                   integer              not null,
  msgprint                      char    (  1)        not null,
  msguserinput                  char    (  1)        not null,
  constraint PK_MESSAGES primary key clustered 
  ( msgid )
)
;



// ---------------------------------------------------------------------
// ------------------------------ Classes ------------------------------

// ---------------------------------------------------------------------
// ------------------------------ AHLP ---------------------------------
// AHLP -> APL
create table application_helps
(
  ahlp_window                   varchar ( 60)        not null,
  ahlp_language                 integer              not null,
  ahlp_help                     text                     null,
  constraint PK_AHLP primary key clustered 
  ( ahlp_window, ahlp_language )
)
;

// ---------------------------------------------------------------------
// ------------------------------ APL ----------------------------------
// APL
create table application_languages
(
  apl_id                        integer              not null,
  apl_language_name             varchar ( 60)        not null,
  apl_font_name                 varchar ( 60)            null,
  apl_right_to_left             smallint                 null,
  apl_font_charset              smallint                 null,
  apl_font_size                 smallint                 null,
  apl_keyboard_layout           char    (  8)            null,
  constraint PK_APL primary key clustered 
  ( apl_id )
)
;


// ---------------------------------------------------------------------
// ------------------------------ APM ----------------------------------
// APM -> APL
create table application_messages
(
  apm_code                      varchar ( 30)        not null,
  apm_language                  integer              not null,
  apm_message                   varchar (255)        not null,
  constraint PK_APM primary key clustered 
  ( apm_code, apm_language )
)
;

// ---------------------------------------------------------------------
// ------------------------------ CAC ----------------------------------
// CAC -> CST, CEV
create table class_actions
(
  cac_class                     integer              not null,
  cac_status                    integer              not null,
  cac_event                     integer              not null,
  cac_action                    text                     null,
  cac_comments                  varchar (255)            null,
  constraint PK_CAC primary key clustered 
  ( cac_class, cac_status, cac_event )
)
;

// ---------------------------------------------------------------------
// ------------------------------ CEV ----------------------------------
// CEV - CLS
create table class_events
(
  cev_class                     integer              not null,
  cev_id                        integer              not null,
  cev_prefix                    char    (  8)        not null,
  cev_name                      varchar ( 60)        not null,
  cev_system                    smallint                 null,
  cev_comments                  varchar (255)            null,
  constraint UC_CEV unique 
  ( cev_class, cev_prefix ),
  constraint PK_CEV primary key clustered 
  ( cev_class, cev_id )
)
;

// ---------------------------------------------------------------------
// ------------------------------ CLP ----------------------------------
// CLP -> CLS ( class ), CLS ( property ), CLS ( parent )
create table class_properties
(
  clp_id                        integer              not null,
  clp_class                     integer              not null,
  clp_property                  integer              not null,
  clp_name                      varchar ( 60)            null,
  clp_parent                    integer                  null,
  clp_data                      text                     null,
  constraint UC_CLP unique 
  ( clp_class, clp_property, clp_name ),
  constraint PK_CLP primary key clustered 
  ( clp_id )
)
;

// ---------------------------------------------------------------------
// ------------------------------ CST ----------------------------------
// CST -> CLS
create table class_statuses
(
  cst_class                     integer              not null,
  cst_id                        integer              not null,
  cst_prefix                    char    (  8)        not null,
  cst_name                      varchar ( 60)        not null,
  cst_system                    smallint                 null,
  cst_comments                  varchar (255)            null,
  cst_order                     smallint                 null,
  cst_protection_level          smallint                 null,
  constraint UC_CST unique 
  ( cst_class, cst_prefix ),
  constraint PK_CST primary key clustered 
  ( cst_class, cst_id )
)
;

// ---------------------------------------------------------------------
// ------------------------------ CLS ----------------------------------
// CLS
create table classes
(
  cls_id                        integer              not null,
  cls_prefix                    char    (  8)        not null,
  cls_name                      varchar ( 60)        not null,
  cls_data                      text                     null,
  cls_comments                  text                     null,
  constraint UC_CLS_P unique 
  ( cls_prefix ),
  constraint UC_CLS_N unique 
  ( cls_name ),
  constraint PK_CLS primary key clustered 
  ( cls_id )
)
;

// ---------------------------------------------------------------------
// ------------------------------ INH ----------------------------------
// INH-> CLS, CLS
create table inheritance
(
  inh_parent                    integer              not null,
  inh_class                     integer              not null,
  constraint PK_INH primary key clustered 
  ( inh_parent, inh_class )
)
;

// ---------------------------------------------------------------------
// ------------------------------ OIN ----------------------------------
// OIN -> CLS
create table object_indexes
(
  oin_prefix                    char    (  8)        not null,
  oin_restkey                   varchar ( 32)        not null,
  oin_numind                    integer                  null,
  oin_refresh                   varchar (255)            null,
  constraint PK_OIN primary key clustered 
  ( oin_prefix, oin_restkey )
)
;

// ---------------------------------------------------------------------
// ------------------------------ OST ----------------------------------
// OST -> CLS
create table object_statuses
(
  ost_class_prefix              char    (  8)        not null,
  ost_object_key                varchar ( 32)        not null,
  ost_status                    integer                  null,
  ost_date                      datetime                 null,
  constraint PK_OST primary key clustered 
  ( ost_class_prefix, ost_object_key )
)
;

// ---------------------------------------------------------------------
// ------------------------------ PRF ----------------------------------
// PRF -> USR
create table profiles
(
  prf_user                      integer              not null,
  prf_datawindow                varchar ( 60)        not null,
  prf_profile                   varchar ( 60)        not null,
  prf_data                      text                     null,
  constraint PK_PRF primary key clustered 
    ( prf_user, prf_datawindow, prf_profile )
)
;

// ---------------------------------------------------------------------
// ------------------------------ UAC ----------------------------------
// UAC -> UAC, CST
create table user_actions
(
  uac_id                        integer              not null,
  uac_parent                    integer                  null,
  uac_class                     integer              not null,
  uac_status                    integer              not null,
  uac_call_data                 text                     null,
  uac_text                      varchar ( 60)            null,
  uac_text_order                smallint                 null,
  uac_picture                   varchar ( 60)            null,
  uac_comments                  text                     null,
  constraint PK_UAC primary key clustered 
    ( uac_id, uac_class, uac_status )
)
;

// ---------------------------------------------------------------------
// ------------------------------ UACP ---------------------------------
// UACP -> UAC, USR
create table user_action_preferences
(
  uacp_action                   integer              not null,
  uacp_class                    integer              not null,
  uacp_status                   integer              not null,
  uacp_user                     integer              not null,
  constraint PK_UACP primary key clustered 
    ( uacp_action, uacp_class, uacp_status, uacp_user )
)
;

// ---------------------------------------------------------------------
// ------------------------------ UAP ----------------------------------
// UAP -> UAC, USR
create table user_action_permissions
(
  uap_action                    integer              not null,
  uap_class                     integer              not null,
  uap_status                    integer              not null,
  uap_user                      integer              not null,
  uap_permissions               varchar (255)            null,
  constraint PK_UAP primary key clustered
  ( uap_action, uap_class, uap_status, uap_user )
)
;

// ---------------------------------------------------------------------
// ------------------------------ UASC ---------------------------------
// UASC -> USR
// Frequency:
// 0 - one time
// 1 - minutely ( each <uasc_minute> minutes )
// 2 - hourly ( each <uasc_minute> of hour )
// 3 - daily ( of week )
// 4 - daily ( of month )
// 5 - weekly
// 6 - monthly
// 7 - quarterly
// 8 - half-yearly
// 9 - yearly
create table user_action_schedules
(
  uasc_id                       integer              not null,
  uasc_user                     integer                  null,
  uasc_start_date               datetime                 null,
  uasc_finish_date              datetime                 null,
  uasc_frequency                smallint                 null,
  uasc_year                     smallint                 null,
  uasc_month                    smallint                 null,
  uasc_day                      smallint                 null,
  uasc_week                     smallint                 null,
  uasc_weekday                  smallint                 null,
  uasc_hour                     smallint                 null,
  uasc_minute                   smallint                 null,
  uasc_name                     varchar ( 60)            null,
  uasc_data                     varchar (255)            null,
  uasc_comments                 varchar (255)            null,
  uasc_status                   integer                  null,
  constraint PK_UASC primary key clustered 
  ( uasc_id )
)
;

// ---------------------------------------------------------------------
// ------------------------------ USS ----------------------------------
// USS -> USR
create table user_sessions
(
  uss_id                        integer              not null,
  uss_user                      integer                  null,
  uss_begintime                 datetime                 null,
  uss_endtime                   datetime                 null,
  uss_message                   varchar (255)            null,
  constraint PK_USS primary key clustered 
  ( uss_id )
)
;

// ---------------------------------------------------------------------
// ------------------------------ UGR ----------------------------------
// UGR -> USR, USR
create table user_groups
(
  ugr_group                     integer              not null,
  ugr_user                      integer              not null,
  constraint PK_UGR primary key clustered 
  ( ugr_group, ugr_user )
)
;

// ---------------------------------------------------------------------
// ------------------------------ USC ----------------------------------
// USC -> CST, CST, USR
create table user_status_changing
(
  usc_class                     integer              not null,
  usc_status                    integer              not null,
  usc_new_status                integer              not null,
  usc_user                      integer              not null,
  constraint PK_USC primary key clustered 
  ( usc_class, usc_status, usc_new_status, usc_user )
)
;

// ---------------------------------------------------------------------
// ------------------------------ USR ----------------------------------
// USR - APL, DPR, EMP
create table users
(
  usr_id                        integer              not null,
  usr_code                      varchar ( 10)            null,
  usr_password                  varchar ( 10)            null,
  usr_name                      varchar ( 60)            null,
  usr_group                     smallint                 null,
  usr_language                  integer                  null,
  usr_active                    smallint                 null,
  usr_data                      varchar (255)            null,
  usr_comments                  varchar (255)            null,
  usr_employee_id               integer                  null,
  usr_department_id             integer                  null,
  usr_worklevel                 varchar ( 20)            null,
  usr_datasource                integer                  null,
  constraint UC_USR unique 
  ( usr_code ),
  constraint PK_USR primary key clustered 
  ( usr_id )
)
;



// ---------------------------------------------------------------------
// ------------------------------ PB Library Objects -------------------

// ---------------------------------------------------------------------
// ------------------------------ DCOB ---------------------------------
// DCOB
create table documentation_objects 
(
  dcob_id                       integer              not null,
  dcob_name                     varchar ( 60)            null,
  dcob_type                     smallint                 null,
  dcob_ancestor                 varchar ( 60)            null,
  dcob_library                  varchar (128)            null,
  dcob_title                    varchar (255)            null,
  dcob_instance                 text                     null,
  dcob_shared                   text                     null,
  dcob_global                   text                     null,
  dcob_description              text                     null,
  dcob_status                   integer                  null,
  constraint PK_DCOB primary key 
  ( dcob_id ) 
)
;

// ---------------------------------------------------------------------
// ------------------------------ DCOP ---------------------------------
// DCOP -> DCOB
create table documentation_object_phrases
(
  dcop_object                   integer              not null,
  dcop_phrase                   varchar (255)        not null,
  dcop_translation              varchar (255)            null,
  constraint PK_DCOP primary key 
  ( dcop_object, dcop_phrase )
)
;

// ---------------------------------------------------------------------
// ------------------------------ DCSO ---------------------------------
// DCSO -> DCOB
create table documentation_subobjects
(
  dcso_id                       integer              not null,
  dcso_object                   integer              not null,
  dcso_name                     varchar ( 60)            null,
  dcso_type                     smallint                 null,
  dcso_access                   smallint                 null,
  dcso_return                   varchar ( 60)            null,
  dcso_signature                varchar (255)            null,
  dcso_description              text                     null,
  dcso_status                   integer                  null,
  constraint PK_DCSO primary key 
  ( dcso_id )
)
;

// ---------------------------------------------------------------------
// ------------------------------ DCPK ---------------------------------
// DCPK -> DCPK, DCOB
create table documentation_packages 
(
  dcpk_id                       integer              not null,
  dcpk_parent                   integer                  null,
  dcpk_name                     varchar ( 60)            null,
  dcpk_order                    integer                  null,
  dcpk_object                   integer                  null,
  dcpk_description              text                     null,
  dcpk_status                   integer                  null,
  dcpk_ext_file_path            varchar (128)            null,
  constraint PK_DCPK primary key 
  ( dcpk_id )
)
;
