﻿create schema skyscraper5 collate utf8mb3_general_ci;

create table skyscraper_satellites
(
    checksum  int                                 not null
        primary key
        unique,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null,
    angle     float                               not null,
    east      bool                                not null,
    name      VARCHAR(32)                         not null,
    lof1      int                                 not null,
    lof2      int                                 not null,
    lofsw     int                                 not null,
    minfreq   int                                 not null,
    maxfreq   int                                 not null
);

create table skyscraper_queued_jobs
(
    uuid      varchar(36) default UUID()            not null
        primary key
        unique,
    dateadded TIMESTAMP   default CURRENT_TIMESTAMP not null,
    type      int                                   not null,
    i_arg1    int                                   null,
    s_arg1    VARCHAR(255)                          null
);

alter table skyscraper_queued_jobs
    add done bool default false not null;

create table skyscraper_imported_streams
(
    filename  mediumtext                          not null
        primary key
        unique,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null
);

create table dvb_sdt
(
    tsid                   int          not null,
    onid                   int          not null,
    service_id             int          not null,
    eit_schedule           bool         not null,
    eit_schedule_following bool         not null,
    free_ca_mode           bool         not null,
    service_name           varchar(128) null,
    service_provider_name  varchar(128) null,
    service_type           int          null,
    private_data_specifier bigint       null,
    constraint dvb_sdt_pk
        primary key (tsid, onid, service_id)
);

create table dvb_sdt_ca_identifiers
(
    tsid          int                                 not null,
    onid          int                                 not null,
    service_id    int                                 not null,
    ordinal       int                                 not null,
    ca_identifier int                                 not null,
    dateadded     TIMESTAMP default CURRENT_TIMESTAMP not null
);

alter table dvb_sdt
    add component_tag int null;

alter table dvb_sdt
    add iso_639_language_code varchar(3) null;

alter table dvb_sdt
    add component_type int null;

alter table dvb_sdt
    add stream_context int null;

alter table dvb_sdt
    add stream_context_ext int null;

alter table dvb_sdt
    add text varchar(100) null;

alter table dvb_sdt
    add data_broadcast_id int null;

alter table dvb_sdt
    add selector tinyblob null;

alter table dvb_sdt_ca_identifiers
    drop column ordinal;

alter table dvb_sdt_ca_identifiers
    add constraint dvb_sdt_ca_identifiers_pk
        primary key (tsid, onid, service_id, ca_identifier);

alter table dvb_sdt_ca_identifiers
    add constraint dvb_sdt_ca_identifiers_dvb_sdt_tsid_onid_service_id_fk
        foreign key (tsid, onid, service_id) references dvb_sdt (tsid, onid, service_id);

create table dvb_sdt_country_availability
(
    tsid         int                                 not null,
    onid         int                                 not null,
    service_id   int                                 not null,
    country      VARCHAR(3)                          not null,
    availability bool                                not null,
    dateadded    TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_sdt_country_availability_pk
        primary key (tsid, onid, service_id, country),
    constraint dvb_sdt_country_availability_dvb_sdt_tsid_onid_service_id_fk
        foreign key (tsid, onid, service_id) references dvb_sdt (tsid, onid, service_id)
);

create table dvb_sdt_linkages
(
    tsid                        int  not null,
    onid                        int  not null,
    service_id                  int  not null,
    linkage_type                int  not null,
    handover_type               int  null,
    handover_origin_type        bool null,
    handover_network_id         int  null,
    handover_initial_service_id int  null,
    target_event_id             int  null,
    target_event_listed         bool null,
    target_event_simulcasted    bool null,
    constraint dvb_sdt_linkages_pk
        primary key (tsid, onid, service_id, linkage_type),
    constraint dvb_sdt_linkages_dvb_sdt_tsid_onid_service_id_fk
        foreign key (tsid, onid, service_id) references dvb_sdt (tsid, onid, service_id)
);

create table dvb_sdt_linkages_extended_event_linkages
(
    tsid              int                                 not null,
    onid              int                                 not null,
    service_id        int                                 not null,
    target_event      int                                 not null,
    target_listed     bool                                not null,
    event_simulcast   bool                                not null,
    link_type         int                                 not null,
    user_defined_id   int                                 null,
    target_tsid       int                                 null,
    target_onid       int                                 null,
    target_service_id int                                 null,
    dateadded         TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_sdt_linkages_extended_event_linkages_pk
        primary key (tsid, onid, service_id, target_event),
    constraint dvb_sdt_linkages_extended_event_linkages_dvb_sdt_tsid_onid_fk
        foreign key (tsid, onid, service_id) references dvb_sdt (tsid, onid, service_id)
);

create table dvb_sdt_ssu
(
    tsid       int                                 not null,
    onid       int                                 not null,
    service_id int                                 not null,
    oui        varchar(8)                          not null,
    selector   tinyblob                            not null,
    dateadded  TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_sdt_ssu_pk
        primary key (tsid, onid, service_id, oui),
    constraint dvb_sdt_ssu_dvb_sdt_tsid_onid_service_id_fk
        foreign key (tsid, onid, service_id) references dvb_sdt (tsid, onid, service_id)
);

alter table dvb_sdt
    add table_type smallint null;

alter table dvb_sdt
    add bouquet_id int null;

alter table dvb_sdt
    add private_data_bytes tinyblob null;

alter table dvb_sdt
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

alter table dvb_sdt_linkages
    add table_type int null;

alter table dvb_sdt_linkages
    add private_data_bytes TINYBLOB null;

create table dvb_sdt_ipmac
(
    tsid       int                                 not null,
    onid       int                                 not null,
    service_id int                                 not null,
    id         int                                 not null,
    dateadded  TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_sdt_ipmac_pk
        primary key (tsid, onid, service_id, id),
    constraint dvb_sdt_ipmac_dvb_sdt_tsid_onid_service_id_fk
        foreign key (tsid, onid, service_id) references dvb_sdt (tsid, onid, service_id)
);

create table dvb_sdt_ipmac_names
(
    tsid       int                                 not null,
    onid       int                                 not null,
    service_id int                                 not null,
    id         int                                 not null,
    lang       VARCHAR(3)                          not null,
    name       VARCHAR(128)                        not null,
    dateadded  TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_sdt_ipmac_names_pk
        primary key (tsid, onid, service_id, id, lang),
    constraint dvb_sdt_ipmac_names_dvb_sdt_ipmac_tsid_onid_service_id_id_fk
        foreign key (tsid, onid, service_id, id) references dvb_sdt_ipmac (tsid, onid, service_id, id)
);

rename table dvb_sdt_ssu to dvb_sdt_linkages_ssu

rename table dvb_sdt_ipmac_names to dvb_sdt_ssu_ipmac_names;

rename table dvb_sdt_ipmac to dvb_sdt_ssu_ipmac;

rename table dvb_sdt_ssu_ipmac to dvb_sdt_linkages_ipmac;

rename table dvb_sdt_ssu_ipmac_names to dvb_sdt_linkages_ipmac_names;

alter table dvb_sdt
    add reference_service_id int null after private_data_bytes;

create table dvb_sdt_nvod_references
(
    tsid             int                                 not null,
    onid             int                                 not null,
    service_id       int                                 not null,
    other_tsid       int                                 not null,
    other_onid       int                                 not null,
    other_service_id int                                 not null,
    dateadded        TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_sdt_nvod_references_pk
        primary key (tsid, onid, service_id, other_tsid, other_onid, other_service_id),
    constraint dvb_sdt_nvod_references_dvb_sdt_tsid_onid_service_id_fk
        foreign key (tsid, onid, service_id) references dvb_sdt (tsid, onid, service_id)
);

alter table dvb_sdt
    add default_authority VARCHAR(100) null after reference_service_id;

create table dvb_sdt_multilingual_service_name
(
    tsid                  int                                 not null,
    onid                  int                                 not null,
    service_id            int                                 not null,
    language_code         VARCHAR(3)                          not null,
    service_provider_name VARCHAR(100)                        not null,
    service_name          VARCHAR(100)                        not null,
    dateadded             TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_sdt_multilingual_service_name_pk
        primary key (tsid, onid, service_id, language_code),
    constraint dvb_sdt_multilingual_service_name_dvb_sdt_tsid_onid_service_fk
        foreign key (tsid, onid, service_id) references dvb_sdt (tsid, onid, service_id)
);

alter table dvb_sdt
    add control_remote_access_over_internet int null after default_authority;

alter table dvb_sdt
    add do_not_apply_revocation bool null after control_remote_access_over_internet;

alter table dvb_sdt
    add do_not_scramble bool null after do_not_apply_revocation;

alter table dvb_sdt
    add old_onid int null after do_not_scramble;

alter table dvb_sdt
    add old_service_id int null after old_onid;

alter table dvb_sdt
    add old_tsid int null after old_service_id;

alter table dvb_sdt
    drop column table_type;

alter table dvb_sdt
    drop column bouquet_id;

alter table dvb_sdt
    drop column private_data_bytes;

alter table dvb_sdt
    add running_status int not null after eit_schedule_following;

alter table dvb_sdt
    add num_updates bigint default 0 not null;

alter table dvb_sdt
    add dateupdated TIMESTAMP null;

rename table dvb_sdt_linkages to dvb_linkages;

rename table dvb_sdt_linkages_extended_event_linkages to dvb_linkages_extended_event_linkages;

rename table dvb_sdt_linkages_ipmac to dvb_linkages_ipmac;

rename table dvb_sdt_linkages_ipmac_names to dvb_linkages_ipmac_names;

rename table dvb_sdt_linkages_ssu to dvb_linkages_ssu;

alter table dvb_linkages
    add uuid varchar(37) not null first;

alter table dvb_linkages
    drop foreign key dvb_sdt_linkages_dvb_sdt_tsid_onid_service_id_fk

alter table dvb_linkages
    drop primary key;

alter table dvb_linkages
    drop column tsid;

alter table dvb_linkages
    drop column onid;

alter table dvb_linkages
    drop column service_id;

alter table dvb_linkages
    add constraint dvb_linkages_pk
        primary key (uuid, linkage_type);

alter table dvb_linkages_extended_event_linkages
    drop foreign key dvb_sdt_linkages_extended_event_linkages_dvb_sdt_tsid_onid_fk;

alter table dvb_linkages_extended_event_linkages
    add uuid varchar(37) not null first;

alter table dvb_linkages_extended_event_linkages
    drop primary key;

alter table dvb_linkages_extended_event_linkages
    drop column tsid;

alter table dvb_linkages_extended_event_linkages
    drop column onid;

alter table dvb_linkages_extended_event_linkages
    drop column service_id;

alter table dvb_linkages_extended_event_linkages
    add constraint dvb_linkages_extended_event_linkages_pk
        primary key (uuid, target_event);

alter table dvb_linkages_ipmac
    drop foreign key dvb_sdt_ipmac_dvb_sdt_tsid_onid_service_id_fk;

alter table dvb_linkages_ipmac
    add uuid varchar(37) not null first;

alter table dvb_linkages_ipmac
    drop primary key;

alter table dvb_linkages_ipmac_names
    drop foreign key dvb_sdt_ipmac_names_dvb_sdt_ipmac_tsid_onid_service_id_id_fk;

alter table dvb_linkages_ipmac
    drop primary key;

alter table dvb_linkages_ipmac
    drop column tsid;

alter table dvb_linkages_ipmac
    drop column onid;

alter table dvb_linkages_ipmac
    drop column service_id;

alter table dvb_linkages_ipmac
    add primary key (uuid, id);

alter table dvb_linkages_ipmac
    add constraint dvb_linkages_ipmac_dvb_linkages_uuid_fk
        foreign key (uuid) references dvb_linkages (uuid);

alter table dvb_linkages_extended_event_linkages
    add constraint dvb_linkages_extended_event_linkages_dvb_linkages_uuid_fk
        foreign key (uuid) references dvb_linkages (uuid);

