/*==============================================================*/
/* Table: GP_CYCLE                                              */
/*==============================================================*/
create table GP_CYCLE (
CYCLE_DATE_TIME      TIMESTAMP            not null,
CELL_ID              INT4                 not null,
PART_TYPE_ID         INT4                 not null,
CYCLE_MODE_CODE_ID   INT4                 not null,
ERROR_COUNT          INT4                 null,
QUALITY_CODE_ID      INT4                 null,
ALARM_COUNT          INT4                 null,
CYCLE_ELAPSED_TIME   FLOAT8               null,
GOOD_COUNT           INT4                 null,
TRENDING_COUNT       INT4                 null,
OUT_OF_SPEC_COUNT    INT4                 null,
REJECT_COUNT         INT4                 null,
SDA_RESULT_CODE_ID   INT4                 null,
CRIT_ERROR_COUNT     INT4                 null,
CRIT_ALARM_COUNT     INT4                 null,
CRIT_GOOD_COUNT      INT4                 null,
CRIT_TRENDING_COUNT  INT4                 null,
CRIT_OUT_OF_SPEC_COUNT INT4                 null,
CRIT_REJECT_COUNT    INT4                 null,
CRIT_QUALITY_CODE_ID INT4                 null,
constraint PK_GP_CYCLE primary key (CELL_ID, PART_TYPE_ID, CYCLE_DATE_TIME)
);

/*==============================================================*/
/* Table: GP_CYCLE_ALARM                                        */
/*==============================================================*/
create table GP_CYCLE_ALARM (
CELL_ID              INT4                 not null,
PART_TYPE_ID         INT4                 not null,
CYCLE_DATE_TIME      TIMESTAMP            not null,
ALARM_ID             INT4                 not null,
CH_ID                INT4                 not null,
LIMIT_TYPE_CODE_ID   INT4                 not null,
constraint PK_GP_CYCLE_ALARM primary key (CELL_ID, PART_TYPE_ID, CYCLE_DATE_TIME, ALARM_ID, CH_ID, LIMIT_TYPE_CODE_ID)
);

/*==============================================================*/
/* Table: GP_CYCLE_PART_ID                                      */
/*==============================================================*/
create table GP_CYCLE_PART_ID (
CYCLE_DATE_TIME      TIMESTAMP            not null,
CELL_ID              INT4                 not null,
PART_TYPE_ID         INT4                 not null,
PART_ID_NAME         VARCHAR(100)         not null,
PART_ID_VALUE        VARCHAR(255)         null,
constraint PK_GP_CYCLE_PART_ID primary key (CELL_ID, PART_TYPE_ID, CYCLE_DATE_TIME, PART_ID_NAME)
);

/*==============================================================*/
/* Table: GP_CYCLE_PROCESS_ID                                   */
/*==============================================================*/
create table GP_CYCLE_PROCESS_ID (
CYCLE_DATE_TIME      TIMESTAMP            not null,
CELL_ID              INT4                 not null,
PART_TYPE_ID         INT4                 not null,
PROCESS_ID_NAME      VARCHAR(100)         not null,
PROCESS_ID_VALUE     VARCHAR(255)         not null,
constraint PK_GP_CYCLE_PROCESS_ID primary key (CELL_ID, PART_TYPE_ID, CYCLE_DATE_TIME, PROCESS_ID_NAME)
);

/*==============================================================*/
/* Table: GP_CYCLE_VF_SEC_POINTS                                */
/*==============================================================*/
create table GP_CYCLE_VF_SEC_POINTS (
CYCLE_DATE_TIME      TIMESTAMP            not null,
CELL_ID              INT4                 not null,
PART_TYPE_ID         INT4                 not null,
VISUAL_FIXTURE_ID    INT4                 not null,
INSP_POINT_ID        INT4                 not null,
constraint PK_GP_CYCLE_VF_SEC_POINTS primary key (CELL_ID, PART_TYPE_ID, CYCLE_DATE_TIME, VISUAL_FIXTURE_ID, INSP_POINT_ID)
);

/*==============================================================*/
/* Table: GP_CYCLE_VISUAL_FIXTURE                               */
/*==============================================================*/
create table GP_CYCLE_VISUAL_FIXTURE (
CYCLE_DATE_TIME      TIMESTAMP            not null,
CELL_ID              INT4                 not null,
PART_TYPE_ID         INT4                 not null,
VISUAL_FIXTURE_ID    INT4                 not null,
ROBOT_ID             INT4                 not null,
TRANSFORM_TYPE       INT4                 not null,
VISUAL_FIXTURE_TRANSFORM BYTEA                null,
BOUNDARY_BOX_TRANSFORM BYTEA                null,
POSITION_ID          INT4                 null,
BACKUP_SCHEME        INT4                 null,
VF_QUALITY_CODE_ID   INT4                 not null,
SECONDARY_POINTS_USED SMALLINT             not null,
CYCLE_MODE_CODE_ID   INT4                 not null,
constraint PK_GP_CYCLE_VISUAL_FIXTURE primary key (CELL_ID, PART_TYPE_ID, CYCLE_DATE_TIME, VISUAL_FIXTURE_ID, ROBOT_ID, TRANSFORM_TYPE)
);

/*==============================================================*/
/* Table: GP_MEASUREMENT                                        */
/*==============================================================*/
create table GP_MEASUREMENT (
CYCLE_DATE_TIME      TIMESTAMP            not null,
CH_ID                INT4                 not null,
CELL_ID              INT4                 not null,
MEASUREMENT          FLOAT8               null,
QUALITY_CODE_ID      INT4                 null,
ERROR_CODE_ID        INT4                 null,
LIMIT_ALARM_MASK     INT4                 null,
VISUAL_FIXTURE_ID    INT4                 not null,
constraint PK_GP_MEASUREMENT primary key (CYCLE_DATE_TIME, CH_ID, VISUAL_FIXTURE_ID)
);




