AnonymousAnonymous -4 years ago
1167 0

No description

SQL

dump12345

CREATE TABLE airbridge
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(20) NOT NULL,
    parking_id NUMERIC(38) NOT NULL,
    resource_id NUMERIC(38),
    CONSTRAINT airbridge_parking_fk FOREIGN KEY (parking_id) REFERENCES parking (id),
    CONSTRAINT airbridge_resources_fk FOREIGN KEY (resource_id) REFERENCES resources (id)
);
CREATE TABLE aircraft
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    aircraft_type_id NUMERIC(38) NOT NULL,
    bort_number VARCHAR(20),
    aviacompany_id NUMERIC(38) NOT NULL,
    mtow NUMERIC(38),
    is_deleted NUMERIC(38) NOT NULL,
    change_datetime TIMESTAMP,
    composition_id NUMERIC(38),
    max_pass NUMERIC(38),
    CONSTRAINT aircraft_aircraft_type_fk FOREIGN KEY (aircraft_type_id) REFERENCES aircraft_type (id),
    CONSTRAINT aircraft_aircompany_fk FOREIGN KEY (aviacompany_id) REFERENCES aviacompany (id)
);
CREATE UNIQUE INDEX aircraft_index1 ON aircraft (bort_number);
CREATE TABLE aircraft_new
(
    id NUMERIC(38) DEFAULT nextval('aircraft_new_id_seq'::regclass) NOT NULL,
    aircraft_type_id NUMERIC(38) NOT NULL,
    bort_number VARCHAR(20),
    aviacompany_id NUMERIC(38) NOT NULL,
    mtow NUMERIC(38),
    is_deleted NUMERIC(38) NOT NULL,
    change_datetime TIMESTAMP,
    composition_id NUMERIC(38),
    max_pass NUMERIC(38)
);
CREATE TABLE aircraft_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name_ru VARCHAR(50),
    name_en VARCHAR(50),
    iata_code VARCHAR(11),
    icao_code VARCHAR(11),
    length NUMERIC(38),
    width NUMERIC(38),
    sirena_code VARCHAR(11),
    aid NUMERIC(38),
    map_icon_id NUMERIC(38),
    is_deleted NUMERIC(38) NOT NULL,
    icao_class VARCHAR(20),
    diametr NUMERIC(38),
    iata_code_ru VARCHAR(50),
    icao_code_ru VARCHAR(50),
    CONSTRAINT aircraft_type_fk1 FOREIGN KEY (map_icon_id) REFERENCES map_icon (id)
);
CREATE TABLE aircraft_type_copy_nsi
(
    id NUMERIC(38) DEFAULT nextval('aircraft_type_copy_nsi_id_seq'::regclass) NOT NULL,
    name_ru VARCHAR(50),
    name_en VARCHAR(50),
    iata_code VARCHAR(11),
    icao_code VARCHAR(11),
    length NUMERIC(38),
    width NUMERIC(38),
    sirena_code VARCHAR(11),
    aid NUMERIC(38),
    map_icon_id NUMERIC(38),
    is_deleted NUMERIC(38) NOT NULL,
    iata_code_ru VARCHAR(11),
    icao_code_ru VARCHAR(11),
    icao_class VARCHAR(20),
    max_pass NUMERIC(38)
);
CREATE TABLE aircraft_type_reserve_copy
(
    id NUMERIC(38) DEFAULT nextval('aircraft_type_reserve_copy_id_seq'::regclass) NOT NULL,
    name_ru VARCHAR(50),
    name_en VARCHAR(50),
    iata_code VARCHAR(11),
    icao_code VARCHAR(11),
    length NUMERIC(38),
    width NUMERIC(38),
    sirena_code VARCHAR(11),
    aid NUMERIC(38),
    map_icon_id NUMERIC(38),
    is_deleted NUMERIC(38) NOT NULL,
    iata_code_ru VARCHAR(11),
    icao_code_ru VARCHAR(11),
    icao_class VARCHAR(20),
    max_pass NUMERIC(38)
);
CREATE TABLE airport
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    aid NUMERIC(38),
    name_ru VARCHAR(150),
    name_en VARCHAR(150),
    iata_code VARCHAR(11),
    iata_num NUMERIC(38),
    icao_code VARCHAR(11),
    sirena_code VARCHAR(11),
    timezone NUMERIC(38) NOT NULL,
    city_id NUMERIC(38),
    country_code VARCHAR(11),
    country_id NUMERIC(38),
    is_deleted NUMERIC(38) NOT NULL,
    is_rt NUMERIC(38) NOT NULL,
    CONSTRAINT airport_city_fk FOREIGN KEY (city_id) REFERENCES city (id),
    CONSTRAINT airport_country_fk FOREIGN KEY (country_id) REFERENCES country (id)
);
CREATE TABLE api_command
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    api_command_type_id NUMERIC(38) NOT NULL,
    created_at TIMESTAMP NOT NULL,
    received_at TIMESTAMP,
    employee_id NUMERIC(38) NOT NULL,
    CONSTRAINT api_c_api_c_type_fk FOREIGN KEY (api_command_type_id) REFERENCES api_command_type (id),
    CONSTRAINT api_com_emp_fk FOREIGN KEY (employee_id) REFERENCES employee (id)
);
CREATE TABLE api_command_arg
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    api_command_id NUMERIC(38) NOT NULL,
    key VARCHAR(32),
    value VARCHAR(230),
    CONSTRAINT api_com_arg_api_com_fk FOREIGN KEY (api_command_id) REFERENCES api_command (id)
);
CREATE TABLE api_command_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(30)
);
CREATE TABLE available_employee
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    employee_id NUMERIC(38) NOT NULL,
    CONSTRAINT available_employee_employee_fk FOREIGN KEY (employee_id) REFERENCES employee (id)
);
CREATE TABLE aviacompany
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    aid NUMERIC(38),
    iata_code VARCHAR(11),
    icao_code VARCHAR(11),
    sirena_code VARCHAR(11),
    name_ru VARCHAR(150),
    name_en VARCHAR(150),
    contractor_id NUMERIC(38),
    iata_num VARCHAR(11),
    dcs_id NUMERIC(38),
    airbridge NUMERIC(38) NOT NULL,
    name_1c VARCHAR(20),
    is_deleted NUMERIC(38) NOT NULL,
    country_code VARCHAR(11),
    country_id NUMERIC(38),
    aon NUMERIC(38) NOT NULL,
    military NUMERIC(38) NOT NULL,
    CONSTRAINT aviacom_contractor_fk FOREIGN KEY (contractor_id) REFERENCES contractor (id),
    CONSTRAINT aviacom_dcs_fk FOREIGN KEY (dcs_id) REFERENCES dcs (id),
    CONSTRAINT aviaco_country_fk FOREIGN KEY (country_id) REFERENCES country (id)
);
CREATE TABLE aviacompany_aircraft
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    access_datetime TIMESTAMP,
    aircraft_id NUMERIC(38) NOT NULL,
    aviacompany_id NUMERIC(38) NOT NULL,
    CONSTRAINT aviac_aircraft_aircraft_fk FOREIGN KEY (aircraft_id) REFERENCES aircraft (id),
    CONSTRAINT aviac_aircraft_aviac_fk FOREIGN KEY (aviacompany_id) REFERENCES aviacompany (id)
);
CREATE TABLE aviacompany_contractor
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    aviacompany_id NUMERIC(38) NOT NULL,
    job_id NUMERIC(38) NOT NULL,
    employee_position_old_id NUMERIC(38) NOT NULL,
    employee_position_new_id NUMERIC(38) NOT NULL,
    CONSTRAINT table_104_aviacompany_fk FOREIGN KEY (aviacompany_id) REFERENCES aviacompany (id),
    CONSTRAINT table_104_job_fk FOREIGN KEY (job_id) REFERENCES job (id),
    CONSTRAINT table_104_employee_pos_fk FOREIGN KEY (employee_position_old_id) REFERENCES employee_position (id),
    CONSTRAINT avia_contr_empl_position_fk FOREIGN KEY (employee_position_new_id) REFERENCES employee_position (id)
);
CREATE TABLE avto
(
    idmp NUMERIC(38),
    acronym VARCHAR(10)
);
CREATE TABLE baggage
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    flight_id NUMERIC(38),
    container_id NUMERIC(38),
    baggage_type_id NUMERIC(38) NOT NULL,
    weight NUMERIC(10,2) NOT NULL,
    bsm_msg_number NUMERIC(38),
    tag VARCHAR(25) NOT NULL,
    baggage_status_id NUMERIC(38) NOT NULL,
    position NUMERIC(38) NOT NULL,
    date_receive TIMESTAMP,
    date_load TIMESTAMP,
    name VARCHAR(150),
    next_airport VARCHAR(20),
    next_flight VARCHAR(20),
    class VARCHAR,
    seat VARCHAR(6),
    travel_class_id NUMERIC(38),
    comment_text VARCHAR(2048),
    bsm_msg TEXT,
    baggage_number NUMERIC(38),
    source_weight NUMERIC(38),
    date_send TIMESTAMP,
    CONSTRAINT baggage_flight_fk FOREIGN KEY (flight_id) REFERENCES flight (id),
    CONSTRAINT baggage_container_fk FOREIGN KEY (container_id) REFERENCES container (id),
    CONSTRAINT baggage_baggage_type_fk FOREIGN KEY (baggage_type_id) REFERENCES baggage_type (id),
    CONSTRAINT baggage_baggage_status_fk FOREIGN KEY (baggage_status_id) REFERENCES baggage_status (id),
    CONSTRAINT bag_travel_class_fk FOREIGN KEY (travel_class_id) REFERENCES travel_class (id)
);
CREATE INDEX baggage_index4 ON baggage (flight_id, container_id, baggage_type_id, baggage_status_id, position, date_receive);
CREATE INDEX baggage_index2 ON baggage (flight_id, container_id, baggage_status_id);
CREATE INDEX baggage_index3 ON baggage (flight_id, baggage_type_id, baggage_status_id, container_id);
CREATE INDEX baggage_index1 ON baggage (container_id, baggage_status_id);
CREATE INDEX baggage_index6 ON baggage (tag);
CREATE INDEX baggage_index5 ON baggage (date_receive);
CREATE TABLE baggage_status
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(100) NOT NULL
);
CREATE TABLE baggage_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(30) NOT NULL
);
CREATE TABLE city
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name_ru VARCHAR(20) NOT NULL,
    name_en VARCHAR(20),
    country_id NUMERIC(38),
    iata_code VARCHAR(11),
    icao_code VARCHAR(11),
    sirena_code VARCHAR(11),
    time_zone NUMERIC(38) NOT NULL,
    CONSTRAINT city_country_fk FOREIGN KEY (country_id) REFERENCES country (id)
);
CREATE TABLE coef
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    value REAL NOT NULL,
    name VARCHAR(320),
    reverse NUMERIC(1) NOT NULL
);
CREATE TABLE columns
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(30) NOT NULL,
    page_id NUMERIC(38) NOT NULL,
    code VARCHAR(255) NOT NULL,
    CONSTRAINT column_page_fk FOREIGN KEY (page_id) REFERENCES page (id)
);
CREATE TABLE comp
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(150) NOT NULL,
    biz NUMERIC(38) NOT NULL,
    eco NUMERIC(38) NOT NULL,
    total NUMERIC(38) NOT NULL,
    is_deleted NUMERIC(38) NOT NULL
);
CREATE TABLE comp_aircraft
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    aircraft_id NUMERIC(38) NOT NULL,
    comp_id NUMERIC(38),
    datetime TIMESTAMP NOT NULL,
    CONSTRAINT comp_aircraft_aircraft_fk FOREIGN KEY (aircraft_id) REFERENCES aircraft (id),
    CONSTRAINT comp_aircraft_comp_fk FOREIGN KEY (comp_id) REFERENCES comp (id)
);
CREATE TABLE composition
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    comp_name VARCHAR(20),
    seat_number NUMERIC(38)
);
CREATE TABLE config
(
    key VARCHAR(20) PRIMARY KEY NOT NULL,
    value VARCHAR(20) NOT NULL,
    description VARCHAR(120)
);
CREATE TABLE connection_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(30) NOT NULL
);
CREATE TABLE consumption
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    resource_id NUMERIC(38) NOT NULL,
    quant NUMERIC(4),
    percentage NUMERIC(38),
    task_id NUMERIC(38) NOT NULL,
    CONSTRAINT " consumption_res_fk" FOREIGN KEY (resource_id) REFERENCES resources (id),
    CONSTRAINT consumption_employee_fk FOREIGN KEY (task_id) REFERENCES task (id)
);
CREATE TABLE container
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    flight_id NUMERIC(38) NOT NULL,
    baggage_type_id NUMERIC(38) NOT NULL,
    tag VARCHAR(15) NOT NULL,
    name VARCHAR(15),
    container_weight NUMERIC(10,2),
    travel_class_id NUMERIC(38),
    max_weight NUMERIC(10,2),
    container_status_id NUMERIC(38),
    remark VARCHAR(40),
    CONSTRAINT container_flight_fk FOREIGN KEY (flight_id) REFERENCES flight (id),
    CONSTRAINT container_baggage_type_fk FOREIGN KEY (baggage_type_id) REFERENCES baggage_type (id),
    CONSTRAINT container_travel_class_fk FOREIGN KEY (travel_class_id) REFERENCES travel_class (id),
    CONSTRAINT container_container_status_fk FOREIGN KEY (container_status_id) REFERENCES container_status (id)
);
CREATE TABLE container_status
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(30) NOT NULL
);
CREATE TABLE contractor
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(100) NOT NULL,
    color CHAR(7) NOT NULL
);
CREATE TABLE country
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    region_id NUMERIC(38),
    name_ru VARCHAR(60),
    name_en VARCHAR(60),
    alpha2 VARCHAR(2),
    alpha3 VARCHAR(3),
    code NUMERIC(38),
    is_deleted NUMERIC(38) NOT NULL,
    dts NUMERIC(38),
    is_sng NUMERIC(38) NOT NULL,
    CONSTRAINT country_region_fk FOREIGN KEY (region_id) REFERENCES region (id)
);
CREATE TABLE dcs
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(20) NOT NULL
);
CREATE TABLE dcs_resources
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    dcs_id NUMERIC(38) NOT NULL,
    resources_id NUMERIC(38) NOT NULL,
    CONSTRAINT dcs_resources_dcs_fk FOREIGN KEY (dcs_id) REFERENCES dcs (id),
    CONSTRAINT dcs_res_res_fk FOREIGN KEY (resources_id) REFERENCES resources (id)
);
CREATE TABLE delay_history
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    flight_id NUMERIC(38) NOT NULL,
    delay_duration VARCHAR(20) NOT NULL,
    delay_iata_id NUMERIC(38) NOT NULL,
    CONSTRAINT delay_history_delay_iata_fk FOREIGN KEY (delay_iata_id) REFERENCES delay_iata (id)
);
CREATE TABLE delay_iata
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    number_code VARCHAR(11) NOT NULL,
    letter_code VARCHAR(11),
    transcript VARCHAR(1000) NOT NULL,
    delay_iata_type_id NUMERIC(38) NOT NULL,
    CONSTRAINT delay_iata_delay_iata_type_fk FOREIGN KEY (delay_iata_type_id) REFERENCES delay_iata_type (id)
);
CREATE TABLE delay_iata_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(225) NOT NULL
);
CREATE TABLE department
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(30) NOT NULL,
    parent_id NUMERIC(38),
    full_name VARCHAR(100)
);
CREATE TABLE department_contractor
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    department_id NUMERIC(38) NOT NULL,
    contractor_id NUMERIC(38) NOT NULL,
    CONSTRAINT depart_contr_contr_fk FOREIGN KEY (contractor_id) REFERENCES contractor (id)
);
CREATE TABLE direction
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(20) NOT NULL
);
CREATE TABLE employee
(
    personal_number NUMERIC(38) NOT NULL,
    first_name VARCHAR(30) NOT NULL,
    middle_name VARCHAR(30),
    last_name VARCHAR(50) NOT NULL,
    employee_position_id NUMERIC(38) NOT NULL,
    user_id NUMERIC(38),
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    shift NUMERIC(38),
    working_shift_id NUMERIC(38),
    is_deleted NUMERIC(38) DEFAULT 0 NOT NULL,
    international_access NUMERIC(38) NOT NULL,
    CONSTRAINT emp_emp_position_fk FOREIGN KEY (employee_position_id) REFERENCES employee_position (id),
    CONSTRAINT employee_user_fk FOREIGN KEY (user_id) REFERENCES users (id)
);
CREATE UNIQUE INDEX employee_index1 ON employee (personal_number);
CREATE UNIQUE INDEX employee_index2 ON employee (user_id);
CREATE INDEX employee_index3 ON employee (last_name);
CREATE TABLE employee_coordinates
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    employee_id NUMERIC(38) NOT NULL,
    ip NUMERIC(38),
    mac VARCHAR(50),
    lat NUMERIC(38),
    lng NUMERIC(38),
    speed REAL,
    bearing REAL,
    accuracy REAL,
    device_timestamp TIMESTAMP,
    gps_timestamp TIMESTAMP,
    charge NUMERIC(38),
    CONSTRAINT emp_coordinates_emp_fk FOREIGN KEY (employee_id) REFERENCES employee (id)
);
CREATE TABLE employee_position
(
    name VARCHAR(60) NOT NULL,
    department_id NUMERIC(38) NOT NULL,
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    CONSTRAINT emp_position_dep_fk FOREIGN KEY (department_id) REFERENCES department (id)
);
CREATE TABLE employee_position_job
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    employee_position_id NUMERIC(38) NOT NULL,
    job_id NUMERIC(38) NOT NULL,
    CONSTRAINT "emp.pos.job_emp.pos_fk" FOREIGN KEY (employee_position_id) REFERENCES employee_position (id),
    CONSTRAINT "emp_ position_job_job_fk" FOREIGN KEY (job_id) REFERENCES job (id)
);
CREATE TABLE factor
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(20) NOT NULL
);
CREATE TABLE flight
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    plan_departure_datetime TIMESTAMP,
    fact_departure_datetime TIMESTAMP,
    plan_arrival_datetime TIMESTAMP,
    flight_number NUMERIC(38) NOT NULL,
    fact_arrival_datetime TIMESTAMP,
    aircraft_id NUMERIC(38),
    aviacompany_id NUMERIC(38) NOT NULL,
    departure_airport_id NUMERIC(38) NOT NULL,
    arrival_airport_id NUMERIC(38) NOT NULL,
    flight_type_id NUMERIC(38) NOT NULL,
    direction_id NUMERIC(38) NOT NULL,
    parking_id NUMERIC(38),
    aid NUMERIC(38),
    num NUMERIC(38),
    flight_baggage_status_id NUMERIC(38),
    sharing_aviacompany_id NUMERIC(38),
    sharing_flight_number NUMERIC(38),
    season_flight_id NUMERIC(38),
    aircraft_type_id NUMERIC(38),
    calc_arrival_datetime TIMESTAMP,
    calc_departure_datetime TIMESTAMP,
    flight_status_id NUMERIC(38),
    flight_number_symbol VARCHAR(10),
    terminal_id NUMERIC(38),
    tgo_id NUMERIC(38),
    approved NUMERIC(38) NOT NULL,
    rem VARCHAR(1000),
    sharing_number_symbol VARCHAR(10),
    take_off TIMESTAMP,
    delay_iata_id NUMERIC(38),
    flight_class_id NUMERIC(38),
    flight_condition_id NUMERIC(38),
    is_control NUMERIC(38) NOT NULL,
    flight_target_id NUMERIC(38),
    is_public NUMERIC(38),
    CONSTRAINT flight_aircraft_fk FOREIGN KEY (aircraft_id) REFERENCES aircraft (id),
    CONSTRAINT flight_aviacompany_fk FOREIGN KEY (aviacompany_id) REFERENCES aviacompany (id),
    CONSTRAINT flight_airport_fk FOREIGN KEY (departure_airport_id) REFERENCES airport (id),
    CONSTRAINT flight_airport_fkv1 FOREIGN KEY (arrival_airport_id) REFERENCES airport (id),
    CONSTRAINT flight_flight_type_fk FOREIGN KEY (flight_type_id) REFERENCES flight_type (id),
    CONSTRAINT flight_direction_fk FOREIGN KEY (direction_id) REFERENCES direction (id),
    CONSTRAINT flight_parking_fk FOREIGN KEY (parking_id) REFERENCES parking (id),
    CONSTRAINT flight_flight_bag_status_fk FOREIGN KEY (flight_baggage_status_id) REFERENCES flight_baggage_status (id),
    CONSTRAINT flight_aviacompany_fkv1 FOREIGN KEY (sharing_aviacompany_id) REFERENCES aviacompany (id),
    CONSTRAINT flight_season_flight_fk FOREIGN KEY (season_flight_id) REFERENCES season_flight (id),
    CONSTRAINT flight_aircraft_type_fk FOREIGN KEY (aircraft_type_id) REFERENCES aircraft_type (id),
    CONSTRAINT flight_flight_status_fk FOREIGN KEY (flight_status_id) REFERENCES flight_status (id),
    CONSTRAINT flight_terminal_fk FOREIGN KEY (terminal_id) REFERENCES terminal (id),
    CONSTRAINT flight_fk1 FOREIGN KEY (tgo_id) REFERENCES tgo (id),
    CONSTRAINT flight_fk2 FOREIGN KEY (delay_iata_id) REFERENCES delay_iata (id),
    CONSTRAINT flight_condition FOREIGN KEY (flight_condition_id) REFERENCES flight_condition (id),
    CONSTRAINT flight_fk3 FOREIGN KEY (flight_target_id) REFERENCES flight_target (id)
);
CREATE INDEX flight_index3 ON flight (fact_departure_datetime);
CREATE INDEX flight_index2 ON flight (plan_arrival_datetime);
CREATE INDEX flight_index1 ON flight (flight_number, plan_departure_datetime, direction_id);
CREATE INDEX idx_flight_aid_status ON flight (aid, flight_status_id);
CREATE TABLE flight_aviacompany
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    flight_id NUMERIC(38) NOT NULL,
    base CHAR,
    aviacompany_id NUMERIC(38) NOT NULL,
    flight_number NUMERIC(38),
    CONSTRAINT flight_aviacompany_flight FOREIGN KEY (flight_id) REFERENCES flight (id)
);
CREATE TABLE flight_baggage_status
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(100) NOT NULL
);
CREATE TABLE flight_class
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(50)
);
CREATE TABLE flight_condition
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(255),
    comm VARCHAR(255)
);
CREATE TABLE flight_gate
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    flight_id NUMERIC(38) NOT NULL,
    gate_id NUMERIC(38) NOT NULL,
    CONSTRAINT flight_gate_flight_fk FOREIGN KEY (flight_id) REFERENCES flight (id),
    CONSTRAINT flight_gate_gate_fk FOREIGN KEY (gate_id) REFERENCES gate (id)
);
CREATE TABLE flight_new
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    plan_departure_datetime TIMESTAMP NOT NULL,
    fact_departure_datetime TIMESTAMP,
    plan_arrival_datetime TIMESTAMP NOT NULL,
    fact_arrival_datetime TIMESTAMP,
    aircraft_id NUMERIC(38),
    departure_airport_id NUMERIC(38) NOT NULL,
    arrival_airport_id NUMERIC(38) NOT NULL,
    flight_type_id NUMERIC(38) NOT NULL,
    direction_id NUMERIC(38),
    parking_id NUMERIC(38),
    aid NUMERIC(38),
    num NUMERIC(38),
    flight_baggage_status_id NUMERIC(38),
    aircraft_type_id NUMERIC(38) NOT NULL,
    calc_arrival_datetime TIMESTAMP,
    calc_departure_datetime TIMESTAMP,
    flight_status_id NUMERIC(38),
    terminal_id NUMERIC(38),
    tgo_id NUMERIC(38),
    season_route_id NUMERIC(38),
    flight_number NUMERIC(38),
    aviacompany_id NUMERIC(38),
    flight_target_id NUMERIC(38),
    flight_class_id NUMERIC(38),
    season_flight_id NUMERIC(38),
    sharing_aviacompany_id NUMERIC(38),
    sharing_flight_number VARCHAR(20),
    group_id NUMERIC(38),
    flight_number_symbol VARCHAR(10),
    is_public NUMERIC(38) NOT NULL,
    take_off TIMESTAMP,
    CONSTRAINT flight_new_aircraft_id FOREIGN KEY (aircraft_id) REFERENCES aircraft (id),
    CONSTRAINT flight_new_dep_air FOREIGN KEY (departure_airport_id) REFERENCES airport (id),
    CONSTRAINT flight_new_arr_airport FOREIGN KEY (arrival_airport_id) REFERENCES airport (id),
    CONSTRAINT flight_new_fl_type FOREIGN KEY (flight_type_id) REFERENCES flight_type (id),
    CONSTRAINT flight_new_direction_id FOREIGN KEY (direction_id) REFERENCES direction (id),
    CONSTRAINT flight_new_parking_id FOREIGN KEY (parking_id) REFERENCES parking (id),
    CONSTRAINT flight_new_bag_status FOREIGN KEY (flight_baggage_status_id) REFERENCES flight_baggage_status (id),
    CONSTRAINT flight_new_aircraft_type FOREIGN KEY (aircraft_type_id) REFERENCES aircraft_type (id),
    CONSTRAINT flight_new_fl_status FOREIGN KEY (flight_status_id) REFERENCES flight_status (id),
    CONSTRAINT flight_terminal FOREIGN KEY (terminal_id) REFERENCES terminal (id),
    CONSTRAINT flight_new_tgo FOREIGN KEY (tgo_id) REFERENCES tgo (id),
    CONSTRAINT flight_new_season_route FOREIGN KEY (season_route_id) REFERENCES season_route (id),
    CONSTRAINT flight_new_aviacompany FOREIGN KEY (aviacompany_id) REFERENCES aviacompany (id),
    CONSTRAINT flight_new_fl_target FOREIGN KEY (flight_target_id) REFERENCES flight_target (id),
    CONSTRAINT flight_new_fl_class FOREIGN KEY (flight_class_id) REFERENCES flight_class (id),
    CONSTRAINT flight_new_seas_fl FOREIGN KEY (season_flight_id) REFERENCES season_flight (id)
);
CREATE TABLE flight_new_aviacompany
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    flight_new_id NUMERIC(38) NOT NULL,
    base CHAR,
    aviacompany_id NUMERIC(38) NOT NULL,
    flight_number NUMERIC(38),
    CONSTRAINT flig_new_avia_flig_new_fk FOREIGN KEY (flight_new_id) REFERENCES flight_new (id),
    CONSTRAINT flig_new_avia_avia_fk FOREIGN KEY (aviacompany_id) REFERENCES aviacompany (id)
);
CREATE TABLE flight_registration_desk
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    flight_id NUMERIC(38) NOT NULL,
    registration_desk_id NUMERIC(38) NOT NULL,
    CONSTRAINT flight_reg_desk_flight_fk FOREIGN KEY (flight_id) REFERENCES flight (id),
    CONSTRAINT flight_reg_desk_reg_desk_fk FOREIGN KEY (registration_desk_id) REFERENCES registration_desk (id)
);
CREATE TABLE flight_status
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(150) NOT NULL
);
CREATE TABLE flight_target
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(35) NOT NULL,
    code VARCHAR(3)
);
CREATE TABLE flight_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(30) NOT NULL
);
CREATE TABLE gate
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name NUMERIC(38),
    terminal_id NUMERIC(38) NOT NULL,
    flight_type_id NUMERIC(38) NOT NULL,
    airbridge NUMERIC(38) NOT NULL,
    status_id NUMERIC(38),
    kupol_id NUMERIC(38),
    CONSTRAINT gate_terminal_fk FOREIGN KEY (terminal_id) REFERENCES terminal (id),
    CONSTRAINT gate_flight_type_fk FOREIGN KEY (flight_type_id) REFERENCES flight_type (id),
    CONSTRAINT gate_status_fk FOREIGN KEY (status_id) REFERENCES status (id)
);
CREATE TABLE gate_dcs
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    gate_id NUMERIC(38) NOT NULL,
    dcs_id NUMERIC(38) NOT NULL,
    CONSTRAINT gate_dcs_gate_fk FOREIGN KEY (gate_id) REFERENCES gate (id),
    CONSTRAINT gate_dcs_dcs_fk FOREIGN KEY (dcs_id) REFERENCES dcs (id)
);
CREATE TABLE gate_resources
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    gate_id NUMERIC(38) NOT NULL,
    resources_id NUMERIC(38) NOT NULL,
    CONSTRAINT gate_resources_gate_fk FOREIGN KEY (gate_id) REFERENCES gate (id),
    CONSTRAINT gate_res_res_fk FOREIGN KEY (resources_id) REFERENCES resources (id)
);
CREATE TABLE hidden_group_column
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    rbac_group_id NUMERIC(38) NOT NULL,
    column_id NUMERIC(38) NOT NULL,
    CONSTRAINT hidden_group_col_rbac_group_fk FOREIGN KEY (rbac_group_id) REFERENCES rbac_group (id),
    CONSTRAINT hidden_group_col_column_fk FOREIGN KEY (column_id) REFERENCES columns (id)
);
CREATE TABLE job
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    job_category_id NUMERIC(38),
    name VARCHAR(100) NOT NULL,
    is_deleted NUMERIC(38) NOT NULL,
    job_type_id NUMERIC(38) NOT NULL,
    CONSTRAINT job_fk1 FOREIGN KEY (job_type_id) REFERENCES job_type (id)
);
CREATE TABLE job_category
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(50) NOT NULL
);
CREATE TABLE job_resource_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    job_id NUMERIC(38) NOT NULL,
    resource_type_id NUMERIC(38) NOT NULL,
    CONSTRAINT "job_ resource_type_job_fk" FOREIGN KEY (job_id) REFERENCES job (id),
    CONSTRAINT "job_ res_type_res_type_fk" FOREIGN KEY (resource_type_id) REFERENCES resource_type (id)
);
CREATE TABLE job_tgo
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    tgo_id NUMERIC(38) NOT NULL,
    job_id NUMERIC(38) NOT NULL,
    begin_time NUMERIC(38) NOT NULL,
    duration NUMERIC(38) NOT NULL,
    direction_id NUMERIC(38),
    sort NUMERIC(38) NOT NULL,
    not_required NUMERIC(38) NOT NULL,
    block_time_before NUMERIC(38),
    block_time_after NUMERIC(38),
    group_id NUMERIC(38),
    is_deleted NUMERIC(38) NOT NULL,
    CONSTRAINT job_tgo_tgo_fk FOREIGN KEY (tgo_id) REFERENCES tgo (id),
    CONSTRAINT job_tgo_job_fk FOREIGN KEY (job_id) REFERENCES job (id),
    CONSTRAINT job_tgo_direction_fk FOREIGN KEY (direction_id) REFERENCES direction (id),
    CONSTRAINT job_tgo_fk1 FOREIGN KEY (group_id) REFERENCES tgo (id)
);
CREATE TABLE job_tgo_connections
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    job_tgo_id_1 NUMERIC(38) NOT NULL,
    job_tgo_id_2 NUMERIC(38) NOT NULL,
    connection_type_id NUMERIC(38) NOT NULL,
    CONSTRAINT job_tgo_con_job_tgo_fk FOREIGN KEY (job_tgo_id_1) REFERENCES job_tgo (id),
    CONSTRAINT job_tgo_con_job_tgo_fkv1 FOREIGN KEY (job_tgo_id_2) REFERENCES job_tgo (id),
    CONSTRAINT job_tgo_con_con_type_fk FOREIGN KEY (connection_type_id) REFERENCES connection_type (id)
);
CREATE TABLE job_tgo_emp_pos_child
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    employee_position_id NUMERIC(38) NOT NULL,
    job_tgo_employee_position_id NUMERIC(38) NOT NULL,
    CONSTRAINT emp_pos_child_emp_pos_fk FOREIGN KEY (employee_position_id) REFERENCES employee_position (id),
    CONSTRAINT job_tgo_emp_pos_child_fk FOREIGN KEY (job_tgo_employee_position_id) REFERENCES job_tgo_employee_position (id)
);
CREATE TABLE job_tgo_employee_position
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    job_tgo_id NUMERIC(38) NOT NULL,
    employee_position_id NUMERIC(38),
    employee_position_count NUMERIC(38) NOT NULL,
    is_deleted NUMERIC(38) NOT NULL,
    CONSTRAINT job_tgo_emp_pos_job_tgo_fk FOREIGN KEY (job_tgo_id) REFERENCES job_tgo (id),
    CONSTRAINT job_tgo_emp_pos_emp_pos_fk FOREIGN KEY (employee_position_id) REFERENCES employee_position (id)
);
CREATE TABLE job_tgo_employee_resource
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    job_tgo_employee_position_id NUMERIC(38) NOT NULL,
    job_tgo_resource_type_id NUMERIC(38) NOT NULL,
    CONSTRAINT job_tgo_emp_res_emp_pos_fk FOREIGN KEY (job_tgo_employee_position_id) REFERENCES job_tgo_employee_position (id),
    CONSTRAINT job_tgo_emp_res_res_type_fk FOREIGN KEY (job_tgo_resource_type_id) REFERENCES job_tgo_resource_type (id)
);
CREATE TABLE job_tgo_resource_type
(
    job_tgo_id NUMERIC(38) NOT NULL,
    resource_type_id NUMERIC(38),
    resource_type_count NUMERIC(38) NOT NULL,
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    is_deleted NUMERIC(38) NOT NULL,
    CONSTRAINT "job_tgo_res_ type_job_tgo_fk" FOREIGN KEY (job_tgo_id) REFERENCES job_tgo (id),
    CONSTRAINT "job_tgo_res_ type_res_type_fk" FOREIGN KEY (resource_type_id) REFERENCES resource_type (id)
);
CREATE TABLE job_tgo_resource_type_child
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    resource_type_id NUMERIC(38) NOT NULL,
    job_tgo_resource_type_id NUMERIC(38) NOT NULL,
    CONSTRAINT res_type_child_res_type_fk FOREIGN KEY (resource_type_id) REFERENCES resource_type (id),
    CONSTRAINT res_type_child_job_tgo_res_fk FOREIGN KEY (job_tgo_resource_type_id) REFERENCES job_tgo_resource_type (id)
);
CREATE TABLE job_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(15)
);
CREATE TABLE journal
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    journal_job_id NUMERIC(38) NOT NULL,
    user_id NUMERIC(38) NOT NULL,
    ip_address VARCHAR(15),
    flight_id NUMERIC(38),
    container_id NUMERIC(38),
    baggage_id NUMERIC(38),
    message CHAR(512),
    action_datetime TIMESTAMP NOT NULL,
    mac VARCHAR(20),
    CONSTRAINT journal_fk1 FOREIGN KEY (journal_job_id) REFERENCES journal_job (id),
    CONSTRAINT journal_fk2 FOREIGN KEY (flight_id) REFERENCES flight (id),
    CONSTRAINT journal_fk3 FOREIGN KEY (container_id) REFERENCES container (id),
    CONSTRAINT journal_fk4 FOREIGN KEY (baggage_id) REFERENCES baggage (id)
);
CREATE INDEX journal_job_flight ON journal (journal_job_id, flight_id);
CREATE INDEX journal_flight_id ON journal (flight_id);
CREATE INDEX journal_container ON journal (container_id);
CREATE INDEX journal_baggage ON journal (baggage_id);
CREATE TABLE journal2
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    journal_job_id NUMERIC(38) NOT NULL,
    user_id NUMERIC(38) NOT NULL,
    ip_address VARCHAR(15),
    flight_id NUMERIC(38),
    container_id NUMERIC(38),
    baggage_id NUMERIC(38),
    action_datetime TIMESTAMP NOT NULL,
    mac VARCHAR(20),
    message VARCHAR(4000),
    CONSTRAINT journal2_journal_job_fk FOREIGN KEY (journal_job_id) REFERENCES journal_job (id),
    CONSTRAINT journal2_users_fk FOREIGN KEY (user_id) REFERENCES users (id),
    CONSTRAINT journal2_flight_fk FOREIGN KEY (flight_id) REFERENCES flight (id),
    CONSTRAINT journal2_container_fk FOREIGN KEY (container_id) REFERENCES container (id),
    CONSTRAINT journal2_baggage_fk FOREIGN KEY (baggage_id) REFERENCES baggage (id)
);
CREATE INDEX journal2_flight ON journal2 (flight_id);
CREATE INDEX journal2_container ON journal2 (container_id);
CREATE INDEX journal2_baggage ON journal2 (baggage_id);
CREATE INDEX journal2_datetime ON journal2 (action_datetime);
CREATE TABLE journal_job
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(100) NOT NULL,
    route VARCHAR(100),
    journal_job_type_id NUMERIC(38) NOT NULL,
    CONSTRAINT journal_job_fk1 FOREIGN KEY (journal_job_type_id) REFERENCES journal_job_type (id)
);
CREATE TABLE journal_job_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(20)
);
CREATE TABLE load_info
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    flight_id NUMERIC(38) NOT NULL,
    cargo NUMERIC(38),
    mail NUMERIC(38),
    baggage NUMERIC(38),
    weapon VARCHAR(50),
    disabled_pass VARCHAR(50),
    adult NUMERIC(38),
    rb NUMERIC(38),
    rm NUMERIC(38),
    vip_adult NUMERIC(38),
    vip_rb NUMERIC(38),
    vip_rm NUMERIC(38),
    adult_rb_rm VARCHAR(30),
    tranzit NUMERIC(38),
    plan_pass_ar NUMERIC(38),
    plan_pass_dep_vip NUMERIC(38),
    plan_pass_dep NUMERIC(38),
    pay_baggage NUMERIC(38),
    tranzit_adult NUMERIC(38),
    tranzit_rb NUMERIC(38),
    tranzit_rm NUMERIC(38),
    CONSTRAINT load_info_flight_fk FOREIGN KEY (flight_id) REFERENCES flight (id)
);
CREATE TABLE load_info_new
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    flight_id NUMERIC(38) NOT NULL,
    cargo NUMERIC(38),
    mail NUMERIC(38),
    baggage NUMERIC(38),
    weapon VARCHAR(50),
    disabled_pass VARCHAR(50),
    adult NUMERIC(38),
    rb NUMERIC(38),
    rm NUMERIC(38),
    vip_adult NUMERIC(38),
    vip_rb NUMERIC(38),
    vip_rm NUMERIC(38),
    adult_rb_rm VARCHAR(30),
    tranzit NUMERIC(38),
    plan_pass_ar NUMERIC(38),
    plan_pass_dep_vip NUMERIC(38),
    plan_pass_dep NUMERIC(38),
    pay_baggage NUMERIC(38),
    tranzit_adult NUMERIC(38),
    tranzit_rb NUMERIC(38),
    tranzit_rm NUMERIC(38)
);
CREATE TABLE log_trg
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    table_id NUMERIC(38) NOT NULL,
    table_name VARCHAR(64) NOT NULL,
    change_datetime TIMESTAMP NOT NULL
);
CREATE TABLE map_icon
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    img_path VARCHAR(20) NOT NULL,
    width NUMERIC(38),
    height NUMERIC(38),
    map_icon_type_id NUMERIC(38),
    CONSTRAINT map_icon_type_fk FOREIGN KEY (map_icon_type_id) REFERENCES map_icon_type (id)
);
CREATE TABLE map_icon_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    map_icon_type VARCHAR(20) NOT NULL
);
CREATE TABLE map_object
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    draw NUMERIC(38) NOT NULL
);
CREATE TABLE map_people_coordinates
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    employee_id NUMERIC(38) NOT NULL,
    speed NUMERIC(38),
    mac_address VARCHAR(20),
    gps_utc_timestamp TIMESTAMP,
    lat NUMERIC(38),
    lng NUMERIC(38),
    accuracy NUMERIC(38),
    charge NUMERIC(38),
    CONSTRAINT map_people_coord_employee_fk FOREIGN KEY (employee_id) REFERENCES employee (id)
);
CREATE TABLE map_vertex
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    object_id NUMERIC(38) NOT NULL,
    y NUMERIC(38) NOT NULL,
    x NUMERIC(38) NOT NULL,
    lat NUMERIC(38),
    lng NUMERIC(38),
    sort NUMERIC(38),
    CONSTRAINT map_vertex_fk1 FOREIGN KEY (object_id) REFERENCES map_object (id)
);
CREATE TABLE mobile_device
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    mac_address CHAR(20),
    device_model VARCHAR(255),
    charge NUMERIC(38),
    application_version VARCHAR(10),
    access_time TIMESTAMP NOT NULL,
    employee_id NUMERIC(38),
    CONSTRAINT mobile_device_employee_fk FOREIGN KEY (employee_id) REFERENCES employee (id)
);
CREATE INDEX mobile_device_employee ON mobile_device (employee_id, mac_address);
CREATE TABLE page
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(30) NOT NULL,
    code VARCHAR(255) NOT NULL
);
CREATE TABLE parking
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(128),
    status_id NUMERIC(38),
    length NUMERIC(38) NOT NULL,
    width NUMERIC(38),
    x NUMERIC(38),
    y NUMERIC(38),
    map_object_id NUMERIC(38),
    rotate NUMERIC(38),
    is_deleted NUMERIC(38) DEFAULT 0 NOT NULL,
    is_cargo NUMERIC(38) DEFAULT 0 NOT NULL,
    airbridge NUMERIC(38) DEFAULT 0 NOT NULL,
    CONSTRAINT parking_status_fk FOREIGN KEY (status_id) REFERENCES status (id),
    CONSTRAINT parking_fk1 FOREIGN KEY (map_object_id) REFERENCES map_object (id)
);
CREATE TABLE parking_aircraft_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    parking_id NUMERIC(38) NOT NULL,
    aircraft_type_id NUMERIC(38) NOT NULL,
    CONSTRAINT "park_ air_type_park_fk" FOREIGN KEY (parking_id) REFERENCES parking (id),
    CONSTRAINT "park_ air_type_air_type_fk" FOREIGN KEY (aircraft_type_id) REFERENCES aircraft_type (id)
);
CREATE TABLE parking_calendar
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    parking_id NUMERIC(38) NOT NULL,
    arrival_flight_id NUMERIC(38),
    end_datetime TIMESTAMP,
    aircraft_id NUMERIC(38),
    start_datetime TIMESTAMP,
    departure_flight_id NUMERIC(38),
    start_datetime_log NUMERIC(38),
    end_datetime_log NUMERIC(38),
    fact_start_datetime TIMESTAMP,
    fact_end_datetime TIMESTAMP,
    reserved_user_id NUMERIC(38),
    reserved_rem VARCHAR(255),
    CONSTRAINT parking_calendar_flight_fk FOREIGN KEY (arrival_flight_id) REFERENCES flight (id),
    CONSTRAINT parking_calendar_aircraft_fk FOREIGN KEY (aircraft_id) REFERENCES aircraft (id),
    CONSTRAINT parking_calendar_fk1 FOREIGN KEY (departure_flight_id) REFERENCES flight (id),
    CONSTRAINT parking_calendar_parking_fk FOREIGN KEY (reserved_user_id) REFERENCES users (id)
);
CREATE INDEX parking_calendar_index1 ON parking_calendar (parking_id, start_datetime, end_datetime);
CREATE INDEX idx_arrival_flight_id ON parking_calendar (arrival_flight_id);
CREATE INDEX idx_departure_f_id ON parking_calendar (departure_flight_id);
CREATE TABLE rbac_action
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(50) NOT NULL,
    description VARCHAR(256) NOT NULL
);
CREATE UNIQUE INDEX rbac_action_name ON rbac_action (name);
CREATE TABLE rbac_allow
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    group_id NUMERIC(38) NOT NULL,
    action_id NUMERIC(38) NOT NULL,
    CONSTRAINT rbac_allow_fk2 FOREIGN KEY (group_id) REFERENCES rbac_group (id),
    CONSTRAINT rbac_allow_fk1 FOREIGN KEY (action_id) REFERENCES rbac_action (id)
);
CREATE UNIQUE INDEX rbac_allow_inndex_ids ON rbac_allow (group_id, action_id);
CREATE TABLE rbac_group
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(256) NOT NULL,
    employee_position_id NUMERIC(38),
    CONSTRAINT rbac_group_fk1 FOREIGN KEY (employee_position_id) REFERENCES employee_position (id)
);
CREATE UNIQUE INDEX rbac_group_uniq ON rbac_group (name);
CREATE TABLE region
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name_ru VARCHAR(20),
    name_en VARCHAR(20),
    code NUMERIC(38) NOT NULL
);
CREATE TABLE registration_desk
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name NUMERIC(38),
    terminal_id NUMERIC(38) NOT NULL,
    flight_type_id NUMERIC(38) NOT NULL,
    status_id NUMERIC(38),
    kupol_id NUMERIC(38),
    drop_off NUMERIC(38),
    oversize NUMERIC(38),
    resource_id NUMERIC(38),
    CONSTRAINT reg_desk_flight_type_fk FOREIGN KEY (flight_type_id) REFERENCES flight_type (id),
    CONSTRAINT reg_desk_status_fk FOREIGN KEY (status_id) REFERENCES status (id),
    CONSTRAINT registration_desk_fk1 FOREIGN KEY (resource_id) REFERENCES resources (id)
);
CREATE TABLE registration_desk_dcs
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    registration_desk_id NUMERIC(38) NOT NULL,
    dcs_id NUMERIC(38) NOT NULL,
    CONSTRAINT reg_desk_dcs_reg_desk_fk FOREIGN KEY (registration_desk_id) REFERENCES registration_desk (id),
    CONSTRAINT registration_desk_dcs_dcs_fk FOREIGN KEY (dcs_id) REFERENCES dcs (id)
);
CREATE TABLE registration_desk_priority
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    aviacompany_id NUMERIC(38) NOT NULL,
    registration_desk_id NUMERIC(38) NOT NULL,
    CONSTRAINT reg_desk_priority_avia_fk FOREIGN KEY (aviacompany_id) REFERENCES aviacompany (id)
);
CREATE TABLE registration_desk_resources
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    registration_desk_id NUMERIC(38) NOT NULL,
    resources_id NUMERIC(38) NOT NULL,
    CONSTRAINT reg_desk_res_reg_desk_fk FOREIGN KEY (registration_desk_id) REFERENCES registration_desk (id),
    CONSTRAINT reg_desk_res_res_fk FOREIGN KEY (resources_id) REFERENCES resources (id)
);
CREATE TABLE resource_access
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    resource_type_id NUMERIC(38) NOT NULL,
    employee_id NUMERIC(38) NOT NULL,
    access_datetime TIMESTAMP,
    CONSTRAINT res_access_res_type_fk FOREIGN KEY (resource_type_id) REFERENCES resource_type (id),
    CONSTRAINT res_access_employee_fk FOREIGN KEY (employee_id) REFERENCES employee (id)
);
CREATE INDEX resource_access_index2 ON resource_access (resource_type_id);
CREATE INDEX resource_access_index1 ON resource_access (employee_id);
CREATE TABLE resource_accounting
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    resource_id NUMERIC(38) NOT NULL,
    change_datetime TIMESTAMP NOT NULL,
    user_id NUMERIC(38) NOT NULL,
    resource_status_id NUMERIC(38) NOT NULL,
    rem VARCHAR(255),
    CONSTRAINT resource_accounting_fk1 FOREIGN KEY (resource_id) REFERENCES resources (id),
    CONSTRAINT resource_accounting_fk2 FOREIGN KEY (user_id) REFERENCES users (id),
    CONSTRAINT resource_accounting_fk3 FOREIGN KEY (resource_status_id) REFERENCES resource_status (id)
);
CREATE TABLE resource_class
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(30) NOT NULL
);
CREATE TABLE resource_coordinates
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    lat NUMERIC(38),
    lng NUMERIC(38),
    autograph_timestamp TIMESTAMP,
    "current_timestamp" TIMESTAMP,
    resource_id NUMERIC(38) NOT NULL,
    CONSTRAINT res_coord_res_fk FOREIGN KEY (resource_id) REFERENCES resources (id)
);
CREATE TABLE resource_status
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(50) NOT NULL
);
CREATE TABLE resource_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(50) NOT NULL,
    resource_class_id NUMERIC(38) NOT NULL,
    parent_id NUMERIC(38),
    access_need NUMERIC(38) NOT NULL,
    department_id NUMERIC(38),
    map_icon_id NUMERIC(38),
    CONSTRAINT res_type_res_class_fk FOREIGN KEY (resource_class_id) REFERENCES resource_class (id),
    CONSTRAINT resource_type_map_icon_fk FOREIGN KEY (map_icon_id) REFERENCES map_icon (id)
);
CREATE UNIQUE INDEX resource_type_index1 ON resource_type (name);
CREATE TABLE resources
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(50) NOT NULL,
    resource_type_id NUMERIC(38) NOT NULL,
    resource_status_id NUMERIC(38) NOT NULL,
    inventory_number VARCHAR(20),
    gos_number VARCHAR(20),
    autograph_id NUMERIC(38),
    is_deleted NUMERIC(38) NOT NULL,
    report_allow NUMERIC(38) NOT NULL,
    calc_type NUMERIC(38),
    coeff REAL,
    tariff REAL,
    infinite NUMERIC(38),
    CONSTRAINT resource_resource_type_fk FOREIGN KEY (resource_type_id) REFERENCES resource_type (id),
    CONSTRAINT resources_fk1 FOREIGN KEY (resource_status_id) REFERENCES resource_status (id)
);
CREATE UNIQUE INDEX resources_index1 ON resources (inventory_number);
CREATE UNIQUE INDEX resources_index2 ON resources (gos_number);
CREATE TABLE "right"
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(50) NOT NULL
);
CREATE TABLE season
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(10)
);
CREATE TABLE season_flight
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    season_year NUMERIC(38) NOT NULL,
    season_id NUMERIC(38) NOT NULL,
    is_deleted NUMERIC(1),
    approved NUMERIC(38),
    CONSTRAINT season_flight_season_id FOREIGN KEY (season_id) REFERENCES season (id)
);
CREATE TABLE season_flight_aircraft_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    season_flight_id NUMERIC(38) NOT NULL,
    aircraft_type_id NUMERIC(38) NOT NULL,
    CONSTRAINT s_flight_air_type_s_flight_fk FOREIGN KEY (season_flight_id) REFERENCES season_flight (id),
    CONSTRAINT s_flight_air_type_air_type_fk FOREIGN KEY (aircraft_type_id) REFERENCES aircraft_type (id)
);
CREATE TABLE season_flight_date
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    flight_date TIMESTAMP,
    season_flight_period_id NUMERIC(38) NOT NULL,
    CONSTRAINT season_flight_date_fk1 FOREIGN KEY (season_flight_period_id) REFERENCES season_flight_period (id)
);
CREATE TABLE season_flight_period
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    begin_date TIMESTAMP,
    end_date TIMESTAMP,
    season_flight_id NUMERIC(38) NOT NULL,
    week_day VARCHAR(7),
    week_periodicity CHAR,
    is_deleted CHAR,
    CONSTRAINT s_fl_period_s_fl_fk FOREIGN KEY (season_flight_id) REFERENCES season_flight (id)
);
CREATE TABLE season_flight_sharing
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    season_flight_id NUMERIC(38) NOT NULL,
    aviacompany_id NUMERIC(38) NOT NULL,
    CONSTRAINT seas_fl_date_seas_fl_fk FOREIGN KEY (season_flight_id) REFERENCES season_flight (id),
    CONSTRAINT seas_fl_date_aviac_fk FOREIGN KEY (aviacompany_id) REFERENCES aviacompany (id)
);
CREATE TABLE season_route
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    season_flight_period_id NUMERIC(38) NOT NULL,
    departure_airport_id NUMERIC(38) NOT NULL,
    arrival_airport_id NUMERIC(38) NOT NULL,
    departure_time VARCHAR(10),
    arrival_time VARCHAR(10),
    route_order NUMERIC(38),
    aircraft_type_id NUMERIC(38) NOT NULL,
    flight_type_id NUMERIC(38) NOT NULL,
    flight_class_id NUMERIC(38) NOT NULL,
    flight_target_id NUMERIC(38) NOT NULL,
    terminal_id NUMERIC(38),
    canceled NUMERIC(38),
    is_deleted NUMERIC(38),
    is_public NUMERIC(38) NOT NULL,
    CONSTRAINT s_route_s_fl_p_fk FOREIGN KEY (season_flight_period_id) REFERENCES season_flight_period (id),
    CONSTRAINT s_route_airport_fk FOREIGN KEY (departure_airport_id) REFERENCES airport (id),
    CONSTRAINT s_route_airport_fk1 FOREIGN KEY (arrival_airport_id) REFERENCES airport (id),
    CONSTRAINT s_route_aircraft_type_fk FOREIGN KEY (aircraft_type_id) REFERENCES aircraft_type (id),
    CONSTRAINT s_route_flight_type_fk FOREIGN KEY (flight_type_id) REFERENCES flight_type (id),
    CONSTRAINT s_route_flight_class_fk FOREIGN KEY (flight_class_id) REFERENCES flight_class (id),
    CONSTRAINT s_route_flight_target_fk FOREIGN KEY (flight_target_id) REFERENCES flight_target (id),
    CONSTRAINT s_route_term_fk FOREIGN KEY (terminal_id) REFERENCES terminal (id)
);
CREATE TABLE season_route_aviacompany
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    season_route_id NUMERIC(38) NOT NULL,
    aviacompany_id NUMERIC(38) NOT NULL,
    flight_number VARCHAR(10),
    base NUMERIC(38),
    CONSTRAINT s_fl_avia_seas_route_fk FOREIGN KEY (season_route_id) REFERENCES season_route (id),
    CONSTRAINT s_fl_avia_avia_fk FOREIGN KEY (aviacompany_id) REFERENCES aviacompany (id)
);
CREATE TABLE session_log
(
    fdate TIMESTAMP,
    username VARCHAR(30),
    cnt_session NUMERIC(38)
);
CREATE TABLE sheduler
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    begin_time TIMESTAMP NOT NULL,
    end_time TIMESTAMP NOT NULL,
    duration NUMERIC(38) NOT NULL,
    interval NUMERIC(38) NOT NULL,
    weekend NUMERIC(38) NOT NULL,
    working_shift_id NUMERIC(38) NOT NULL,
    CONSTRAINT sheduler_work_shift_fk FOREIGN KEY (working_shift_id) REFERENCES working_shift (id)
);
CREATE TABLE shift_calendar
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    begin_datetime TIMESTAMP NOT NULL,
    end_datetime TIMESTAMP NOT NULL,
    sheduler_id NUMERIC(38) NOT NULL,
    working_shift_id NUMERIC(38) NOT NULL,
    CONSTRAINT shift_calendar_sheduler_fk FOREIGN KEY (sheduler_id) REFERENCES sheduler (id),
    CONSTRAINT shift_calendar_work_shift_fk FOREIGN KEY (working_shift_id) REFERENCES working_shift (id)
);
CREATE TABLE shift_cycle
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    shift NUMERIC(38) NOT NULL
);
CREATE TABLE shift_except
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    employee_id NUMERIC(38) NOT NULL,
    begin_datetime TIMESTAMP NOT NULL,
    end_datetime TIMESTAMP NOT NULL,
    status_id NUMERIC(38) NOT NULL,
    CONSTRAINT shift_except_fk1 FOREIGN KEY (employee_id) REFERENCES employee (id),
    CONSTRAINT shift_except_fk2 FOREIGN KEY (status_id) REFERENCES shift_except_status (id)
);
CREATE TABLE shift_except_status
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(64) NOT NULL
);
CREATE TABLE shift_history
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    shift_cycle_id NUMERIC(38) NOT NULL,
    datetime TIMESTAMP NOT NULL,
    CONSTRAINT shift_history_shift_cycle_fk FOREIGN KEY (shift_cycle_id) REFERENCES shift_cycle (id)
);
CREATE TABLE sos
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    send_employee_id NUMERIC(38),
    send_datetime TIMESTAMP,
    message VARCHAR(230),
    CONSTRAINT sos_employee_fk FOREIGN KEY (send_employee_id) REFERENCES employee (id)
);
CREATE TABLE sos_msg
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    receive_datetime TIMESTAMP,
    sos_id NUMERIC(38) NOT NULL,
    receive_employee_id NUMERIC(38) NOT NULL,
    CONSTRAINT sos_msg_sos_fk FOREIGN KEY (sos_id) REFERENCES sos (id),
    CONSTRAINT sos_msg_employee_fk FOREIGN KEY (receive_employee_id) REFERENCES employee (id)
);
CREATE TABLE status
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(50) NOT NULL
);
CREATE TABLE sys_log
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    text TEXT,
    created TIMESTAMP
);
CREATE TABLE task
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    tgo_id NUMERIC(38),
    flight_id NUMERIC(38),
    job_id NUMERIC(38) NOT NULL,
    status_id NUMERIC(38) NOT NULL,
    plan_begin_time TIMESTAMP NOT NULL,
    plan_end_time TIMESTAMP NOT NULL,
    fact_begin_time TIMESTAMP,
    fact_end_time TIMESTAMP,
    sort NUMERIC(38) NOT NULL,
    job_tgo_id NUMERIC(38),
    hand_edited NUMERIC(1) NOT NULL,
    begin_time NUMERIC(38),
    duration NUMERIC(38),
    hand_added NUMERIC(1) NOT NULL,
    aircraft_id NUMERIC(38),
    CONSTRAINT task_tgo_fk FOREIGN KEY (tgo_id) REFERENCES tgo (id),
    CONSTRAINT task_flight_fk FOREIGN KEY (flight_id) REFERENCES flight (id),
    CONSTRAINT task_job_fk FOREIGN KEY (job_id) REFERENCES job (id),
    CONSTRAINT task_status_fk FOREIGN KEY (status_id) REFERENCES status (id),
    CONSTRAINT task_job_tgo_fk FOREIGN KEY (job_tgo_id) REFERENCES job_tgo (id),
    CONSTRAINT task_fk1 FOREIGN KEY (aircraft_id) REFERENCES aircraft (id)
);
CREATE INDEX idx_task_flight_id ON task (flight_id);
CREATE INDEX task_job_id ON task (job_id);
CREATE TABLE task_employee
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    task_id NUMERIC(38) NOT NULL,
    employee_id NUMERIC(38),
    plan_begin_time TIMESTAMP NOT NULL,
    plan_end_time TIMESTAMP NOT NULL,
    fact_begin_time TIMESTAMP,
    fact_end_time TIMESTAMP,
    status_id NUMERIC(38) NOT NULL,
    delay_reason VARCHAR(256),
    employee_position_id NUMERIC(38),
    job_tgo_employee_position_id NUMERIC(38),
    receive_datetime TIMESTAMP,
    accept_datetime TIMESTAMP,
    fact_type NUMERIC(1),
    report_allow NUMERIC(38) NOT NULL,
    hand_edited NUMERIC(1) NOT NULL,
    begin_time NUMERIC(38),
    duration NUMERIC(38),
    CONSTRAINT task_employee_task_fk FOREIGN KEY (task_id) REFERENCES task (id),
    CONSTRAINT task_employee_employee_fk FOREIGN KEY (employee_id) REFERENCES employee (id),
    CONSTRAINT task_employee_status_fk FOREIGN KEY (status_id) REFERENCES status (id),
    CONSTRAINT task_employee_fk1 FOREIGN KEY (employee_position_id) REFERENCES employee_position (id),
    CONSTRAINT task_employee_fk2 FOREIGN KEY (job_tgo_employee_position_id) REFERENCES job_tgo_employee_position (id)
);
CREATE INDEX task_employee_task_id ON task_employee (task_id);
CREATE INDEX task_employee_employee_id ON task_employee (employee_id);
CREATE INDEX task_employee_plan_begin ON task_employee (plan_begin_time, employee_id);
CREATE TABLE task_employee_factor
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    task_employee_id NUMERIC(38) NOT NULL,
    employee_id NUMERIC(38) NOT NULL,
    factor_id NUMERIC(38) NOT NULL,
    CONSTRAINT task_empl_factor_task_empl_fk FOREIGN KEY (task_employee_id) REFERENCES task_employee (id),
    CONSTRAINT task_employee_factor_empl_fk FOREIGN KEY (employee_id) REFERENCES employee (id),
    CONSTRAINT task_employee_factor_factor_fk FOREIGN KEY (factor_id) REFERENCES factor (id)
);
CREATE TABLE task_resource
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    task_employee_id NUMERIC(38) NOT NULL,
    resource_id NUMERIC(38) NOT NULL,
    task_status_id NUMERIC(38),
    job_tgo_resource_type_id NUMERIC(38),
    CONSTRAINT task_resource_fk1 FOREIGN KEY (task_employee_id) REFERENCES task_employee (id),
    CONSTRAINT task_resource_resource_fk FOREIGN KEY (resource_id) REFERENCES resources (id),
    CONSTRAINT task_resource_fk2 FOREIGN KEY (job_tgo_resource_type_id) REFERENCES job_tgo_resource_type (id)
);
CREATE TABLE task_resource_require
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    task_id NUMERIC(38) NOT NULL,
    resource_type_id NUMERIC(38) NOT NULL,
    count NUMERIC(38) NOT NULL,
    CONSTRAINT task_resource_require_fk2 FOREIGN KEY (resource_type_id) REFERENCES resource_type (id)
);
CREATE TABLE task_resources_factor
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    resources_id NUMERIC(38) NOT NULL,
    task_resource_id NUMERIC(38) NOT NULL,
    factor_id NUMERIC(38) NOT NULL,
    CONSTRAINT task_res_factor_res_fk FOREIGN KEY (resources_id) REFERENCES resources (id),
    CONSTRAINT task_res_factor_task_res_fk FOREIGN KEY (task_resource_id) REFERENCES task_resource (id),
    CONSTRAINT task_res_factor_factor_fk FOREIGN KEY (factor_id) REFERENCES factor (id)
);
CREATE TABLE task_status
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(50) NOT NULL
);
CREATE TABLE telegram_source
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(50) NOT NULL
);
CREATE TABLE telegram_status
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(100) NOT NULL
);
CREATE TABLE telegram_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name_ru VARCHAR(10),
    name_en VARCHAR(10) NOT NULL
);
CREATE TABLE telegrams
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    receive_datetime TIMESTAMP NOT NULL,
    type_id NUMERIC(38),
    status_id NUMERIC(38) NOT NULL,
    flight_id NUMERIC(38),
    reg_no NUMERIC(38),
    message VARCHAR(1000),
    accept_datetime TIMESTAMP,
    source_id NUMERIC(38),
    text VARCHAR(4000) NOT NULL,
    user_text VARCHAR(4000),
    sita_id NUMERIC(38),
    CONSTRAINT telegrams_telegram_type_fk FOREIGN KEY (type_id) REFERENCES telegram_type (id),
    CONSTRAINT telegrams_telegram_status_fk FOREIGN KEY (status_id) REFERENCES telegram_status (id),
    CONSTRAINT telegrams_source FOREIGN KEY (source_id) REFERENCES telegram_source (id)
);
CREATE TABLE templates
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    text VARCHAR(400) NOT NULL
);
CREATE TABLE terminal
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(15) NOT NULL
);
CREATE TABLE tgo
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(50) NOT NULL,
    flight_type_id NUMERIC(38),
    direction_id NUMERIC(38),
    is_deleted NUMERIC(38) NOT NULL,
    active NUMERIC(38),
    operative NUMERIC(38),
    airbridge NUMERIC(38),
    tgo_type NUMERIC(38) NOT NULL,
    CONSTRAINT tgo_flight_type_fk FOREIGN KEY (flight_type_id) REFERENCES flight_type (id),
    CONSTRAINT tgo_direction_fk FOREIGN KEY (direction_id) REFERENCES direction (id)
);
CREATE TABLE tgo_aircraft_type
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    tgo_id NUMERIC(38) NOT NULL,
    aircraft_type_id NUMERIC(38) NOT NULL,
    CONSTRAINT "tgo_ aircraft_type_tgo_fk" FOREIGN KEY (tgo_id) REFERENCES tgo (id),
    CONSTRAINT "tgo_ air_type_air_type_fk" FOREIGN KEY (aircraft_type_id) REFERENCES aircraft_type (id)
);
CREATE TABLE tgo_aviacompany
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    tgo_id NUMERIC(38) NOT NULL,
    aviacompany_id NUMERIC(38) NOT NULL,
    CONSTRAINT "tgo_ avcom_tgo_fk" FOREIGN KEY (tgo_id) REFERENCES tgo (id),
    CONSTRAINT "tgo_ av_avcom_fk" FOREIGN KEY (aviacompany_id) REFERENCES aviacompany (id)
);
CREATE TABLE tgo_flight_number
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    tgo_id NUMERIC(38) NOT NULL,
    flight_id NUMERIC(38) NOT NULL,
    CONSTRAINT tgo_flight_num_tgo_fk FOREIGN KEY (tgo_id) REFERENCES tgo (id),
    CONSTRAINT tgo_flight_num_flight_fk FOREIGN KEY (flight_id) REFERENCES flight (id)
);
CREATE TABLE travel_class
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(100) NOT NULL
);
CREATE TABLE travel_class_code
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    travel_class_id NUMERIC(38) NOT NULL,
    code VARCHAR NOT NULL,
    CONSTRAINT trav_class_code_trav_class_fk FOREIGN KEY (travel_class_id) REFERENCES travel_class (id)
);
CREATE TABLE user_right
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    user_id NUMERIC(38) NOT NULL,
    right_id NUMERIC(38) NOT NULL,
    CONSTRAINT user_right_user_fk FOREIGN KEY (user_id) REFERENCES users (id),
    CONSTRAINT user_right_right_fk FOREIGN KEY (right_id) REFERENCES "right" (id)
);
CREATE TABLE users
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(60) NOT NULL,
    password VARCHAR(60) NOT NULL,
    auth_key VARCHAR(60) NOT NULL,
    token VARCHAR(60) NOT NULL,
    group_id NUMERIC(38) NOT NULL,
    is_deleted NUMERIC(38) DEFAULT 0 NOT NULL,
    CONSTRAINT users_fk1 FOREIGN KEY (group_id) REFERENCES rbac_group (id)
);
CREATE UNIQUE INDEX users_index1 ON users (name);
CREATE TABLE working_shift
(
    id NUMERIC(38) PRIMARY KEY NOT NULL,
    name VARCHAR(100) NOT NULL,
    contractor_id NUMERIC(38),
    CONSTRAINT working_shift_fk1 FOREIGN KEY (contractor_id) REFERENCES contractor (id)
);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download