alter table dvb_linkages_ipmac_names
    drop primary key;

alter table dvb_linkages_ipmac_names
    drop column tsid;

alter table dvb_linkages_ipmac_names
    add uuid varchar(37) not null first;

alter table dvb_linkages_ipmac_names
    drop column onid;

alter table dvb_linkages_ipmac_names
    drop column service_id;

alter table dvb_linkages_ipmac_names
    add constraint dvb_linkages_ipmac_names_pk
        primary key (uuid, id);

alter table dvb_linkages_ipmac_names
    add constraint dvb_linkages_ipmac_names_dvb_linkages_uuid_fk
        foreign key (uuid) references dvb_linkages (uuid);

alter table dvb_linkages_ssu
    drop foreign key dvb_sdt_ssu_dvb_sdt_tsid_onid_service_id_fk;

alter table dvb_linkages_ssu
    add uuid varchar(37) not null first;

alter table dvb_linkages_ssu
    drop primary key;

alter table dvb_linkages_ssu
    drop column tsid;

alter table dvb_linkages_ssu
    drop column onid;

alter table dvb_linkages_ssu
    drop column service_id;

alter table dvb_linkages_ssu
    add constraint dvb_linkages_ssu_pk
        primary key (uuid, oui);

alter table dvb_linkages_ssu
    add constraint dvb_linkages_ssu_dvb_linkages_uuid_fk
        foreign key (uuid) references dvb_linkages (uuid);

alter table dvb_sdt
    add uuid varchar(37) null after old_tsid;

create table dvb_nit
(
    id int not null
        primary key
);

alter table dvb_nit
    add name VARCHAR(100) null;

alter table dvb_nit
    add uuid varchar(37) null;

alter table dvb_nit
    add private_data_specifier_id bigint null;

create table dvb_nit_cells
(
    nid_id              int not null,
    cell_id             int not null,
    cell_longitude      int not null,
    cell_latitude       int not null,
    extend_of_latitude  int not null,
    extend_of_longitude int not null,
    constraint dvb_nit_cells_pk
        primary key (nid_id, cell_id),
    constraint dvb_nit_cells_dvb_nit_id_fk
        foreign key (nid_id) references dvb_nit (id)
);

alter table dvb_nit_cells
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

create table dvb_nit_cells_subcells
(
    nid                         int                                 not null,
    cell_id                     int                                 not null,
    cell_id_extension           smallint                            not null,
    subcell_latitude            int                                 not null,
    subcell_longitude           int                                 not null,
    subcell_extent_of_latitude  int                                 not null,
    subcell_extent_of_longitude int                                 not null,
    dateadded                   TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_cells_subcells_pk
        primary key (nid, cell_id, cell_id_extension),
    constraint dvb_nit_cells_subcells_dvb_nit_cells_nid_id_cell_id_fk
        foreign key (nid, cell_id) references dvb_nit_cells (nid_id, cell_id)
);

alter table dvb_nit
    add xait_pid int null;

create table dvb_nit_multilingual_name
(
    id        int                                 not null,
    language  varchar(3)                          not null,
    name      varchar(100)                        not null,
    dateadded timestamp default current_timestamp not null,
    constraint dvb_nit_multilingual_name_pk
        primary key (id, language),
    constraint dvb_nit_multilingual_name_dvb_nit_id_fk
        foreign key (id) references dvb_nit (id)
);

create table dvb_nit_region_names
(
    id             int                                 not null,
    name           VARCHAR(100)                        not null,
    primary_code   smallint                            not null,
    secondary_code smallint                            null,
    teritary_code  int                                 null,
    dateadded      TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_region_names_pk
        primary key (id, name),
    constraint dvb_nit_region_names_dvb_nit_id_fk
        foreign key (id) references dvb_nit (id)
);

alter table dvb_nit
    add region_name_country_code varchar(3) null;

alter table dvb_nit
    add region_name_language_code varchar(3) null;

create table dvb_nit_regions
(
    id                    int                                 not null,
    country_code          varchar(3)                          not null,
    primary_region_code   smallint                            null,
    secondary_region_code smallint                            null,
    teritary_region_code  int                                 null,
    dateadded             TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_regions_pk
        primary key (id, country_code),
    constraint dvb_nit_regions_dvb_nit_id_fk
        foreign key (id) references dvb_nit (id)
);

alter table dvb_nit
    add region_country_code VARCHAR(3) null;

create table dvb_nit_messages
(
    network_id    int                                 not null,
    message_id    int                                 not null,
    language_code VARCHAR(3)                          not null,
    message       VARCHAR(100)                        not null,
    dateadded     TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_messages_pk
        primary key (network_id, message_id),
    constraint dvb_nit_messages_dvb_nit_id_fk
        foreign key (network_id) references dvb_nit (id)
);

alter table dvb_nit
    add min_polling_interval int null;

alter table dvb_nit
    add uri varchar(100) null;

alter table dvb_nit
    add uri_linkage_type int null;

create table dvb_nit_services
(
    network_id   int                                 not null,
    service_id   int                                 not null,
    service_type int                                 null,
    dateadded    TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_services_pk
        primary key (network_id, service_id),
    constraint dvb_nit_services_dvb_nit_id_fk
        foreign key (network_id) references dvb_nit (id)
);

alter table dvb_nit
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

create table dvb_nit_transport_stream
(
    nid       int                                 not null,
    tsid      int                                 not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_transport_stream_pk
        primary key (nid, tsid),
    constraint dvb_nit_transport_stream_dvb_nit_id_fk
        foreign key (nid) references dvb_nit (id)
);

alter table dvb_nit_transport_stream
    add onid int not null;

alter table dvb_nit_transport_stream
    add delivery_method int not null;

alter table dvb_nit_transport_stream
    add east bool null;

alter table dvb_nit_transport_stream
    add fec_inner int null;

alter table dvb_nit_transport_stream
    add frequency bigint null;

alter table dvb_nit_transport_stream
    add orbital_position float null;

alter table dvb_nit_transport_stream
    add polarization int null;

alter table dvb_nit_transport_stream
    add roll_off int null;

alter table dvb_nit_transport_stream
    add s2 bool null;

alter table dvb_nit_transport_stream
    add symbol_rate bigint null;

alter table dvb_nit_transport_stream
    add scrambling_sequence_index int null;

alter table dvb_nit_transport_stream
    add input_stream_identifier smallint null;

alter table dvb_nit_transport_stream
    add timeslice_number smallint null;

alter table dvb_nit_transport_stream
    add ts_gs_mode int null;

alter table dvb_nit_transport_stream
    add private_data_specifier_id bigint null;

alter table dvb_nit_transport_stream
    add tfs_flag bool null;

alter table dvb_nit_transport_stream
    add bandwidth int null;

alter table dvb_nit_transport_stream
    add guard_interval int null;

alter table dvb_nit_transport_stream
    add other_frequency_flag bool null;

alter table dvb_nit_transport_stream
    add plp_id smallint null;

alter table dvb_nit_transport_stream
    add siso_miso int null;

alter table dvb_nit_transport_stream
    add t2_system_id int null;

alter table dvb_nit_transport_stream
    add transmission_mode int null;

alter table dvb_nit_transport_stream
    add coding_type int null;

alter table dvb_nit_transport_stream
    add modulation_type int null;

alter table dvb_nit_transport_stream
    add fec_outer int null;

alter table dvb_nit_transport_stream
    add code_rate_hp_stream int null;

alter table dvb_nit_transport_stream
    add code_rate_lp_stream int null;

alter table dvb_nit_transport_stream
    add hierarchy_information int null;

alter table dvb_nit_transport_stream
    add mpe_fec_indicator bool null;

alter table dvb_nit_transport_stream
    add priority bool null;

alter table dvb_nit_transport_stream
    add time_slicing_indicator bool null;

alter table dvb_nit_transport_stream
    add network_name varchar(100) null;

alter table dvb_nit_transport_stream
    add target_region_country_code varchar(3) null;

create table dvb_nit_transport_stream_services
(
    nid          int                                 null,
    tsid         int                                 null,
    service_id   int                                 null,
    service_type int                                 null,
    date_added   TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_transport_stream_services_pk
        primary key (nid, tsid, service_id),
    constraint dvb_nit_transport_stream_services_dvb_nit_transport_stream_fk
        foreign key (nid, tsid) references dvb_nit_transport_stream (nid, tsid)
);

alter table dvb_nit_transport_stream
    add uuid varchar(37) null;

create table dvb_nit_transport_stream_lcn
(
    nid        int                                 not null,
    tsid       int                                 not null,
    service_id int                                 not null,
    lcn        int                                 not null,
    dateadded  TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_transport_stream_lcn_pk
        primary key (nid, tsid, service_id),
    constraint dvb_nit_transport_stream_lcn_dvb_nit_transport_stream_nid_fk
        foreign key (nid, tsid) references dvb_nit_transport_stream (nid, tsid)
);

create table dvb_nit_transport_stream_cell_infos
(
    nid       int                                 not null,
    tsid      int                                 not null,
    cell_id   int                                 not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_transport_stream_cell_infos_pk
        primary key (nid, tsid, cell_id),
    constraint dvb_nit_transport_stream_cell_infos_dvb_nit_transport_stream_fk
        foreign key (nid, tsid) references dvb_nit_transport_stream (nid, tsid)
);

create table dvb_nit_transport_stream_cell_infos_center_frequencies
(
    nid       int                                 not null,
    tsid      int                                 not null,
    cell_id   int                                 not null,
    ordinal   int                                 not null,
    frequency bigint                              not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_transport_stream_cell_infos_center_frequencies_pk
        primary key (tsid, nid, cell_id, ordinal),
    constraint dvb_nit_transport_stream_cell_infos_center_frequencies_dvb_fk
        foreign key (nid, tsid, cell_id) references dvb_nit_transport_stream_cell_infos (nid, tsid, cell_id)
);

drop table dvb_nit_transport_stream_lcn;

create table dvb_nit_transport_stream_cell_infos_subcell_infos
(
    nid                  int                                 not null,
    tsid                 int                                 not null,
    cell_id              int                                 not null,
    ordinal              int                                 not null,
    cell_id_extension    smallint                            not null,
    transposer_frequency bigint                              not null,
    dateadded            TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_transport_stream_cell_infos_subcell_infos_pk
        primary key (tsid, nid, cell_id, ordinal),
    constraint dvb_nit_transport_stream_cell_infos_subcell_infos_dvb_nit_fk
        foreign key (nid, tsid, cell_id) references dvb_nit_transport_stream_cell_infos (nid, tsid, cell_id)
);

create table dvb_nit_transport_stream_centre_frequencies
(
    nid       int                                 not null,
    tsid      int                                 not null,
    ordinal   int                                 not null,
    frequency bigint                              not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_transport_stream_centre_frequencies_pk
        primary key (tsid, nid, ordinal),
    constraint dvb_nit_transport_stream_centre_frequencies_dvb_nit_fk
        foreign key (nid, tsid) references dvb_nit_transport_stream (nid, tsid)
);

create table dvb_nit_transport_stream_cells
(
    nid        int                                 not null,
    tsid       int                                 not null,
    cell_id    int                                 not null,
    cell_lat   int                                 not null,
    cell_lon   int                                 not null,
    extent_lat bigint                              not null,
    extent_lon bigint                              not null,
    date_added TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_transport_stream_cells_pk
        primary key (nid, tsid, cell_id),
    constraint dvb_nit_transport_stream_cells_dvb_nit_transport_stream_nid_fk
        foreign key (nid, tsid) references dvb_nit_transport_stream (nid, tsid)
);

create table dvb_nit_transport_streams_cells_subcells
(
    nid                int                                 not null,
    tsid               int                                 not null,
    cell_id            int                                 not null,
    cell_id_extension  int                                 not null,
    subcell_lat        int                                 not null,
    subcell_lon        int                                 not null,
    subcell_extent_lat int                                 not null,
    subcell_extent_lon int                                 not null,
    dateadded          TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_transport_streams_cells_subcells_pk
        primary key (nid, tsid, cell_id, cell_id_extension),
    constraint dvb_nit_transport_streams_cells_subcells_dvb_nit_transport_fk
        foreign key (nid, tsid, cell_id) references dvb_nit_transport_stream_cells (nid, tsid, cell_id)
);

