CREATE TABLE IF NOT EXISTS asc_node (
    asc_node_id BIGSERIAL PRIMARY KEY,
    satellite_id BIGINT NOT NULL,
    t TIMESTAMP NOT NULL,
    revolution BIGINT NOT NULL,
    longitude DOUBLE PRECISION,
    height DOUBLE PRECISION,
    x DOUBLE PRECISION,
    y DOUBLE PRECISION,
    z DOUBLE PRECISION,
    vx DOUBLE PRECISION,
    vy DOUBLE PRECISION,
    vz DOUBLE PRECISION
);
CREATE INDEX idx_asc_node_satellite_id ON asc_node(satellite_id);
CREATE INDEX idx_asc_node_t ON asc_node(t);
CREATE INDEX idx_asc_node_revolution ON asc_node(revolution);


CREATE TABLE IF NOT EXISTS flight_line (
    flight_line_id BIGSERIAL PRIMARY KEY,
    satellite_id BIGINT NOT NULL,
    t TIMESTAMP NOT NULL,
    revolution BIGINT NOT NULL,
    revolution_sign VARCHAR(4) NOT NULL CHECK (revolution_sign IN ('ASC', 'DESC')),
    longitude DOUBLE PRECISION,
    latitude DOUBLE PRECISION,
    longitude_outer_left DOUBLE PRECISION,
    latitude_outer_left DOUBLE PRECISION,
    longitude_inner_left DOUBLE PRECISION,
    latitude_inner_left DOUBLE PRECISION,
    longitude_inner_right DOUBLE PRECISION,
    latitude_inner_right DOUBLE PRECISION,
    longitude_outer_right DOUBLE PRECISION,
    latitude_outer_right DOUBLE PRECISION
);
CREATE INDEX idx_flight_line_satellite_id ON flight_line(satellite_id);
CREATE INDEX idx_flight_line_t ON flight_line(t);
CREATE INDEX idx_flight_line_revolution ON flight_line(revolution);


CREATE TABLE IF NOT EXISTS earth_coverage (
    earth_coverage_id BIGSERIAL PRIMARY KEY,
    satellite_id BIGINT NOT NULL,
    cell_number BIGINT NOT NULL,
    t_start TIMESTAMP NOT NULL,
    t_stop TIMESTAMP NOT NULL
);
CREATE INDEX idx_earth_coverage_satellite_id ON earth_coverage(satellite_id);
CREATE INDEX idx_earth_coverage_t ON earth_coverage(t_start);
CREATE INDEX idx_earth_coverage_cell_number ON earth_coverage(cell_number);