-- begin TMS_HEART_BEAT
alter table TMS_HEART_BEAT add constraint FK_TMS_HEART_BEAT_ON_TERMINAL foreign key (TERMINAL_ID) references TMS_TERMINAL(ID)^
create index IDX_TMS_HEART_BEAT_ON_TERMINAL on TMS_HEART_BEAT (TERMINAL_ID)^
-- end TMS_HEART_BEAT
-- begin TMS_DELETE_TASK_LOG
alter table TMS_DELETE_TASK_LOG add constraint FK_TMS_DELETE_TASK_LOG_ON_TASK foreign key (TASK_ID) references TMS_DELETE_TASK(ID)^
alter table TMS_DELETE_TASK_LOG add constraint FK_TMS_DELETE_TASK_LOG_ON_APPLICATION_SIMPLE foreign key (APPLICATION_SIMPLE_ID) references TMS_APPLICATION_SIMPLE(ID) on delete CASCADE^
alter table TMS_DELETE_TASK_LOG add constraint FK_TMS_DELETE_TASK_LOG_ON_TERMINAL foreign key (TERMINAL_ID) references TMS_TERMINAL(ID)^
create index IDX_TMS_DELETE_TASK_LOG_ON_TASK on TMS_DELETE_TASK_LOG (TASK_ID)^
create index IDX_TMS_DELETE_TASK_LOG_ON_APPLICATION_SIMPLE on TMS_DELETE_TASK_LOG (APPLICATION_SIMPLE_ID)^
create index IDX_TMS_DELETE_TASK_LOG_ON_TERMINAL on TMS_DELETE_TASK_LOG (TERMINAL_ID)^
-- end TMS_DELETE_TASK_LOG
-- begin TMS_CONTACT_PERSON
alter table TMS_CONTACT_PERSON add constraint FK_TMS_CONTACT_PERSON_ON_MERCHANT foreign key (MERCHANT_ID) references TMS_MERCHANT(ID)^
create index IDX_TMS_CONTACT_PERSON_ON_MERCHANT on TMS_CONTACT_PERSON (MERCHANT_ID)^
-- end TMS_CONTACT_PERSON
-- begin TMS_APPLICATION_SIMPLE
alter table TMS_APPLICATION_SIMPLE add constraint FK_TMS_APPLICATION_SIMPLE_ON_DIAGNOSTIC_INFO foreign key (DIAGNOSTIC_INFO_ID) references TMS_DIAGNOSTIC_INFO(ID)^
create index IDX_TMS_APPLICATION_SIMPLE_ON_DIAGNOSTIC_INFO on TMS_APPLICATION_SIMPLE (DIAGNOSTIC_INFO_ID)^
-- end TMS_APPLICATION_SIMPLE
-- begin TMS_DOWNLOAD_TASK_LOG
alter table TMS_DOWNLOAD_TASK_LOG add constraint FK_TMS_DOWNLOAD_TASK_LOG_ON_TASK foreign key (TASK_ID) references TMS_DOWNLOAD_TASK(ID)^
alter table TMS_DOWNLOAD_TASK_LOG add constraint FK_TMS_DOWNLOAD_TASK_LOG_ON_APPLICATION foreign key (APPLICATION_ID) references TMS_APPLICATION(ID)^
alter table TMS_DOWNLOAD_TASK_LOG add constraint FK_TMS_DOWNLOAD_TASK_LOG_ON_TERMINAL foreign key (TERMINAL_ID) references TMS_TERMINAL(ID)^
create index IDX_TMS_DOWNLOAD_TASK_LOG_ON_TASK on TMS_DOWNLOAD_TASK_LOG (TASK_ID)^
create index IDX_TMS_DOWNLOAD_TASK_LOG_ON_APPLICATION on TMS_DOWNLOAD_TASK_LOG (APPLICATION_ID)^
create index IDX_TMS_DOWNLOAD_TASK_LOG_ON_TERMINAL on TMS_DOWNLOAD_TASK_LOG (TERMINAL_ID)^
-- end TMS_DOWNLOAD_TASK_LOG
-- begin TMS_DIAGNOSTIC_INFO
alter table TMS_DIAGNOSTIC_INFO add constraint FK_TMS_DIAGNOSTIC_INFO_ON_TERMINAL foreign key (TERMINAL_ID) references TMS_TERMINAL(ID)^
create index IDX_TMS_DIAGNOSTIC_INFO_ON_TERMINAL on TMS_DIAGNOSTIC_INFO (TERMINAL_ID)^
-- end TMS_DIAGNOSTIC_INFO
-- begin TMS_CITY
alter table TMS_CITY add constraint FK_TMS_CITY_ON_STATES foreign key (STATES_ID) references TMS_STATES(ID)^
create index IDX_TMS_CITY_ON_STATES on TMS_CITY (STATES_ID)^
-- end TMS_CITY
-- begin TMS_COUNTRY
create unique index IDX_TMS_COUNTRY_UK_CODE on TMS_COUNTRY (CODE) where DELETE_TS is null ^
-- end TMS_COUNTRY
-- begin TMS_TERMINAL_LINK
alter table TMS_TERMINAL_LINK add constraint FK_TMS_TERMINAL_LINK_ON_TERMINAL foreign key (TERMINAL_ID) references TMS_TERMINAL(ID)^
alter table TMS_TERMINAL_LINK add constraint FK_TMS_TERMINAL_LINK_ON_TERMINAL_EXT foreign key (TERMINAL_EXT_ID) references TMSEXT_TERMINAL_EXT(ID)^
create index IDX_TMS_TERMINAL_LINK_ON_TERMINAL on TMS_TERMINAL_LINK (TERMINAL_ID)^
create index IDX_TMS_TERMINAL_LINK_ON_TERMINAL_EXT on TMS_TERMINAL_LINK (TERMINAL_EXT_ID)^
-- end TMS_TERMINAL_LINK
-- begin TMS_STATES
alter table TMS_STATES add constraint FK_TMS_STATES_ON_COUNTRY foreign key (COUNTRY_ID) references TMS_COUNTRY(ID)^
create index IDX_TMS_STATES_ON_COUNTRY on TMS_STATES (COUNTRY_ID)^
-- end TMS_STATES
-- begin TMS_DISTRICT
alter table TMS_DISTRICT add constraint FK_TMS_DISTRICT_ON_CITY foreign key (CITY_ID) references TMS_CITY(ID)^
create index IDX_TMS_DISTRICT_ON_CITY on TMS_DISTRICT (CITY_ID)^
-- end TMS_DISTRICT
-- begin TMS_APPLICATION
alter table TMS_APPLICATION add constraint FK_TMS_APPLICATION_ON_ICON foreign key (ICON_ID) references SYS_FILE(ID)^
alter table TMS_APPLICATION add constraint FK_TMS_APPLICATION_ON_APK foreign key (APK_ID) references SYS_FILE(ID)^
create unique index IDX_TMS_APPLICATION_UNQ on TMS_APPLICATION (PACKAGE_NAME, VERSION) where DELETE_TS is null ^
create index IDX_TMS_APPLICATION_ON_ICON on TMS_APPLICATION (ICON_ID)^
create index IDX_TMS_APPLICATION_ON_APK on TMS_APPLICATION (APK_ID)^
-- end TMS_APPLICATION
-- begin TMS_MERCHANT
alter table TMS_MERCHANT add constraint FK_TMS_MERCHANT_ON_TYPE foreign key (TYPE_ID) references TMS_MERCHANT_TYPE(ID)^
alter table TMS_MERCHANT add constraint FK_TMS_MERCHANT_ON_DISTRICT foreign key (DISTRICT_ID) references TMS_DISTRICT(ID)^
create index IDX_TMS_MERCHANT_ON_TYPE on TMS_MERCHANT (TYPE_ID)^
create index IDX_TMS_MERCHANT_ON_DISTRICT on TMS_MERCHANT (DISTRICT_ID)^
-- end TMS_MERCHANT
-- begin TMS_TERMINAL
alter table TMS_TERMINAL add constraint FK_TMS_TERMINAL_ON_MODEL foreign key (MODEL_ID) references TMS_DEVICE_MODEL(ID)^
alter table TMS_TERMINAL add constraint FK_TMS_TERMINAL_ON_MERCHANT foreign key (MERCHANT_ID) references TMS_MERCHANT(ID)^
alter table TMS_TERMINAL add constraint FK_TMS_TERMINAL_ON_PROFILE foreign key (PROFILE_ID) references TMS_DEVICE_PROFILE(ID)^
create unique index IDX_TMS_TERMINAL_UK_IMEI on TMS_TERMINAL (IMEI) where DELETE_TS is null ^
create unique index IDX_TMS_TERMINAL_UK_SN on TMS_TERMINAL (SN) where DELETE_TS is null ^
create unique index IDX_TMS_TERMINAL_UNQ on TMS_TERMINAL (SN, IMEI) where DELETE_TS is null ^
create index IDX_TMS_TERMINAL_ON_MODEL on TMS_TERMINAL (MODEL_ID)^
create index IDX_TMS_TERMINAL_ON_MERCHANT on TMS_TERMINAL (MERCHANT_ID)^
create index IDX_TMS_TERMINAL_ON_PROFILE on TMS_TERMINAL (PROFILE_ID)^
-- end TMS_TERMINAL
-- begin TMS_DOWNLOAD_TASK_TERMINAL_LINK
alter table TMS_DOWNLOAD_TASK_TERMINAL_LINK add constraint FK_DOWTASTER_ON_TERMINAL foreign key (TERMINAL_ID) references TMS_TERMINAL(ID)^
alter table TMS_DOWNLOAD_TASK_TERMINAL_LINK add constraint FK_DOWTASTER_ON_DOWNLOAD_TASK foreign key (DOWNLOAD_TASK_ID) references TMS_DOWNLOAD_TASK(ID)^
-- end TMS_DOWNLOAD_TASK_TERMINAL_LINK
-- begin TMS_DOWNLOAD_TASK_APPLICATION_LINK
alter table TMS_DOWNLOAD_TASK_APPLICATION_LINK add constraint FK_DOWTASAPP_ON_DOWNLOAD_TASK foreign key (DOWNLOAD_TASK_ID) references TMS_DOWNLOAD_TASK(ID)^
alter table TMS_DOWNLOAD_TASK_APPLICATION_LINK add constraint FK_DOWTASAPP_ON_APPLICATION foreign key (APPLICATION_ID) references TMS_APPLICATION(ID)^
-- end TMS_DOWNLOAD_TASK_APPLICATION_LINK
-- begin TMS_DOWNLOAD_TASK_TERMINAL_GROUP_LINK
alter table TMS_DOWNLOAD_TASK_TERMINAL_GROUP_LINK add constraint FK_DOWTASTERGRO_ON_DOWNLOAD_TASK foreign key (DOWNLOAD_TASK_ID) references TMS_DOWNLOAD_TASK(ID)^
alter table TMS_DOWNLOAD_TASK_TERMINAL_GROUP_LINK add constraint FK_DOWTASTERGRO_ON_TERMINAL_GROUP foreign key (GROUP_ID) references TMS_TERMINAL_GROUP(ID)^
-- end TMS_DOWNLOAD_TASK_TERMINAL_GROUP_LINK
-- begin TMS_TERMINAL_GROUP_LINK
alter table TMS_TERMINAL_GROUP_LINK add constraint FK_TERGRO_ON_TERMINAL foreign key (TERMINAL_ID) references TMS_TERMINAL(ID)^
alter table TMS_TERMINAL_GROUP_LINK add constraint FK_TERGRO_ON_TERMINAL_GROUP foreign key (TERMINAL_GROUP_ID) references TMS_TERMINAL_GROUP(ID)^
-- end TMS_TERMINAL_GROUP_LINK
-- begin TMS_DELETE_TASK_APPLICATION_LINK
alter table TMS_DELETE_TASK_APPLICATION_LINK add constraint FK_DELTASAPP_ON_APPLICATION_SIMPLE foreign key (APPLICATION_ID) references TMS_APPLICATION_SIMPLE(ID)^
alter table TMS_DELETE_TASK_APPLICATION_LINK add constraint FK_DELTASAPP_ON_DELETE_TASK foreign key (DELETE_TASK_ID) references TMS_DELETE_TASK(ID)^
-- end TMS_DELETE_TASK_APPLICATION_LINK
-- begin TMS_DELETE_TASK_APPLICATION_SIMPLE_LINK
alter table TMS_DELETE_TASK_APPLICATION_SIMPLE_LINK add constraint FK_DELTASAPPSIM_ON_DELETE_TASK foreign key (DELETE_TASK_ID) references TMS_DELETE_TASK(ID)^
alter table TMS_DELETE_TASK_APPLICATION_SIMPLE_LINK add constraint FK_DELTASAPPSIM_ON_APPLICATION_SIMPLE foreign key (APPLICATION_SIMPLE_ID) references TMS_APPLICATION_SIMPLE(ID)^
-- end TMS_DELETE_TASK_APPLICATION_SIMPLE_LINK
-- begin TMS_DELETE_TASK_TERMINAL_GROUP_LINK
alter table TMS_DELETE_TASK_TERMINAL_GROUP_LINK add constraint FK_DELTASTERGRO_ON_DELETE_TASK foreign key (DELETE_TASK_ID) references TMS_DELETE_TASK(ID)^
alter table TMS_DELETE_TASK_TERMINAL_GROUP_LINK add constraint FK_DELTASTERGRO_ON_TERMINAL_GROUP foreign key (GROUP_ID) references TMS_TERMINAL_GROUP(ID)^
-- end TMS_DELETE_TASK_TERMINAL_GROUP_LINK
-- begin TMS_DEVICE_PROFILE_ACQUIRER_LINK
alter table TMS_DEVICE_PROFILE_ACQUIRER_LINK add constraint FK_DEVPROACQ_ON_DEVICE_PROFILE foreign key (DEVICE_PROFILE_ID) references TMS_DEVICE_PROFILE(ID)^
alter table TMS_DEVICE_PROFILE_ACQUIRER_LINK add constraint FK_DEVPROACQ_ON_ACQUIRER foreign key (ACQUIRER_ID) references TMSEXT_ACQUIRER(ID)^
-- end TMS_DEVICE_PROFILE_ACQUIRER_LINK
-- begin TMS_DEVICE_PROFILE_APP
alter table TMS_DEVICE_PROFILE_APP add constraint FK_TMS_DEVICE_PROFILE_APP_ON_PROFILE foreign key (PROFILE_ID) references TMS_DEVICE_PROFILE(ID)^
create index IDX_TMS_DEVICE_PROFILE_APP_ON_PROFILE on TMS_DEVICE_PROFILE_APP (PROFILE_ID)^
-- end TMS_DEVICE_PROFILE_APP
-- begin TMS_TERMINAL_PROFILING
alter table TMS_TERMINAL_PROFILING add constraint FK_TMS_TERMINAL_PROFILING_ON_FILE foreign key (FILE) references SYS_FILE(ID)^
create index IDX_TMS_TERMINAL_PROFILING_ON_FILE on TMS_TERMINAL_PROFILING (FILE)^
-- end TMS_TERMINAL_PROFILING
-- begin TMS_TERMINAL_PROFILING_ITEMS
alter table TMS_TERMINAL_PROFILING_ITEMS add constraint FK_TMS_TERMINAL_PROFILING_ITEMS_ON_PROFILING foreign key (PROFILING_ID) references TMS_TERMINAL_PROFILING(ID) on delete CASCADE^
create index IDX_TMS_TERMINAL_PROFILING_ITEMS_ON_PROFILING on TMS_TERMINAL_PROFILING_ITEMS (PROFILING_ID)^
-- end TMS_TERMINAL_PROFILING_ITEMS
-- begin TMS_TERMINAL_GROUP_IMPORT_STAGE
create index IDX_TMS_TERMINAL_GROUP_IMPORT_STAGE_IMPORT on TMS_TERMINAL_GROUP_IMPORT_STAGE (IMPORT_ID)^
create index IDX_TMS_TERMINAL_GROUP_IMPORT_STAGE_SN on TMS_TERMINAL_GROUP_IMPORT_STAGE (IMPORT_ID, SN_NORM)^
create index IDX_TMS_TERMINAL_GROUP_IMPORT_STAGE_CREATE_TS on TMS_TERMINAL_GROUP_IMPORT_STAGE (CREATE_TS)^
-- end TMS_TERMINAL_GROUP_IMPORT_STAGE