create table dvb_nit_transport_stream_target_regions
(
    nid          int                                 not null,
    tsid         int                                 not null,
    country_code varchar(3)                          not null,
    primary_rc   smallint                            null,
    secondary_rc smallint                            null,
    teritary_rc  int                                 null,
    dateadded    TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_transport_stream_target_regions_pk
        primary key (nid, tsid, country_code),
    constraint dvb_nit_transport_stream_target_regions_dvb_nit_transport_fk
        foreign key (nid, tsid) references dvb_nit_transport_stream (nid, tsid)
);

create table dvb_nit_transport_stream_cell_frequencies
(
    nid       int                                 not null,
    tsid      int                                 not null,
    cell_id   int                                 not null,
    frequency bigint                              not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_nit_transport_stream_cell_frequencies_pk
        primary key (nid, tsid, cell_id),
    constraint dvb_nit_transport_stream_cell_frequencies_dvb_nit_transport_fk
        foreign key (nid, tsid) references dvb_nit_transport_stream (nid, tsid)
);

alter table dvb_nit_transport_stream
    modify roll_off float null;

rename table dvb_nit_transport_streams_cells_subcells to dvb_nit_transport_stream_cells_subcells;

alter table dvb_nit
    add numupdates int default 0 not null;

alter table dvb_nit
    add dateupdated TIMESTAMP null;

alter table dvb_nit_transport_stream
    add numupdates int default 0 not null;

alter table dvb_nit_transport_stream
    add dateupdated TIMESTAMP null;

create table dvb_cat
(
    nid       int                                 not null,
    tsid      int                                 not null,
    ca_pid    int                                 not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_cat_pk
        primary key (nid, tsid, ca_pid)
)

alter table dvb_cat
    add ca_system_id int not null after ca_pid;

alter table dvb_cat
    add private_data tinyblob null after ca_system_id;

create table dvb_pmt
(
    nid            int                                 not null,
    tsid           int                                 not null,
    program_number int                                 not null,
    dateadded      TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_pmt_pk
        primary key (nid, tsid, program_number)
);

alter table dvb_pmt
    add pcr_pid int not null after program_number;

create table dvb_pmt_streams
(
    onid                  int        not null,
    tsid                  int        not null,
    program_number        int        not null,
    stream_type           int        not null,
    elementary_pid        int        not null,
    component_tag         smallint   null,
    audio_type            int        null,
    iso_639_language_code VARCHAR(3) null,
    constraint dvb_pmt_streams_pk
        primary key (onid, tsid, program_number, elementary_pid),
    constraint dvb_pmt_streams_dvb_pmt_nid_tsid_program_number_fk
        foreign key (onid, tsid, program_number) references dvb_pmt (nid, tsid, program_number)
);

create table dvb_pmt_streams_teletext
(
    onid                     int                                 not null,
    tsid                     int                                 not null,
    elementary_pid           int                                 not null,
    iso_639_language_code    VARCHAR(3)                          not null,
    teletext_type            int                                 not null,
    teletext_magazine_number int                                 not null,
    teletext_page_number     int                                 not null,
    dateadded                TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_pmt_streams_teletext_pk
        primary key (onid, tsid, elementary_pid, teletext_page_number)
);

create index dvb_pmt_streams_onid_tsid_elementary_pid_index
    on dvb_pmt_streams (onid, tsid, elementary_pid);

alter table dvb_pmt_streams_teletext
    add constraint dvb_pmt_streams_teletext_dvb_pmt_streams_onid_tsid_elementary_fk
        foreign key (onid, tsid, elementary_pid) references dvb_pmt_streams (onid, tsid, elementary_pid);

create table dvb_pmt_streams_applications
(
    onid               int                                 not null,
    tsid               int                                 not null,
    elementary_pid     int                                 not null,
    application_type   int                                 not null,
    ait_version_number int                                 not null,
    dateadded          TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_pmt_streams_applications_pk
        primary key (onid, tsid, elementary_pid),
    constraint dvb_pmt_streams_applications_dvb_pmt_streams_onid_tsid_fk
        foreign key (onid, tsid, elementary_pid) references dvb_pmt_streams (onid, tsid, elementary_pid)
);

alter table dvb_pmt_streams
    add carousel_format_id smallint null;

alter table dvb_pmt_streams
    add carousel_id bigint null;

alter table dvb_pmt_streams
    add data_broadcast_id int null;

alter table dvb_pmt_streams
    add data_broadcast_selector tinyblob null;

create table dvb_pmt_streams_ip
(
    onid                int                                 not null,
    tsid                int                                 not null,
    elementary_pid      int                                 not null,
    platform_id         bigint                              not null,
    action_type         tinyint                             not null,
    int_versioning_flag bool                                not null,
    int_version         int                                 not null,
    dateadded           TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_pmt_streams_ip_pk
        primary key (onid, tsid, elementary_pid, platform_id),
    constraint dvb_pmt_streams_ip_dvb_pmt_streams_onid_tsid_elementary_pid_fk
        foreign key (onid, tsid, elementary_pid) references dvb_pmt_streams (onid, tsid, elementary_pid)
);

alter table dvb_pmt_streams
    add supplementary_independant_stream bool null;

alter table dvb_pmt_streams
    add editorial_classification int null;

alter table dvb_pmt_streams
    add supplementary_language_code varchar(3) null;

alter table dvb_pmt_streams
    add asvc tinyint null;

alter table dvb_pmt_streams
    add bsid int null;

alter table dvb_pmt_streams
    add component_type int null;

alter table dvb_pmt_streams
    add main_id tinyint null;

alter table dvb_pmt_streams
    add frame_rate double null;

alter table dvb_pmt_streams
    add mpeg1_only_flag bool null;

alter table dvb_pmt_streams
    add chroma_format int null;

alter table dvb_pmt_streams
    add constrained_parameter_flag bool null;

alter table dvb_pmt_streams
    add frame_rate_extension_flag int null;

alter table dvb_pmt_streams
    add multiple_framerate_flag bool null;

alter table dvb_pmt_streams
    add profile_and_level_indicator tinyint null;

alter table dvb_pmt_streams
    add still_picture_flag bool null;

alter table dvb_pmt_streams
    add alignment_type tinyint null;

alter table dvb_pmt_streams
    add maximum_bitrate bigint null;

alter table dvb_pmt_streams
    add audio_stream_id bool null;

alter table dvb_pmt_streams
    add free_format bool null;

alter table dvb_pmt_streams
    add layer int null;

alter table dvb_pmt_streams
    add variable_rate_audio bool null;

alter table dvb_pmt_streams
    add constraint_set0_flag bool null;

alter table dvb_pmt_streams
    add avc_24hour_picture_flag bool null;

alter table dvb_pmt_streams
    add avc_compatible_flags int null;

alter table dvb_pmt_streams
    add avc_still_present bool null;

alter table dvb_pmt_streams
    add constraint_set1_flag bool null;

alter table dvb_pmt_streams
    add constraint_set2_flag bool null;

alter table dvb_pmt_streams
    add constraint_set3_flag bool null;

alter table dvb_pmt_streams
    add constraint_set4_flag bool null;

alter table dvb_pmt_streams
    add constraint_set5_flag bool null;

alter table dvb_pmt_streams
    add frame_packing_sei_not_present bool not null;

alter table dvb_pmt_streams
    add level_idc tinyint null;

alter table dvb_pmt_streams
    add profile_rdc tinyint null;

alter table dvb_pmt_streams
    add ca_pid int null;

alter table dvb_pmt_streams
    add ca_system_id int null;

alter table dvb_pmt_streams
    add ca_private_data tinyblob null;

alter table dvb_pmt_streams
    add private_data_specifier bigint null;

create table dvb_pmt_streams_subtitle
(
    onid                  int                                 not null,
    tsid                  int                                 not null,
    elementary_pid        int                                 not null,
    ordinal               int                                 not null,
    iso_639_language_type varchar(3)                          not null,
    subtitling_type       tinyint                             not null,
    composition_page_id   int                                 not null,
    ancillary_page_id     int                                 not null,
    dateadded             TIMESTAMP default CURRENT_TIMESTAMP null,
    constraint dvb_pmt_streams_subtitle_pk
        primary key (onid, tsid, elementary_pid, ordinal),
    constraint dvb_pmt_streams_subtitle_dvb_pmt_streams_onid_tsid_elementary_fk
        foreign key (onid, tsid, elementary_pid) references dvb_pmt_streams (onid, tsid, elementary_pid)
);

alter table dvb_pmt_streams
    add format_identifier bigint null;

alter table dvb_pmt_streams
    add additional_identification_info tinyblob null;

alter table dvb_pmt_streams
    add association_tag_selector tinyblob null;

alter table dvb_pmt_streams
    add association_tag_transaction_id bigint null;

alter table dvb_pmt_streams
    add association_tag_use int null;

alter table dvb_pmt_streams
    add association_tag_private_data tinyblob null;

alter table dvb_pmt_streams
    add association_tag_timeout bigint null;

create table dvb_pmt_streams_vbi
(
    onid            int                                 not null,
    tsid            int                                 not null,
    elementary_pid  int                                 not null,
    field_parity    bool                                not null,
    line_offset     int                                 not null,
    data_service_id tinyint                             not null,
    dateadded       TIMESTAMP default CURRENT_TIMESTAMP null,
    constraint dvb_pmt_streams_vbi_pk
        primary key (onid, tsid, elementary_pid, field_parity, line_offset),
    constraint dvb_pmt_streams_vbi_dvb_pmt_streams_onid_tsid_elementary_pid_fk
        foreign key (onid, tsid, elementary_pid) references dvb_pmt_streams (onid, tsid, elementary_pid)
);

alter table dvb_pmt_streams
    add aac_type tinyint null;

alter table dvb_pmt_streams
    add aac_additional_info tinyblob null;

alter table dvb_pmt_streams
    add aac_profile_and_level tinyint null;

alter table dvb_pmt_streams
    add saoc_de_flag bool null;

alter table dvb_pmt_streams
    add ancillary_data_identifier smallint null;

alter table dvb_pmt_streams
    add mix_info_exists bool null;

alter table dvb_pmt_streams
    add substream1 tinyint null;

alter table dvb_pmt_streams
    add substream2 tinyint null;

alter table dvb_pmt_streams
    add substream3 tinyint null;

alter table dvb_pmt_streams
    add copied_44bits bigint null;

alter table dvb_pmt_streams
    add frame_only_constraint_flag bool null;

alter table dvb_pmt_streams
    add hdr_wcg_idc int null;

alter table dvb_pmt_streams
    add hevc_24hr_picture_present_flag bool null;

alter table dvb_pmt_streams
    add hevc_still_present_flag bool null;

alter table dvb_pmt_streams
    add interlaced_source_flag bool null;

alter table dvb_pmt_streams
    add non_packed_constraint_flag bool null;

alter table dvb_pmt_streams
    add profile_compatibility_indication bigint null;

alter table dvb_pmt_streams
    add profile_idc int null;

alter table dvb_pmt_streams
    add profile_space int null;

alter table dvb_pmt_streams
    add progressive_source_flag bool null;

alter table dvb_pmt_streams
    add sub_pic_hrd_params_not_present_flag bool null;

alter table dvb_pmt_streams
    add temporal_id_max int null;

alter table dvb_pmt_streams
    add tier_flag bool null;

alter table dvb_pmt_streams
    add temporal_id_min int null;

alter table dvb_pmt_streams
    add ac4_channel_mode int null;

alter table dvb_pmt_streams
    add ac4_dialog_enhancement bool null;

