-- begin TMS_HEART_BEAT
create table TMS_HEART_BEAT (
    ID uuid,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    VERSION integer not null,
    --
    TERMINAL_ID uuid not null,
    BATTERY_TEMP double precision not null,
    BATTERY_PERCENTAGE integer not null,
    LATITUDE double precision,
    LONGITUDE double precision,
    CELL_INFOS varchar(500),
    CELL_NAME varchar(50),
    CELL_TYPE varchar(10),
    CELL_STRENGTH integer,
    --
    primary key (ID)
)^
-- end TMS_HEART_BEAT
-- begin TMS_DELETE_TASK_LOG
create table TMS_DELETE_TASK_LOG (
    ID uuid,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    VERSION integer not null,
    --
    TASK_ID uuid not null,
    APPLICATION_SIMPLE_ID uuid not null,
    TERMINAL_ID uuid not null,
    ACTIVITY integer not null,
    OLD_ACTIVITY integer,
    LAST_BROADCAST_TS timestamp,
    MESSAGE varchar(255),
    --
    primary key (ID)
)^
-- end TMS_DELETE_TASK_LOG
-- begin TMS_CONTACT_PERSON
create table TMS_CONTACT_PERSON (
    ID uuid,
    VERSION integer not null,
    --
    NAME varchar(100) not null,
    PHONE varchar(100),
    MOBILE varchar(100) not null,
    EMAIL varchar(255) not null,
    MERCHANT_ID uuid,
    --
    primary key (ID)
)^
-- end TMS_CONTACT_PERSON
-- begin TMS_APPLICATION_SIMPLE
create table TMS_APPLICATION_SIMPLE (
    ID uuid,
    --
    APP_NAME varchar(255) not null,
    PACKAGE_NAME varchar(255) not null,
    APP_VERSION varchar(50) not null,
    DIAGNOSTIC_INFO_ID uuid,
    --
    primary key (ID)
)^
-- end TMS_APPLICATION_SIMPLE
-- begin TMS_DOWNLOAD_TASK_LOG
create table TMS_DOWNLOAD_TASK_LOG (
    ID uuid,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    VERSION integer not null,
    --
    TASK_ID uuid not null,
    APPLICATION_ID uuid not null,
    TERMINAL_ID uuid not null,
    ACTIVITY integer not null,
    OLD_ACTIVITY integer,
    LAST_BROADCAST_TS timestamp,
    MESSAGE varchar(255),
    --
    primary key (ID)
)^
-- end TMS_DOWNLOAD_TASK_LOG
-- begin TMS_DIAGNOSTIC_INFO
create table TMS_DIAGNOSTIC_INFO (
    ID uuid,
    TERMINAL_ID uuid not null,
    BATTERY_TEMP double precision not null,
    BATTERY_PERCENTAGE integer not null,
    LATITUDE double precision,
    LONGITUDE double precision,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    VERSION integer not null,
    CELL_INFOS varchar(500),
    CELL_NAME varchar(50),
    CELL_TYPE varchar(10),
    CELL_STRENGTH integer,
    --
    MEID varchar(20),
    INSTALLED_APPS_STRING text,
    TOTAL_MEMORY bigint,
    AVAILABLE_MEMORY bigint,
    TOTAL_FLASH_MEMORY bigint,
    AVAILABLE_FLASH_MEMORY bigint,
    TOTAL_MOBILE_DATA bigint,
    SWITCHING_TIMES integer,
    CURRENT_BOOT_TIME integer,
    TOTAL_BOOT_TIME integer,
    TOTAL_LENGTH_PRINTED double precision,
    SWIPING_CARD_TIMES integer,
    DIP_INSERTING_TIMES integer,
    NFC_CARD_READING_TIMES integer,
    FRONT_CAMERA_OPEN_TIMES integer,
    REAR_CAMERA_OPEN_TIMES integer,
    SAM_AVAILABLE boolean,
    CHARGE_TIMES integer,
    --
    primary key (ID)
)^
-- end TMS_DIAGNOSTIC_INFO
-- begin TMS_CITY
create table TMS_CITY (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    --
    STATES_ID uuid not null,
    NAME varchar(50) not null,
    --
    primary key (ID)
)^
-- end TMS_CITY
-- begin TMS_COUNTRY
create table TMS_COUNTRY (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    --
    CODE varchar(2) not null,
    NAME varchar(50) not null,
    --
    primary key (ID)
)^
-- end TMS_COUNTRY
-- begin TMS_TERMINAL_LINK
create table TMS_TERMINAL_LINK (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    --
    TERMINAL_ID uuid not null,
    TERMINAL_EXT_ID uuid not null,
    --
    primary key (ID)
)^
-- end TMS_TERMINAL_LINK
-- begin TMS_TERMINAL_GROUP
create table TMS_TERMINAL_GROUP (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    --
    NAME varchar(100) not null,
    DESCRIPTION varchar(255),
    --
    primary key (ID)
)^
-- end TMS_TERMINAL_GROUP
-- begin TMS_STATES
create table TMS_STATES (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    --
    COUNTRY_ID uuid not null,
    NAME varchar(50) not null,
    --
    primary key (ID)
)^
-- end TMS_STATES
-- begin TMS_DEVICE_MODEL
create table TMS_DEVICE_MODEL (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    --
    MODEL varchar(50) not null,
    MODEL_INFORMATION text,
    VENDOR_NAME varchar(100) not null,
    VENDOR_COUNTRY varchar(50) not null,
    --
    primary key (ID)
)^
-- end TMS_DEVICE_MODEL
-- begin TMS_MERCHANT_TYPE
create table TMS_MERCHANT_TYPE (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    --
    NAME varchar(100) not null,
    DESCRIPTION varchar(255),
    --
    primary key (ID)
)^
-- end TMS_MERCHANT_TYPE
-- begin TMS_DISTRICT
create table TMS_DISTRICT (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    --
    CITY_ID uuid not null,
    NAME varchar(50) not null,
    --
    primary key (ID)
)^
-- end TMS_DISTRICT
-- begin TMS_APPLICATION
create table TMS_APPLICATION (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    TENANT_ID varchar(255),
    --
    PACKAGE_NAME varchar(255) not null,
    COMPANY_NAME varchar(100) not null,
    NAME varchar(100) not null,
    DESCRIPTION varchar(255),
    APP_VERSION varchar(50) not null,
    ICON_ID uuid,
    APK_ID uuid not null,
    UNINSTALLABLE boolean,
    DOWNLOAD_URL varchar(500),
    CHECKSUM varchar(32),
    --
    primary key (ID)
)^
-- end TMS_APPLICATION
-- begin TMS_MERCHANT
create table TMS_MERCHANT (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    TENANT_ID varchar(255),
    --
    NAME varchar(100) not null,
    TYPE_ID uuid not null,
    COMPANY_NAME varchar(100) not null,
    DISTRICT_ID uuid not null,
    ADDRESS varchar(255) not null,
    ZIPCODE varchar(5) not null,
    --
    primary key (ID)
)^
-- end TMS_MERCHANT
-- begin TMS_DEVICE_PROFILE
create table TMS_DEVICE_PROFILE (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    TENANT_ID varchar(255),
    --
    NAME varchar(50) not null,
    HEARTBEAT_INTERVAL integer not null,
    DIAGNOSTIC_INTERVAL integer not null,
    MASK_HOME_BUTTON boolean not null,
    MASK_STATUS_BAR boolean not null,
    SCHEDULE_REBOOT boolean not null,
    SCHEDULE_REBOOT_TIME time,
    RELOCATION_ALERT boolean,
    MOVING_THRESHOLD integer,
    ADMIN_PASSWORD varchar(8),
    IS_DEFAULT boolean,
    FRONT_APP varchar(255),
    HOST_REPORT boolean,
    HOST_REPORT_TIMEOUT integer,
    HOST_REPORT_URL varchar(255),
    HOST_REPORT_API_KEY varchar(64),
    HOST_LOGGING boolean,
    HOST_LOGGING_TIMEOUT integer,
    HOST_LOGGING_URL varchar(255),
    HOST_LOGGING_API_KEY varchar(64),
    HOST_LOGGING_INTERVAL integer,
    --
    primary key (ID)
)^
-- end TMS_DEVICE_PROFILE
-- begin TMS_DELETE_TASK
create table TMS_DELETE_TASK (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    TENANT_ID varchar(255),
    --
    NAME varchar(50) not null,
    STATUS integer not null,
    DELETE_TIME timestamp,
    --
    primary key (ID)
)^
-- end TMS_DELETE_TASK
-- begin TMS_DOWNLOAD_TASK
create table TMS_DOWNLOAD_TASK (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    TENANT_ID varchar(255),
    --
    NAME varchar(50) not null,
    STATUS integer not null,
    DOWNLOAD_TIME_TYPE integer not null,
    DOWNLOAD_TIME timestamp,
    INSTALLATION_TIME_TYPE integer not null,
    INSTALLATION_TIME timestamp,
    INSTALLATION_NOTIFICATION integer not null,
    --
    primary key (ID)
)^
-- end TMS_DOWNLOAD_TASK
-- begin TMS_TERMINAL
create table TMS_TERMINAL (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    TENANT_ID varchar(255),
    --
    SN varchar(30) not null,
    IMEI varchar(25) not null,
    MODEL_ID uuid not null,
    MERCHANT_ID uuid not null,
    PROFILE_ID uuid,
    IMPORT_DEFAULT boolean,
    HEARTBEAT_STATUS integer,
    LAST_HEARTBEAT_TIME timestamp,
    LAST_HEARTBEAT_ID uuid,
    LAST_INIT_TIME timestamp,
    LAST_INIT_AID_TIME timestamp,
    LAST_INIT_CAPK_TIME timestamp,
    LAST_INIT_CONTACTLESS_AID_TIME timestamp,
    LAST_INIT_CARDS_TIME timestamp,
    LAST_INIT_TERMINAL_TIME timestamp,
    LATITUDE double precision,
    LONGITUDE double precision,
    LAST_DIAGNOSTIC_TIME timestamp,
    LAST_DIAGNOSTIC_ID uuid,
    APP_VERSION varchar(50),
    LAUNCHER_VERSION varchar(50),
    VFS_VERSION varchar(50),
    VFSS_VERSION varchar(50),
    CELL_NAME varchar(255),
    --
    primary key (ID)
)^
-- end TMS_TERMINAL
-- begin TMS_DOWNLOAD_TASK_TERMINAL_LINK
create table TMS_DOWNLOAD_TASK_TERMINAL_LINK (
    TERMINAL_ID uuid,
    DOWNLOAD_TASK_ID uuid,
    primary key (TERMINAL_ID, DOWNLOAD_TASK_ID)
)^
-- end TMS_DOWNLOAD_TASK_TERMINAL_LINK
-- begin TMS_DOWNLOAD_TASK_APPLICATION_LINK
create table TMS_DOWNLOAD_TASK_APPLICATION_LINK (
    DOWNLOAD_TASK_ID uuid,
    APPLICATION_ID uuid,
    primary key (DOWNLOAD_TASK_ID, APPLICATION_ID)
)^
-- end TMS_DOWNLOAD_TASK_APPLICATION_LINK
-- begin TMS_DOWNLOAD_TASK_TERMINAL_GROUP_LINK
create table TMS_DOWNLOAD_TASK_TERMINAL_GROUP_LINK (
    DOWNLOAD_TASK_ID uuid,
    GROUP_ID uuid,
    primary key (DOWNLOAD_TASK_ID, GROUP_ID)
)^
-- end TMS_DOWNLOAD_TASK_TERMINAL_GROUP_LINK
-- begin TMS_TERMINAL_GROUP_LINK
create table TMS_TERMINAL_GROUP_LINK (
    TERMINAL_ID uuid,
    TERMINAL_GROUP_ID uuid,
    primary key (TERMINAL_ID, TERMINAL_GROUP_ID)
)^
-- end TMS_TERMINAL_GROUP_LINK
-- begin TMS_DELETE_TASK_APPLICATION_LINK
create table TMS_DELETE_TASK_APPLICATION_LINK (
    APPLICATION_ID uuid,
    DELETE_TASK_ID uuid,
    primary key (APPLICATION_ID, DELETE_TASK_ID)
)^
-- end TMS_DELETE_TASK_APPLICATION_LINK
-- begin TMS_DELETE_TASK_APPLICATION_SIMPLE_LINK
create table TMS_DELETE_TASK_APPLICATION_SIMPLE_LINK (
    DELETE_TASK_ID uuid,
    APPLICATION_SIMPLE_ID uuid,
    primary key (DELETE_TASK_ID, APPLICATION_SIMPLE_ID)
)^
-- end TMS_DELETE_TASK_APPLICATION_SIMPLE_LINK
-- begin TMS_DELETE_TASK_TERMINAL_GROUP_LINK
create table TMS_DELETE_TASK_TERMINAL_GROUP_LINK (
    DELETE_TASK_ID uuid,
    GROUP_ID uuid,
    primary key (DELETE_TASK_ID, GROUP_ID)
)^
-- end TMS_DELETE_TASK_TERMINAL_GROUP_LINK
-- begin TMS_DEVICE_PROFILE_ACQUIRER_LINK
create table TMS_DEVICE_PROFILE_ACQUIRER_LINK (
    DEVICE_PROFILE_ID uuid,
    ACQUIRER_ID uuid,
    primary key (DEVICE_PROFILE_ID, ACQUIRER_ID)
)^
-- end TMS_DEVICE_PROFILE_ACQUIRER_LINK
-- begin TMS_TERMINAL_LAST_UPDATE
create table TMS_TERMINAL_LAST_UPDATE (
    ID uuid,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    --
    SN varchar(255),
    HAS_UPDATE boolean,
    FORCE_UPDATE boolean,
    LAST_INIT_TIME timestamp,
    --
    primary key (ID)
)^
-- end TMS_TERMINAL_LAST_UPDATE
-- begin TMS_TERMINAL_LAST_STEP_UPDATE
create table TMS_TERMINAL_LAST_STEP_UPDATE (
    ID uuid,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    --
    SN varchar(255),
    STEP_NAME varchar(255),
    LAST_INIT_TIME timestamp,
    --
    primary key (ID)
)^
-- end TMS_TERMINAL_LAST_STEP_UPDATE
-- begin TMS_TERMINAL_ACK_UPDATE
create table TMS_TERMINAL_ACK_UPDATE (
    ID uuid,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    --
    SN varchar(255),
    LAST_INIT_TIME timestamp,
    SYNC_START_TIME timestamp,
    SYNC_END_TIME timestamp,
    RETRY_COUNT integer,
    --
    primary key (ID)
)^
-- end TMS_TERMINAL_ACK_UPDATE
-- begin TMS_RESPONSE_CODE
create table TMS_RESPONSE_CODE (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    UPDATE_TS timestamp,
    UPDATED_BY varchar(50),
    DELETE_TS timestamp,
    DELETED_BY varchar(50),
    --
    TYPE varchar(50) not null,
    CODE varchar(2) not null,
    DESCRIPTION varchar(255) not null,
    --
    primary key (ID)
)^
-- end TMS_RESPONSE_CODE
-- begin TMS_DEVICE_PROFILE_APP
create table TMS_DEVICE_PROFILE_APP (
    ID uuid,
    --
    PACKAGE_NAME varchar(255) not null,
    PROFILE_ID uuid not null,
    --
    primary key (ID)
)^
-- end TMS_DEVICE_PROFILE_APP
-- begin TMS_TERMINAL_PROFILING
create table TMS_TERMINAL_PROFILING (
    ID uuid,
    VERSION integer not null,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    --
    FILE uuid,
    --
    primary key (ID)
)^
-- end TMS_TERMINAL_PROFILING
-- begin TMS_TERMINAL_PROFILING_ITEMS
create table TMS_TERMINAL_PROFILING_ITEMS (
    ID uuid,
    CREATE_TS timestamp,
    CREATED_BY varchar(50),
    --
    PROFILING_ID uuid,
    sn varchar(30) not null,
    imei varchar(25) not null,
    model_name varchar(50) not null,
    merchant_name varchar(100) not null,
    profile_name varchar(50) not null,
    group_names varchar(255) not null,
    terminal_id_template varchar(8) not null,
    terminal_id varchar(8) not null,
    merchant_id varchar(15) not null,
    merchant_name1 varchar(30) not null,
    merchant_name2 varchar(30),
    merchant_name3 varchar(30),
    merchant_name4 varchar(30),
    merchant_name5 varchar(30),
    --
    primary key (ID)
)^
-- end TMS_TERMINAL_PROFILING_ITEMS
-- begin TMS_TERMINAL_GROUP_IMPORT_STAGE
create table TMS_TERMINAL_GROUP_IMPORT_STAGE (
    IMPORT_ID uuid not null,
    ROW_NO integer not null,
    CREATE_TS timestamp default current_timestamp,
    --
    TID varchar(255),
    SN varchar(255),
    TID_NORM varchar(255),
    SN_NORM varchar(255),
    SN_LOWER_NORM varchar(255),
    --
    primary key (IMPORT_ID, ROW_NO)
)^
-- end TMS_TERMINAL_GROUP_IMPORT_STAGE