alter table dvb_pmt_streams
    add ac4_dsi tinyblob null;

create table dvb_pmt_streams_audio_preselection
(
    onid                       int                                 not null,
    tsid                       int                                 not null,
    elementary_pid             int                                 not null,
    preselection_id            int                                 not null,
    audio_rendering_indication int                                 not null,
    audio_description          bool                                not null,
    spoken_subtitles           bool                                not null,
    dialogue_enhancement       int                                 not null,
    interactivity_enabled      bool                                not null,
    iso_639_language_code      varchar(3)                          not null,
    message_id                 tinyint                             not null,
    component_tags             tinyblob                            not null,
    future_extension           tinyblob                            not null,
    dateadded                  TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_pmt_streams_audio_preselection_pk
        primary key (onid, tsid, elementary_pid, preselection_id),
    constraint dvb_pmt_streams_audio_preselection_dvb_pmt_streams_onid_tsid_fk
        foreign key (onid, tsid, elementary_pid) references dvb_pmt_streams (onid, tsid, elementary_pid)
);

alter table dvb_pmt_streams
    add leak_valid_flag bool null

create table dvb_pmt_streams_flexmux
(
    nid             int                                 not null,
    tsid            int                                 not null,
    elementary_pid  int                                 not null,
    es_id           int                                 not null,
    flexmux_channel tinyint                             not null,
    dateadded       TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_pmt_streams_flexmux_pk
        primary key (nid, tsid, elementary_pid, es_id),
    constraint dvb_pmt_streams_flexmux_dvb_pmt_streams_onid_tsid_elementary_fk
        foreign key (nid, tsid, elementary_pid) references dvb_pmt_streams (onid, tsid, elementary_pid)
);

alter table dvb_pmt_streams
    add sb_leak_rate bigint null;

alter table dvb_pmt_streams
    add sb_size bigint not null;

alter table dvb_pmt_streams
    add private_data_indicator bigint null;

alter table dvb_pmt_streams
    add _90khz_flag bool null;

alter table dvb_pmt_streams
    add picture_and_timing_info_present_flag bool null;

alter table dvb_pmt_streams
    add hdr_management_valid_flag bool null;

alter table dvb_pmt_streams
    add k bigint null;

alter table dvb_pmt_streams
    add n bigint null;

alter table dvb_pmt_streams
    add num_units_in_tick bigint null;

alter table dvb_pmt_streams
    add target_schedule_idx int null;

alter table dvb_pmt_streams
    add target_schedule_idx_not_present_flag bool null;

alter table dvb_pmt_streams
    add adaption_field_data_identifier tinyint null;

alter table dvb_pmt_streams
    add fixed_frame_rate_flag bool null;

alter table dvb_pmt_streams
    add picture_to_display_conversion_flag bool null;

alter table dvb_pmt_streams
    add temporal_poc_flag bool null;

alter table dvb_pmt_streams
    add mpeg4_audio_profile_and_level tinyint null;

alter table dvb_pmt_streams
    add aac_channel_configuration tinyint null;

alter table dvb_pmt_streams
    add aac_profile tinyint null;

alter table dvb_pmt_streams
    add aac_additional_information tinyint null;

alter table dvb_pmt_streams
    add scrambling_mode tinyint null;

alter table dvb_pmt_streams
    add related_content_descriptor_present bool null;

alter table dvb_pmt_streams_teletext
    add vbi boolean default false not null;

alter table dvb_pmt_streams
    add num_t2mi_streams int null;

alter table dvb_pmt_streams
    add t2mi_stream_id int null;

alter table dvb_pmt_streams
    add pcr_iscr_common_clock_flag bool null;

alter table dvb_pmt
    add maximum_bitrate bigint null;

alter table dvb_pmt
    add multiplex_buffer_utilization_bound_valid_flag bool null;

alter table dvb_pmt
    add multiplex_lfw_offset_lower_bound int null;

alter table dvb_pmt
    add multiplex_ltw_offset_upper_bound int null;

alter table dvb_pmt
    add clock_accuracy_exponent int null;

alter table dvb_pmt
    add clock_accuracy_integer int null;

alter table dvb_pmt
    add external_clock_reference_indicator bool null;

alter table dvb_pmt
    add sb_leak_rate bigint null;

alter table dvb_pmt
    add sb_size bigint null;

alter table dvb_pmt
    add ca_pid int null;

alter table dvb_pmt
    add ca_system_id int null;

alter table dvb_pmt
    add ca_private_data tinyblob null;

alter table dvb_pmt
    add private_data_specifier bigint null;

alter table dvb_pmt
    add registration_additional_identification_info tinyblob null;

alter table dvb_pmt
    add registration_format_identifier bigint null;

alter table dvb_pmt
    add new_original_network_id int null;

alter table dvb_pmt
    add new_service_id int null;

alter table dvb_pmt
    add new_transport_stream_id int null;

alter table dvb_pmt
    add component_tag tinyint null;

alter table dvb_pmt
    add metadata_input_leak_rate int null;

alter table dvb_pmt
    add metadata_buffer_size int null;

alter table dvb_pmt
    add metadata_output_leak_rate int null;

alter table dvb_pmt
    add scrambling_mode tinyint null;

alter table dvb_pmt
    add es_id int null;

alter table dvb_pmt
    add audio_type int null;

alter table dvb_pmt
    add iso_639_language_code varchar(3) null;

alter table dvb_pmt
    add iod_graphics_profile_level_indication tinyint null;

alter table dvb_pmt
    add iod_visual_profile_level_indication tinyint null;

alter table dvb_pmt
    add iod_audio_profile_level_indication tinyint null;

alter table dvb_pmt
    add iod_scene_profile_level_indication tinyint null;

alter table dvb_pmt
    add iod_od_profile_level_indication tinyint null;

alter table dvb_pmt
    add iod_url_string varchar(200) null;

alter table dvb_pmt
    add iod_include_inline_profile_level_flag bool null;

alter table dvb_pmt
    add iod_url_flag bool null;

alter table dvb_pmt
    add iod_object_descriptor_id int null;

alter table dvb_pmt
    add scope_of_iod_label tinyint null;

alter table dvb_pmt
    add iod_label tinyint null;

alter table dvb_pmt
    add private_data_indicator bigint null;

alter table dvb_pmt
    add frame_Rate double null;

alter table dvb_pmt
    add chroma_format int null;

alter table dvb_pmt
    add constrained_parameter_flag bool null;

alter table dvb_pmt
    add frame_rate_extension_flag int null;

alter table dvb_pmt
    add mpeg1_only_flag bool null;

alter table dvb_pmt
    add multiple_framerate_flag bool null;

alter table dvb_pmt
    add profile_and_level_indication tinyint null;

alter table dvb_pmt
    add still_picture_flag bool null;

alter table dvb_pmt
    add metadata_program_number int null;

alter table dvb_pmt
    add metadata_application_format int null;

alter table dvb_pmt
    add metadata_application_format_identifier bigint null;

alter table dvb_pmt
    add metadata_format int null;

alter table dvb_pmt
    add metadata_format_identifier bigint null;

alter table dvb_pmt
    add metadata_locator_record tinyblob null;

alter table dvb_pmt
    add metadata_locator_record_flag bool null;

alter table dvb_pmt
    add metadata_service_id tinyblob null;

alter table dvb_pmt
    add mpeg_carriage_flag int null;

alter table dvb_pmt
    add metadata_private_data tinyblob null;

alter table dvb_pmt
    add transport_stream_id int null;

alter table dvb_pmt
    add transport_stream_location int null;

alter table dvb_pmt
    add free_format bool null;

alter table dvb_pmt
    add audio_stream_id bool null;

alter table dvb_pmt
    add layer int null;

alter table dvb_pmt
    add variable_rate_audio bool null;

alter table dvb_pmt
    add copy_control_private_data tinyblob null;

alter table dvb_pmt
    add alignment_type tinyint null;

alter table dvb_pmt
    add hierarchy_type int null;

alter table dvb_pmt
    add hierarchy_layer_type int null;

alter table dvb_pmt
    add tref_present_flag bool null;

alter table dvb_pmt
    add hierarchy_channel int null;

alter table dvb_pmt
    add no_view_scalability_flag bool null;

alter table dvb_pmt
    add hierarchy_embedded_layer_index int null;

alter table dvb_pmt
    add no_quality_scalability_flag bool null;

alter table dvb_pmt
    add no_spatial_scalability_flag bool null;

alter table dvb_pmt
    add no_temporal_scalability_flag bool null;

alter table dvb_pmt_streams
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

alter table dvb_pmt_streams
    modify frame_packing_sei_not_present tinyint(1) null;

alter table dvb_pmt_streams
    modify level_idc smallint null;

alter table dvb_pmt_streams
    modify sb_size bigint null;

create table dvb_pat
(
    cnid       int                                 not null,
    ctsid      int                                 not null,
    pmt_pid    int                                 not null,
    program_id int                                 not null,
    dateadded  TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_pat_pk
        primary key (cnid, ctsid, program_id)
);

create table dvb_tdt
(
    cnid        int                                 not null,
    ctid        int                                 not null,
    utc         TIMESTAMP                           not null,
    dateadded   TIMESTAMP default CURRENT_TIMESTAMP not null,
    dateupdated TIMESTAMP                           null,
    num_updates bigint    default 0                 not null,
    constraint dvb_tdt_pk
        primary key (cnid, ctid)
);

alter table dvb_tdt
    modify utc timestamp null on update current_timestamp()

create table dvb_eit
(
    onid           int       not null,
    tsid           int       not null,
    service_id     int       not null,
    event_id       int       not null,
    start_time     TIMESTAMP not null,
    duration       int       not null,
    running_status int       not null,
    free_ca        bool      not null,
    constraint dvb_eit_pk
        primary key (onid, tsid, service_id, start_time)
);

alter table dvb_eit
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

alter table dvb_eit
    modify start_time timestamp default '0000-00-00 00:00:00' null on update current_timestamp();

alter table dvb_eit
    add iso_639_language_code varchar(3) null;

alter table dvb_eit
    add event_name varchar(128) null;

alter table dvb_eit
    add text mediumtext null;

create table dvb_eit_event_items
(
    onid        int                                     not null,
    tsid        int                                     not null,
    service_id  int                                     not null,
    start_time  TIMESTAMP default '0000-00-00 00:00:00' not null,
    ordinal     int                                     not null,
    description varchar(128)                            not null,
    item        mediumtext                              not null,
    dateadded   TIMESTAMP default CURRENT_TIMESTAMP     not null,
    constraint dvb_eit_event_items_pk
        primary key (onid, tsid, service_id, start_time, ordinal),
    constraint dvb_eit_event_items_dvb_eit_onid_tsid_service_id_start_time_fk
        foreign key (onid, tsid, service_id, start_time) references dvb_eit (onid, tsid, service_id, start_time)
);

alter table dvb_eit
    add extended_text mediumtext null;

alter table dvb_eit
    add pdc timestamp null;

create table dvb_eit_component
(
    onid                  int                                     not null,
    tsid                  int                                     not null,
    service_id            int                                     not null,
    start_time            timestamp default '0000-00-00 00:00:00' not null,
    text                  varchar(127)                            not null,
    iso_639_langauge_code varchar(3)                              not null,
    component_tag         smallint                                not null,
    component_type        smallint                                not null,
    stream_content        int                                     not null,
    stream_content_ext    int                                     not null,
    dateadded             TIMESTAMP default CURRENT_TIMESTAMP     null,
    constraint dvb_eit_pk
        primary key (onid, tsid, service_id, start_time, component_tag),
    constraint dvb_eit_component_dvb_eit_onid_tsid_service_id_start_time_fk
        foreign key (onid, tsid, service_id, start_time) references dvb_eit (onid, tsid, service_id, start_time)
);

create table dvb_eit_content
(
    onid       int                                     not null,
    tsid       int                                     not null,
    service_id int                                     not null,
    start_time timestamp default '0000-00-00 00:00:00' not null,
    l          int                                     not null,
    m          int                                     not null,
    r          tinyint                                 not null,
    dateadded  TIMESTAMP default CURRENT_TIMESTAMP     null,
    constraint dvb_eit_content_pk
        primary key (onid, tsid, service_id, start_time, l, m, r),
    constraint dvb_eit_content_dvb_eit_onid_tsid_service_id_start_time_fk
        foreign key (onid, tsid, service_id, start_time) references dvb_eit (onid, tsid, service_id, start_time)
);

alter table dvb_eit
    add private_data_specifier bigint null;

alter table dvb_eit
    add vps varchar(6) null;

create table dvb_eit_parental_ratings
(
    onid       int                                     not null,
    tsid       int                                     not null,
    service_id int                                     not null,
    start_time timestamp default '0000-00-00 00:00:00' not null,
    country    varchar(3)                              not null,
    age        int                                     not null,
    dateadded  TIMESTAMP default CURRENT_TIMESTAMP     not null,
    constraint dvb_eit_parental_ratings_pk
        primary key (onid, tsid, service_id, start_time, country),
    constraint dvb_eit_parental_ratings_dvb_eit_onid_tsid_service_id_fk
        foreign key (onid, tsid, service_id) references dvb_eit (onid, tsid, service_id)
);

alter table dvb_eit
    add uuid varchar(37) null;

create table dvb_eit_ca_systems
(
    onid       int                                     not null,
    tsid       int                                     not null,
    service_id int                                     not null,
    start_time timestamp default '0000-00-00 00:00:00' not null,
    ca_system  int                                     not null,
    dateadded  TIMESTAMP default CURRENT_TIMESTAMP     not null,
    constraint dvb_eit_ca_systems_pk
        primary key (onid, tsid, service_id, start_time, ca_system),
    constraint dvb_eit_ca_systems_dvb_eit_onid_tsid_service_id_start_time_fk
        foreign key (onid, tsid, service_id, start_time) references dvb_eit (onid, tsid, service_id, start_time)
);

alter table dvb_eit
    add reference_service_id int null;

alter table dvb_eit
    add reference_event_id int null;

create table dvb_eit_crids
(
    onid          int                                     not null,
    tsid          int                                     not null,
    service_id    int                                     not null,
    start_time    timestamp default '0000-00-00 00:00:00' not null,
    ordinal       int                                     not null,
    crid_type     int                                     not null,
    crid_location int                                     not null,
    crid_bytes    tinyblob                                not null,
    dateadded     TIMESTAMP default CURRENT_TIMESTAMP     not null,
    constraint dvb_eit_crids_pk
        primary key (onid, tsid, service_id, start_time, ordinal),
    constraint dvb_eit_crids_dvb_eit_onid_tsid_service_id_start_time_fk
        foreign key (onid, tsid, service_id, start_time) references dvb_eit (onid, tsid, service_id, start_time)
);

alter table dvb_eit
    add control_remove_access_over_internet int null;

alter table dvb_eit
    add do_not_apply_revocation bool null;

alter table dvb_eit
    add do_not_scramble bool null;

create table dvb_bat
(
    id        int                                 not null
        primary key,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null
);

alter table dvb_bat
    add name VARCHAR(127) null;

alter table dvb_bat
    add uuid varchar(37) null;

create table dvb_bat_country_availability
(
    id           int                                 not null,
    country      varchar(3)                          not null,
    availability bool                                not null,
    dateadded    TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_bat_country_availability_pk
        primary key (id, country),
    constraint dvb_bat_country_availability_dvb_bat_id_fk
        foreign key (id) references dvb_bat (id)
);

alter table dvb_bat
    add private_dat_specifier bigint null;

alter table dvb_bat
    add uri_linkage_type tinyint null;

alter table dvb_bat
    add url varchar(127) null;

alter table dvb_bat
    add min_polling_interval int null;

create table dvb_bat_multilingual_bouquet_name
(
    id        int                                 not null
        primary key,
    lang      varchar(3)                          not null,
    name      varchar(127)                        not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_bat_multilingual_bouquet_name_dvb_bat_id_fk
        foreign key (id) references dvb_bat (id)
);
alter table dvb_bat
    add control_remote_access_over_internet int null;

alter table dvb_bat
    add do_not_apply_revocation bool null;

alter table dvb_bat
    add do_not_scramble bool null;

create table teletext_page_cache
(
    nid       int                                     not null,
    tsid      int                                     not null,
    progno    int                                     not null,
    magazine  int                                     not null,
    timestamp TIMESTAMP default '0000-00-00 00:00:00' not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP     not null,
    constraint teletext_page_cache_pk
        primary key (nid, tsid, progno, magazine, timestamp)
);

create table dsmcc_blacklist
(
    network_id          int                                 not null,
    transport_stream_id int                                 not null,
    pid                 int                                 not null,
    module_id           int                                 not null,
    module_version      smallint                            not null,
    dateadded           TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dsmcc_blacklist_pk
        primary key (network_id, transport_stream_id, pid, module_id, module_version)
);

create table dvb_tot
(
    nid         int                                     not null,
    tsid        int                                     not null,
    utc         datetime  default '0000-00-00 00:00:00' not null,
    countrycode varchar(3)                              not null,
    dateadded   TIMESTAMP default CURRENT_TIMESTAMP     not null,
    constraint dvb_tot_pk
        primary key (nid, tsid, countrycode)
);

alter table dvb_tot
    add local_time_offset int null;

alter table dvb_tot
    add time_of_change datetime null;

alter table dvb_tot
    add next_time_offset int null;

alter table dvb_tot
    add country_region_id int not null after countrycode;

alter table dvb_tot
    modify dateadded timestamp default current_timestamp() not null after next_time_offset;

alter table dvb_tot
    add local_time_offset_polarity bool not null after country_region_id;

alter table dvb_tot
    modify local_time_offset int not null;

alter table dvb_tot
    modify time_of_change datetime not null;

alter table dvb_tot
    modify next_time_offset int not null;

create index dvb_eit_onid_tsid_service_id_index
    on dvb_eit (onid, tsid, service_id);

alter table dvb_pmt_streams_teletext
    add ordinal int default 0 not null after elementary_pid;

alter table dvb_pmt_streams_teletext
    drop foreign key dvb_pmt_streams_teletext_dvb_pmt_streams_onid_tsid_elementary_fk;

alter table dvb_pmt_streams_teletext
    drop primary key;

alter table dvb_pmt_streams_teletext
    add constraint dvb_pmt_streams_teletext_pk
        primary key (onid, tsid, elementary_pid, ordinal);

alter table dvb_pmt_streams_teletext
    add constraint dvb_pmt_streams_teletext_dvb_pmt_streams_onid_tsid_elementary_fk
        foreign key (onid, tsid, elementary_pid) references dvb_pmt_streams (onid, tsid, elementary_pid);

create table dvb_ait
(
    org_id    int                                 not null,
    app_id    int                                 not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_ait_pk
        primary key (org_id, app_id)
);

INSERT INTO dsmcc_blacklist (network_id, transport_stream_id, pid, module_id, module_version)
VALUES
(318,1300,3018,9729,138),
(318,1300,3025,4660,16),
(318,1300,3026,4660,32),
(318,1300,7891,4660,85),
(318,1300,7893,4660,74),
(318,12400,8001,0,1),
(318,12400,8001,1,1),
(318,12400,8001,2,1),
(318,12400,8001,3,1),
(318,12400,8001,4,1),
(318,12400,8001,5,1),
(318,12400,8001,6,1),
(318,12400,8001,7,1),
(318,12400,8001,8,1),
(318,12400,8001,9,1),
(318,12400,8001,10,1),
(318,12400,8001,11,1),
(318,12400,8001,12,1),
(318,12400,8001,13,1),
(318,12400,8001,14,1),
(318,12400,8001,15,1),
(318,12400,8001,16,1),
(318,12400,8001,17,1),
(318,12400,8001,18,1),
(318,12400,8001,19,1),
(318,12400,8001,20,1),
(318,12400,8001,21,1),
(318,12400,8001,22,1),
(318,12400,8001,23,1),
(318,12400,8001,24,1),
(318,12400,8001,25,1),
(318,12400,8001,26,1),
(318,12400,8001,27,1),
(318,12400,8001,28,1),
(318,12400,8001,29,1),
(318,12400,8001,30,1),
(318,12400,8001,31,1),
(318,12400,8001,32,1),
(318,12400,8001,33,1),
(318,12400,8001,34,1),
(318,12400,8001,35,1),
(318,12400,8001,36,1),
(318,12400,8001,37,1),
(318,12400,8001,38,1),
(318,12400,8002,0,1),
(318,12400,8002,1,1),
(318,12400,8002,2,1),
(318,12400,8002,3,1),
(318,12400,8002,4,1),
(318,12400,8002,5,1),
(318,12400,8002,6,1),
(318,12400,8002,7,1),
(318,12400,8002,8,1),
(318,12400,8002,9,1),
(318,12400,8002,10,1),
(318,12400,8002,11,1),
(318,12400,8002,12,1),
(318,12400,8002,13,1),
(318,12400,8002,14,1),
(318,12400,8002,15,1),
(318,12400,8002,16,1),
(318,12400,8002,17,1),
(318,12400,8002,18,1),
(318,12400,8002,19,1),
(318,12400,8002,20,1),
(318,12400,8002,21,1),
(318,12400,8002,22,1),
(318,12400,8002,23,1),
(318,12400,8002,24,1),
(318,12400,8002,25,1),
(318,12400,8002,26,1),
(318,12400,8002,27,1),
(318,12400,8002,28,1),
(318,12400,8002,29,1),
(318,12400,8002,30,1),
(318,12400,8002,31,1),
(318,12400,8002,32,1),
(318,12400,8002,33,1),
(318,12400,8002,34,1),
(318,12400,8002,35,1),
(318,12400,8002,36,1),
(318,12400,8002,37,1),
(318,12400,8002,38,1),
(113,7400,8170,512,0),
(113,7400,8171,0,1),
(113,7400,8172,0,1),
(113,7400,8173,0,1),
(318,11000,3019,4660,121)

alter table dvb_ait
    add app_control_code tinyint not null;

create table dvb_ait_application_profiles
(
    org_id      int                                 not null,
    app_id      int                                 not null,
    app_profile int                                 not null,
    major       tinyint                             not null,
    minor       tinyint                             not null,
    micro       tinyint                             not null,
    dateadded   TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_ait_application_profile_pk
        primary key (org_id, app_id, app_profile),
    constraint dvb_ait_application_profile_dvb_ait_org_id_app_id_fk
        foreign key (org_id, app_id) references dvb_ait (org_id, app_id)
);

alter table dvb_ait
    add app_priority tinyint null;

alter table dvb_ait
    add service_bound_flag bool null;

alter table dvb_ait
    add transport_protocol_label tinyblob null;

alter table dvb_ait
    add visibility int null;

create table dvb_ait_application_names
(
    org_id    int                                 not null,
    app_id    int                                 not null,
    lang      varchar(3)                          not null,
    name      varchar(128)                        not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_ait_application_names_pk
        primary key (org_id, app_id, lang),
    constraint dvb_ait_application_names_dvb_ait_org_id_app_id_fk
        foreign key (org_id, app_id) references dvb_ait (org_id, app_id)
);

alter table dvb_ait
    add initial_path varchar(127) null;

create table dvb_ait_boundary_extensions
(
    org_id    int                                 not null,
    app_id    int                                 not null,
    extension varchar(128)                        not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_ait_boundary_extensions_pk
        primary key (org_id, app_id, extension),
    constraint dvb_ait_boundary_extensions_dvb_ait_org_id_app_id_fk
        foreign key (org_id, app_id) references dvb_ait (org_id, app_id)
);

alter table dvb_ait
    add app_usage_code tinyint null;

alter table dvb_ait
    add jvm_arguments mediumtext null;

alter table dvb_ait
    add jvm_base_directory varchar(127) null;

alter table dvb_ait
    add jvm_class_path_extension varchar(127) null;

alter table dvb_ait
    add jvm_initial_class varchar(127) null;

alter table dvb_ait
    add version bigint null;

alter table dvb_ait
    add is_launchable_from_older_version bool null;

alter table dvb_ait
    add launchable_completely_from_cache bool null;

alter table dvb_ait
    add not_launchable_from_broadcast bool null;

alter table dvb_ait
    add application_storage_priority tinyint null;

alter table dvb_ait
    add storage_property tinyint null;

create table dvb_ait_external_authorization
(
    org_id       int                                 not null,
    app_id       int                                 not null,
    ext_org_id   int                                 not null,
    ext_app_id   int                                 not null,
    app_priority smallint                            not null,
    dateadded    TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_ait_external_authorization_pk
        primary key (org_id, app_id, ext_org_id, ext_app_id),
    constraint dvb_ait_external_authorization_dvb_ait_org_id_app_id_fk
        foreign key (org_id, app_id) references dvb_ait (org_id, app_id)
);

alter table dvb_ait
    add auto_select bool null;

alter table dvb_ait
    add service_id bigint null;

alter table dvb_ait
    add service_name varchar(127) null;

alter table dvb_ait
    add version_number bigint null;

alter table dvb_ait
    add launch_order tinyint null;

alter table dvb_ait
    add storage_priority int null;

alter table dvb_ait
    add ip_connection_required bool null;

create table dsmcc_events
(
    timestamp datetime not null,
    cnid      int      not null,
    ctsid     int      not null,
    progno    int      not null,
    pid       int      not null,
    constraint dsmcc_events_pk
        primary key (timestamp, cnid, ctsid, pid)
);

alter table dsmcc_events
    add event_id int not null;

alter table dsmcc_events
    add npt_event_seconds bigint not null;

alter table dsmcc_events
    add npt_event_microseconds int not null;

alter table dsmcc_events
    add private_data tinyint null;

alter table dsmcc_events
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

alter table dsmcc_events
    modify private_data tinyblob null;

alter table dvb_eit
    modify event_name varchar(255) null;

alter table teletext_page_cache
    add constraint teletext_page_cache_pk
        primary key (nid, tsid, progno, magazine, timestamp);

alter table dvb_pmt_streams_applications
    drop foreign key dvb_pmt_streams_applications_dvb_pmt_streams_onid_tsid_fk;

alter table dvb_pmt_streams_applications
    drop primary key;

alter table dvb_pmt_streams_applications
    add primary key (onid, tsid, elementary_pid, application_type, ait_version_number);

alter table dvb_pmt_streams_applications
    add constraint dvb_pmt_streams_applications_dvb_pmt_streams_onid_tsid_fk
        foreign key (onid, tsid, elementary_pid) references dvb_pmt_streams (onid, tsid, elementary_pid);

alter table dvb_eit_content
    modify r smallint not null;

create table dvb_unt
(
    action_type       tinyint                             not null,
    oui_hash          smallint                             not null,
    oui               varchar(8)                          not null,
    processing_order  tinyint                             not null,
    data_broadcast_id int                                 null,
    association_tag   int                                 null,
    private_data      tinyint                             null,
    update_flag       int                                 null,
    update_method     int                                 null,
    update_priority   int                                 null,
    dateadded         TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_pk
        primary key (action_type, oui_hash, oui, processing_order)
);

create table dvb_unt_compatibility
(
    action_type      tinyint    not null,
    oui_hash         smallint    not null,
    oui              varchar(8) not null,
    processing_order tinyint    not null,
    descriptor_type  tinyint    not null,
    private_data     tinyblob   null,
    specifier_type   tinyint    null,
    specifier_data   varchar(8) null,
    model            int        null,
    version          int        null,
    constraint dvb_unt_compatibility_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type),
    constraint dvb_unt_compatibility_dvb_unt_action_type_oui_hash_oui_fk
        foreign key (action_type, oui_hash, oui, processing_order) references dvb_unt (action_type, oui_hash, oui, processing_order)
);

alter table dvb_unt_compatibility
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP null;

create table dvb_unt_compatibility_platform
(
    action_type           tinyint      null,
    oui_hash              smallint      null,
    oui                   varchar(8)   null,
    processing_order      tinyint      null,
    descriptor_type       int          null,
    platform_type_bitmask int          null comment 'Generated by Skyscraper on-the-fly, in order to differentiate between platforms.',
    update_flag           int          null,
    update_method         int          null,
    update_priority       int          null,
    data_broadcast_id     int          null,
    association_tag       int          null,
    private_data          tinyblob     null,
    smart_card_number     varchar(128) null,
    super_ca_system_id    bigint       null,
    serial_data           tinyblob     null,
    mac_address_mask      int          null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform
    add constraint dvb_unt_compatibility_platform_dvb_unt_compatibility_action_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type) references dvb_unt_compatibility (action_type, oui_hash, oui, processing_order, descriptor_type);

create table dvb_unt_compatibility_platform_mac_address_matches
(
    action_type           tinyint                             not null,
    oui_hash              smallint                             not null,
    oui                   varchar(8)                          not null,
    processing_order      tinyint                             not null,
    descriptor_type       int                                 not null,
    platform_type_bitmask int                                 not null,
    mac_match                 varchar(17)                     not null,
    dateadded             TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop primary key;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask, mac_match);

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type) references dvb_unt_compatibility_platform (action_type);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash) references dvb_unt_compatibility_platform (action_type, oui_hash);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui) references dvb_unt_compatibility_platform (action_type, oui_hash, oui);

alter table dvb_unt_compatibility_platform_mac_address_matches
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type,
                     platform_type_bitmask) references dvb_unt_compatibility_platform (action_type, oui_hash, oui,
                                                                                       processing_order,
                                                                                       descriptor_type,
                                                                                       platform_type_bitmask);

alter table dvb_unt_compatibility_platform
    add subgroup_tag tinyblob null;

alter table dvb_unt_compatibility_platform
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

create table dvb_unt
(
    action_type       tinyint                             not null,
    oui_hash          smallint                             not null,
    oui               varchar(8)                          not null,
    processing_order  tinyint                             not null,
    data_broadcast_id int                                 null,
    association_tag   int                                 null,
    private_data      tinyint                             null,
    update_flag       int                                 null,
    update_method     int                                 null,
    update_priority   int                                 null,
    dateadded         TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_pk
        primary key (action_type, oui_hash, oui, processing_order)
);

create table dvb_unt_compatibility
(
    action_type      tinyint    not null,
    oui_hash         smallint    not null,
    oui              varchar(8) not null,
    processing_order tinyint    not null,
    descriptor_type  tinyint    not null,
    private_data     tinyblob   null,
    specifier_type   tinyint    null,
    specifier_data   varchar(8) null,
    model            int        null,
    version          int        null,
    constraint dvb_unt_compatibility_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type),
    constraint dvb_unt_compatibility_dvb_unt_action_type_oui_hash_oui_fk
        foreign key (action_type, oui_hash, oui, processing_order) references dvb_unt (action_type, oui_hash, oui, processing_order)
);

alter table dvb_unt_compatibility
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP null;

create table dvb_unt_compatibility_platform
(
    action_type           tinyint      null,
    oui_hash              smallint      null,
    oui                   varchar(8)   null,
    processing_order      tinyint      null,
    descriptor_type       int          null,
    platform_type_bitmask int          null comment 'Generated by Skyscraper on-the-fly, in order to differentiate between platforms.',
    update_flag           int          null,
    update_method         int          null,
    update_priority       int          null,
    data_broadcast_id     int          null,
    association_tag       int          null,
    private_data          tinyblob     null,
    smart_card_number     varchar(128) null,
    super_ca_system_id    bigint       null,
    serial_data           tinyblob     null,
    mac_address_mask      int          null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform
    add constraint dvb_unt_compatibility_platform_dvb_unt_compatibility_action_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type) references dvb_unt_compatibility (action_type, oui_hash, oui, processing_order, descriptor_type);

create table dvb_unt_compatibility_platform_mac_address_matches
(
    action_type           tinyint                             not null,
    oui_hash              smallint                             not null,
    oui                   varchar(8)                          not null,
    processing_order      tinyint                             not null,
    descriptor_type       int                                 not null,
    platform_type_bitmask int                                 not null,
    mac_match                 varchar(17)                     not null,
    dateadded             TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop primary key;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask, mac_match);

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type) references dvb_unt_compatibility_platform (action_type);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash) references dvb_unt_compatibility_platform (action_type, oui_hash);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui) references dvb_unt_compatibility_platform (action_type, oui_hash, oui);

alter table dvb_unt_compatibility_platform_mac_address_matches
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type,
                     platform_type_bitmask) references dvb_unt_compatibility_platform (action_type, oui_hash, oui,
                                                                                       processing_order,
                                                                                       descriptor_type,
                                                                                       platform_type_bitmask);

alter table dvb_unt_compatibility_platform
    add subgroup_tag tinyblob null;

alter table dvb_unt_compatibility_platform
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

create table dvb_unt
(
    action_type       tinyint                             not null,
    oui_hash          smallint                             not null,
    oui               varchar(8)                          not null,
    processing_order  tinyint                             not null,
    data_broadcast_id int                                 null,
    association_tag   int                                 null,
    private_data      tinyint                             null,
    update_flag       int                                 null,
    update_method     int                                 null,
    update_priority   int                                 null,
    dateadded         TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_pk
        primary key (action_type, oui_hash, oui, processing_order)
);

create table dvb_unt_compatibility
(
    action_type      tinyint    not null,
    oui_hash         smallint    not null,
    oui              varchar(8) not null,
    processing_order tinyint    not null,
    descriptor_type  tinyint    not null,
    private_data     tinyblob   null,
    specifier_type   tinyint    null,
    specifier_data   varchar(8) null,
    model            int        null,
    version          int        null,
    constraint dvb_unt_compatibility_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type),
    constraint dvb_unt_compatibility_dvb_unt_action_type_oui_hash_oui_fk
        foreign key (action_type, oui_hash, oui, processing_order) references dvb_unt (action_type, oui_hash, oui, processing_order)
);

alter table dvb_unt_compatibility
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP null;

create table dvb_unt_compatibility_platform
(
    action_type           tinyint      null,
    oui_hash              smallint      null,
    oui                   varchar(8)   null,
    processing_order      tinyint      null,
    descriptor_type       int          null,
    platform_type_bitmask int          null comment 'Generated by Skyscraper on-the-fly, in order to differentiate between platforms.',
    update_flag           int          null,
    update_method         int          null,
    update_priority       int          null,
    data_broadcast_id     int          null,
    association_tag       int          null,
    private_data          tinyblob     null,
    smart_card_number     varchar(128) null,
    super_ca_system_id    bigint       null,
    serial_data           tinyblob     null,
    mac_address_mask      int          null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform
    add constraint dvb_unt_compatibility_platform_dvb_unt_compatibility_action_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type) references dvb_unt_compatibility (action_type, oui_hash, oui, processing_order, descriptor_type);

create table dvb_unt_compatibility_platform_mac_address_matches
(
    action_type           tinyint                             not null,
    oui_hash              smallint                             not null,
    oui                   varchar(8)                          not null,
    processing_order      tinyint                             not null,
    descriptor_type       int                                 not null,
    platform_type_bitmask int                                 not null,
    mac_match                 varchar(17)                     not null,
    dateadded             TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop primary key;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask, mac_match);

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type) references dvb_unt_compatibility_platform (action_type);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash) references dvb_unt_compatibility_platform (action_type, oui_hash);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui) references dvb_unt_compatibility_platform (action_type, oui_hash, oui);

alter table dvb_unt_compatibility_platform_mac_address_matches
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type,
                     platform_type_bitmask) references dvb_unt_compatibility_platform (action_type, oui_hash, oui,
                                                                                       processing_order,
                                                                                       descriptor_type,
                                                                                       platform_type_bitmask);

alter table dvb_unt_compatibility_platform
    add subgroup_tag tinyblob null;

alter table dvb_unt_compatibility_platform
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

create table dvb_unt
(
    action_type       tinyint                             not null,
    oui_hash          smallint                             not null,
    oui               varchar(8)                          not null,
    processing_order  tinyint                             not null,
    data_broadcast_id int                                 null,
    association_tag   int                                 null,
    private_data      tinyint                             null,
    update_flag       int                                 null,
    update_method     int                                 null,
    update_priority   int                                 null,
    dateadded         TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_pk
        primary key (action_type, oui_hash, oui, processing_order)
);

create table dvb_unt_compatibility
(
    action_type      tinyint    not null,
    oui_hash         smallint    not null,
    oui              varchar(8) not null,
    processing_order tinyint    not null,
    descriptor_type  tinyint    not null,
    private_data     tinyblob   null,
    specifier_type   tinyint    null,
    specifier_data   varchar(8) null,
    model            int        null,
    version          int        null,
    constraint dvb_unt_compatibility_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type),
    constraint dvb_unt_compatibility_dvb_unt_action_type_oui_hash_oui_fk
        foreign key (action_type, oui_hash, oui, processing_order) references dvb_unt (action_type, oui_hash, oui, processing_order)
);

alter table dvb_unt_compatibility
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP null;

create table dvb_unt_compatibility_platform
(
    action_type           tinyint      null,
    oui_hash              smallint      null,
    oui                   varchar(8)   null,
    processing_order      tinyint      null,
    descriptor_type       int          null,
    platform_type_bitmask int          null comment 'Generated by Skyscraper on-the-fly, in order to differentiate between platforms.',
    update_flag           int          null,
    update_method         int          null,
    update_priority       int          null,
    data_broadcast_id     int          null,
    association_tag       int          null,
    private_data          tinyblob     null,
    smart_card_number     varchar(128) null,
    super_ca_system_id    bigint       null,
    serial_data           tinyblob     null,
    mac_address_mask      int          null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform
    add constraint dvb_unt_compatibility_platform_dvb_unt_compatibility_action_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type) references dvb_unt_compatibility (action_type, oui_hash, oui, processing_order, descriptor_type);

create table dvb_unt_compatibility_platform_mac_address_matches
(
    action_type           tinyint                             not null,
    oui_hash              smallint                             not null,
    oui                   varchar(8)                          not null,
    processing_order      tinyint                             not null,
    descriptor_type       int                                 not null,
    platform_type_bitmask int                                 not null,
    mac_match                 varchar(17)                     not null,
    dateadded             TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop primary key;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask, mac_match);

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type) references dvb_unt_compatibility_platform (action_type);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash) references dvb_unt_compatibility_platform (action_type, oui_hash);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui) references dvb_unt_compatibility_platform (action_type, oui_hash, oui);

alter table dvb_unt_compatibility_platform_mac_address_matches
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type,
                     platform_type_bitmask) references dvb_unt_compatibility_platform (action_type, oui_hash, oui,
                                                                                       processing_order,
                                                                                       descriptor_type,
                                                                                       platform_type_bitmask);

alter table dvb_unt_compatibility_platform
    add subgroup_tag tinyblob null;

alter table dvb_unt_compatibility_platform
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

create table dvb_unt
(
    action_type       tinyint                             not null,
    oui_hash          smallint                             not null,
    oui               varchar(8)                          not null,
    processing_order  tinyint                             not null,
    data_broadcast_id int                                 null,
    association_tag   int                                 null,
    private_data      tinyint                             null,
    update_flag       int                                 null,
    update_method     int                                 null,
    update_priority   int                                 null,
    dateadded         TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_pk
        primary key (action_type, oui_hash, oui, processing_order)
);

create table dvb_unt_compatibility
(
    action_type      tinyint    not null,
    oui_hash         smallint    not null,
    oui              varchar(8) not null,
    processing_order tinyint    not null,
    descriptor_type  tinyint    not null,
    private_data     tinyblob   null,
    specifier_type   tinyint    null,
    specifier_data   varchar(8) null,
    model            int        null,
    version          int        null,
    constraint dvb_unt_compatibility_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type),
    constraint dvb_unt_compatibility_dvb_unt_action_type_oui_hash_oui_fk
        foreign key (action_type, oui_hash, oui, processing_order) references dvb_unt (action_type, oui_hash, oui, processing_order)
);

alter table dvb_unt_compatibility
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP null;

create table dvb_unt_compatibility_platform
(
    action_type           tinyint      null,
    oui_hash              smallint      null,
    oui                   varchar(8)   null,
    processing_order      tinyint      null,
    descriptor_type       int          null,
    platform_type_bitmask int          null comment 'Generated by Skyscraper on-the-fly, in order to differentiate between platforms.',
    update_flag           int          null,
    update_method         int          null,
    update_priority       int          null,
    data_broadcast_id     int          null,
    association_tag       int          null,
    private_data          tinyblob     null,
    smart_card_number     varchar(128) null,
    super_ca_system_id    bigint       null,
    serial_data           tinyblob     null,
    mac_address_mask      int          null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform
    add constraint dvb_unt_compatibility_platform_dvb_unt_compatibility_action_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type) references dvb_unt_compatibility (action_type, oui_hash, oui, processing_order, descriptor_type);

create table dvb_unt_compatibility_platform_mac_address_matches
(
    action_type           tinyint                             not null,
    oui_hash              smallint                             not null,
    oui                   varchar(8)                          not null,
    processing_order      tinyint                             not null,
    descriptor_type       int                                 not null,
    platform_type_bitmask int                                 not null,
    mac_match                 varchar(17)                     not null,
    dateadded             TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop primary key;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask, mac_match);

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type) references dvb_unt_compatibility_platform (action_type);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash) references dvb_unt_compatibility_platform (action_type, oui_hash);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui) references dvb_unt_compatibility_platform (action_type, oui_hash, oui);

alter table dvb_unt_compatibility_platform_mac_address_matches
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type,
                     platform_type_bitmask) references dvb_unt_compatibility_platform (action_type, oui_hash, oui,
                                                                                       processing_order,
                                                                                       descriptor_type,
                                                                                       platform_type_bitmask);

alter table dvb_unt_compatibility_platform
    add subgroup_tag tinyblob null;

alter table dvb_unt_compatibility_platform
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

create table dvb_unt
(
    action_type       tinyint                             not null,
    oui_hash          smallint                             not null,
    oui               varchar(8)                          not null,
    processing_order  tinyint                             not null,
    data_broadcast_id int                                 null,
    association_tag   int                                 null,
    private_data      tinyint                             null,
    update_flag       int                                 null,
    update_method     int                                 null,
    update_priority   int                                 null,
    dateadded         TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_pk
        primary key (action_type, oui_hash, oui, processing_order)
);

create table dvb_unt_compatibility
(
    action_type      tinyint    not null,
    oui_hash         smallint    not null,
    oui              varchar(8) not null,
    processing_order tinyint    not null,
    descriptor_type  tinyint    not null,
    private_data     tinyblob   null,
    specifier_type   tinyint    null,
    specifier_data   varchar(8) null,
    model            int        null,
    version          int        null,
    constraint dvb_unt_compatibility_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type),
    constraint dvb_unt_compatibility_dvb_unt_action_type_oui_hash_oui_fk
        foreign key (action_type, oui_hash, oui, processing_order) references dvb_unt (action_type, oui_hash, oui, processing_order)
);

alter table dvb_unt_compatibility
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP null;

create table dvb_unt_compatibility_platform
(
    action_type           tinyint      null,
    oui_hash              smallint      null,
    oui                   varchar(8)   null,
    processing_order      tinyint      null,
    descriptor_type       int          null,
    platform_type_bitmask int          null comment 'Generated by Skyscraper on-the-fly, in order to differentiate between platforms.',
    update_flag           int          null,
    update_method         int          null,
    update_priority       int          null,
    data_broadcast_id     int          null,
    association_tag       int          null,
    private_data          tinyblob     null,
    smart_card_number     varchar(128) null,
    super_ca_system_id    bigint       null,
    serial_data           tinyblob     null,
    mac_address_mask      int          null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform
    add constraint dvb_unt_compatibility_platform_dvb_unt_compatibility_action_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type) references dvb_unt_compatibility (action_type, oui_hash, oui, processing_order, descriptor_type);

create table dvb_unt_compatibility_platform_mac_address_matches
(
    action_type           tinyint                             not null,
    oui_hash              smallint                             not null,
    oui                   varchar(8)                          not null,
    processing_order      tinyint                             not null,
    descriptor_type       int                                 not null,
    platform_type_bitmask int                                 not null,
    mac_match                 varchar(17)                     not null,
    dateadded             TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_unt_compatibility_platform_pk
        primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask)
);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop primary key;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add primary key (action_type, oui_hash, oui, processing_order, descriptor_type, platform_type_bitmask, mac_match);

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type) references dvb_unt_compatibility_platform (action_type);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash) references dvb_unt_compatibility_platform (action_type, oui_hash);

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui) references dvb_unt_compatibility_platform (action_type, oui_hash, oui);

alter table dvb_unt_compatibility_platform_mac_address_matches
    modify descriptor_type tinyint not null;

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    add constraint dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk
        foreign key (action_type, oui_hash, oui, processing_order, descriptor_type,
                     platform_type_bitmask) references dvb_unt_compatibility_platform (action_type, oui_hash, oui,
                                                                                       processing_order,
                                                                                       descriptor_type,
                                                                                       platform_type_bitmask);

alter table dvb_unt_compatibility_platform
    add subgroup_tag tinyblob null;

alter table dvb_unt_compatibility_platform
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

alter table dvb_pmt
    modify iod_graphics_profile_level_indication smallint null;

alter table dvb_pmt
    modify iod_visual_profile_level_indication smallint null;

alter table dvb_pmt
    modify iod_audio_profile_level_indication smallint null;

alter table dvb_pmt
    modify iod_scene_profile_level_indication smallint null;

alter table dvb_pmt
    modify iod_od_profile_level_indication smallint null;

alter table dvb_eit_component
    modify text varchar(127) null;

alter table dvb_linkages
    add bouquet_id int null;

alter table dvb_linkages
    modify handover_origin_type tinyint(1) null after bouquet_id;

alter table dvb_linkages
    add original_network_id int null after handover_type;

alter table dvb_linkages
    add transport_stream_id int null after original_network_id;

alter table dvb_linkages
    modify handover_initial_service_id int null after handover_origin_type;

alter table dvb_linkages
    modify handover_network_id int null after handover_initial_service_id;

alter table dvb_linkages
    add service_id int null after transport_stream_id;

alter table dvb_linkages
    modify original_network_id int not null;

alter table dvb_linkages
    modify transport_stream_id int not null;

alter table dvb_linkages
    modify service_id int not null;

alter table dvb_linkages
    modify handover_type int null;

alter table dvb_linkages_ssu
    drop foreign key dvb_linkages_ssu_dvb_linkages_uuid_fk;

alter table dvb_linkages_ipmac_names
    drop foreign key dvb_linkages_ipmac_names_dvb_linkages_uuid_fk;

alter table dvb_linkages_ipmac
    drop foreign key dvb_linkages_ipmac_dvb_linkages_uuid_fk;

alter table dvb_linkages_extended_event_linkages
    drop foreign key dvb_linkages_extended_event_linkages_dvb_linkages_uuid_fk;

alter table dvb_linkages
    drop primary key;

alter table dvb_linkages
    add primary key (uuid, linkage_type, original_network_id, transport_stream_id, service_id);

alter table dvb_linkages_extended_event_linkages
    add constraint dvb_linkages_extended_event_linkages_dvb_linkages_uuid_fk
        foreign key (uuid) references dvb_linkages (uuid);

alter table dvb_linkages_ipmac
    add constraint dvb_linkages_ipmac_dvb_linkages_uuid_fk
        foreign key (uuid) references dvb_linkages (uuid);

alter table dvb_linkages_ipmac_names
    add constraint dvb_linkages_ipmac_names_dvb_linkages_ipmac_uuid_id_fk
        foreign key (uuid, id) references dvb_linkages_ipmac (uuid, id);

alter table dvb_linkages_ssu
    add constraint dvb_linkages_ssu_dvb_linkages_uuid_fk
        foreign key (uuid) references dvb_linkages (uuid);

create table dvb_bat_transport_stream
(
    bouquet_id          int                                 not null,
    original_network_id int                                 null,
    transport_stream_id int                                 not null,
    dateadded           TIMESTAMP default CURRENT_TIMESTAMP not null
);

create table dvb_bat_transport_stream_services
(
    bouquet_id          int                                 not null,
    original_network_id int                                 not null,
    transport_stream_id int                                 not null,
    service_id          int                                 not null,
    service_type        int                                 not null,
    dateadded           TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_bat_transport_stream_services_pk
        primary key (bouquet_id, original_network_id, transport_stream_id, service_id)
);

alter table dvb_bat_transport_stream
    add constraint dvb_bat_transport_stream_pk
        primary key (bouquet_id, original_network_id, transport_stream_id);

alter table dvb_bat_transport_stream_services
    add constraint dvb_bat_transport_stream_services_dvb_bat_transport_stream_fk
        foreign key (bouquet_id, original_network_id, transport_stream_id) references dvb_bat_transport_stream (bouquet_id, original_network_id, transport_stream_id);

rename table dvb_bat_transport_stream_services to dvb_bat_transport_stream_service_list;

alter table dvb_bat_transport_stream
    add private_data_specifier bigint null;

create table dvb_bat_transport_stream_country_availability
(
    bouquet_id          int                                 not null,
    original_network_id int                                 not null,
    transport_stream_id int                                 not null,
    country             varchar(3)                          not null,
    availability        bool                                not null,
    dateadded           TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_bat_transport_stream_country_availability_pk
        primary key (bouquet_id, original_network_id, transport_stream_id, country),
    constraint dvb_bat_transport_stream_country_availability_dvb_bat_fk
        foreign key (bouquet_id, original_network_id, transport_stream_id) references dvb_bat_transport_stream (bouquet_id, original_network_id, transport_stream_id)
);

alter table dvb_bat_transport_stream
    add default_authority varchar(128) null;

alter table skyscraper_imported_streams
    add debugger bool not null;

alter table skyscraper_imported_streams
    add time_taken int not null;


alter table dvb_ait
    modify app_priority smallint null;

alter table dvb_ait_transport_protocols
    modify component_tag smallint null;

alter table dvb_unt_compatibility_platform
    drop foreign key dvb_unt_compatibility_platform_dvb_unt_compatibility_action_fk;

alter table dvb_unt_compatibility_platform_mac_address_matches
    drop foreign key dvb_unt_compatibility_platform_mac_address_matches_dvb_unt_fk;

alter table dvb_unt_compatibility
    modify descriptor_type smallint not null;

alter table dvb_unt_compatibility_platform
    modify descriptor_type smallint not null;

alter table dvb_linkages
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

create table scte35_splice
(
    cnid            int                                 not null,
    ctsid           int                                 not null,
    progno          int                                 not null,
    splice_event_id bigint                              not null,
    dateadded       TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint sct35_splice_pk
        primary key (cnid, ctsid, progno, splice_event_id)
);

alter table scte35_splice
    add splice_event_cancel_indicator bool null;

alter table scte35_splice
    add avails_expected smallint null;

alter table scte35_splice
    add avail_num smallint null;

alter table scte35_splice
    add unique_program_id int null;

alter table scte35_splice
    add duration bigint null;

alter table scte35_splice
    add duration_auto_return bool null;

create table scte35_splice_components
(
    cnid            int                                 not null,
    ctsid           int                                 not null,
    progno          int                                 not null,
    splice_event_id bigint                              not null,
    k               smallint                            not null,
    v               bigint                              null,
    dateadded       TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint table_name_pk
        primary key (cnid, ctsid, progno, splice_event_id, k),
    constraint scte35_splice_components_scte35_splice_cnid_ctsid_progno_fk
        foreign key (cnid, ctsid, progno, splice_event_id) references scte35_splice (cnid, ctsid, progno, splice_event_id)
);

alter table scte35_splice
    add splice_time bigint null after splice_event_id;

alter table scte35_splice
    add splice_immediate_flag bool null;

alter table scte35_splice
    add duration_flag bool null;

alter table scte35_splice
    add program_splice_flag bool null;

alter table scte35_splice
    add out_of_network_indicator bool null;

alter table scte35_splice
    add provider_avail_id bigint null;

alter table scte35_splice
    add identifier bigint null;

alter table scte35_splice
    add sub_segments_expected smallint null;

alter table scte35_splice
    add sub_segment_num smallint null;

alter table scte35_splice
    add segments_expected smallint null;

alter table scte35_splice
    add segment_num smallint null;

alter table scte35_splice
    add segmentation_type_id smallint null;

alter table scte35_splice
    add segmentation_upid varchar(16) null;

alter table scte35_splice
    add segmentation_upid_type smallint null;

alter table scte35_splice
    add segmentation_duration bigint null;

create table scte35_splice_segmentation_components
(
    cnid            int                                 not null,
    ctsid           int                                 not null,
    progno          int                                 not null,
    splice_event_id bigint                              not null,
    component_tag   smallint                            not null,
    pts_offset      bigint                              not null,
    dateadded       TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint scte35_splice_segmentation_components_pk
        primary key (cnid, ctsid, progno, splice_event_id, component_tag),
    constraint scte35_splice_segmentation_components_scte35_splice_cnid_fk
        foreign key (cnid, ctsid, progno, splice_event_id) references scte35_splice (cnid, ctsid, progno, splice_event_id)
);

alter table scte35_splice
    add program_segmentation_flag bool null;

alter table scte35_splice
    add segmentation_event_cancel_indicator bool null;

alter table scte35_splice
    add device_restrictions int null;

alter table scte35_splice
    add archive_allowed_flag bool null;

alter table scte35_splice
    add no_regional_blackout_flag bool null;

alter table scte35_splice
    add web_delivery_flag bool null;

alter table scte35_splice
    add segmentation_duration_flag bool null;

alter table scte35_splice
    add segmentation_event_id bigint null;

alter table scte35_splice
    add identifier bigint null;

alter table scte35_splice
    add utc_offset int null;

alter table scte35_splice
    add tai_ns bigint null;

alter table scte35_splice
    add tai_seconds bigint null;

alter table scte35_splice
    add tai_identififer bigint null;

alter table scte35_splice
    add program_segmentation_flag bool null;

alter table scte35_splice
    add segmentation_event_cancel_indicator bool null;

alter table scte35_splice
    add device_restrictions int null;

alter table scte35_splice
    add archive_allowed_flag bool null;

alter table scte35_splice
    add no_regional_blackout_flag bool null;

alter table scte35_splice
    add web_delivery_flag bool null;

alter table scte35_splice
    add segmentation_duration_flag bool null;

alter table scte35_splice
    add segmentation_event_id bigint null;

alter table scte35_splice
    add segmentation_identifier bigint null;

alter table scte35_splice
    add utc_offset int null;

alter table scte35_splice
    add tai_ns bigint null;

alter table scte35_splice
    add tai_seconds bigint null;

alter table scte35_splice
    add tai_identififer bigint null;

create table scte35_time_signal

(
    cnid    int    not null,
    ctsid   int    not null,
    progno  int    not null,
    current int    not null,
    value   bigint null,
    provider_avail_id                   bigint                                null,
    identifier                          bigint                                null,
    sub_segments_expected               smallint                              null,
    sub_segment_num                     smallint                              null,
    segments_expected                   smallint                              null,
    segment_num                         smallint                              null,
    segmentation_type_id                smallint                              null,
    segmentation_upid                   varchar(16)                           null,
    segmentation_upid_type              smallint                              null,
    segmentation_duration               bigint                                null,
    program_segmentation_flag           tinyint(1)                            null,
    segmentation_event_cancel_indicator tinyint(1)                            null,
    device_restrictions                 int                                   null,
    archive_allowed_flag                tinyint(1)                            null,
    no_regional_blackout_flag           tinyint(1)                            null,
    web_delivery_flag                   tinyint(1)                            null,
    segmentation_duration_flag          tinyint(1)                            null,
    segmentation_event_id               bigint                                null,
    segmentation_identifier             bigint                                null,
    utc_offset                          int                                   null,
    tai_ns                              bigint                                null,
    tai_seconds                         bigint                                null,
    tai_identififer                     bigint                                null,
    constraint scte35_time_signal_pk
        primary key (cnid, ctsid, progno)
);

alter table scte35_time_signal
    modify current timestamp not null;

alter table scte35_time_signal
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null after value;

alter table scte35_time_signal
    drop primary key;

alter table scte35_time_signal
    add primary key (cnid, ctsid, progno, current);

alter table dvb_pmt_streams_audio_preselection
    modify component_tags tinyblob null;

alter table dvb_pmt_streams_audio_preselection
    modify future_extension tinyblob null;

create table dvb_tsid
(
    cnid       int                                 not null,
    ctsid      int                                 not null,
    compliance varchar(4)                          not null,
    dateadded  TIMESTAMP default CURRENT_TIMESTAMP not null,
    constraint dvb_tsid_pk
        primary key (cnid, ctsid, compliance)
);

rename table dvb_tsid to dvb_tsdt;

alter table dvb_tsdt
    add station_identification varchar(4) null;

alter table dvb_sdt
    drop column component_tag;

alter table dvb_sdt
    drop column iso_639_language_code;

alter table dvb_sdt
    drop column component_type;

alter table dvb_sdt
    drop column stream_context;

alter table dvb_sdt
    drop column stream_context_ext;

alter table dvb_sdt
    drop column text;

alter table dvb_sdt
    add component_tag tinyint null;

alter table dvb_sdt
    add iso_639_language_code varchar(3) null;

alter table dvb_sdt
    add text tinytext null;

create table dvb_sdt_components
(
    tsid                  int        not null,
    nid                   int        not null,
    service_id            int        not null,
    component_tag         smallint   not null,
    stream_content_ext    tinyint    not null,
    stream_content        tinyint    not null,
    component_type        tinyint    not null,
    iso_639_language_code varchar(3) not null,
    text                  mediumtext not null,
    constraint table_name_pk
        primary key (nid, tsid, service_id, component_tag)
);

alter table dvb_sdt_components
    add constraint dvb_sdt_components_dvb_sdt_tsid_onid_service_id_fk
        foreign key (tsid, nid, service_id) references dvb_sdt (tsid, onid, service_id);

alter table dvb_sdt_components
    add dateadded TIMESTAMP default CURRENT_TIMESTAMP not null;

alter table dvb_sdt_components
    modify text mediumtext null;

alter table dvb_unt
    modify processing_order smallint not null;

alter table dvb_unt
    modify private_data tinyblob null;

alter table dvb_unt_compatibility
    modify processing_order smallint not null;

alter table dvb_unt_compatibility_platform
    modify processing_order smallint not null;

alter table dvb_unt_compatibility_platform
    modify mac_address_mask varchar(17) null;

alter table dvb_unt_compatibility_platform_mac_address_matches
    modify processing_order smallint not null;

create table skyscraper_locations
(
    id        int                                 not null
        primary key,
    lon       double                              not null,
    lat       double                              not null,
    name      VARCHAR(100)                        not null,
    dateadded TIMESTAMP default CURRENT_TIMESTAMP not null
);

alter table skyscraper_locations
    add current bit default false not null;

create unique index skyscraper_locations_current_uindex
    on skyscraper_locations (current);

