CREATE SCHEMA IF NOT EXISTS onoffline;

CREATE TABLE IF NOT EXISTS onoffline.onoffline_record (
    guid VARCHAR(32) NOT NULL,
    ts_ms BIGINT NOT NULL,
    write_ts_ms BIGINT NOT NULL,
    hotel_id SMALLINT NOT NULL,
    mac VARCHAR(21) NOT NULL,
    device_id VARCHAR(64) NOT NULL,
    room_id VARCHAR(64) NOT NULL,
    ip VARCHAR(21),
    current_status VARCHAR(255),
    launcher_version VARCHAR(255),
    reboot_reason VARCHAR(255),
    PRIMARY KEY (ts_ms, mac, device_id, room_id)
) PARTITION BY RANGE (ts_ms);

CREATE INDEX IF NOT EXISTS idx_onoffline_ts_ms ON onoffline.onoffline_record (ts_ms);
CREATE INDEX IF NOT EXISTS idx_onoffline_hotel_id ON onoffline.onoffline_record (hotel_id);
CREATE INDEX IF NOT EXISTS idx_onoffline_mac ON onoffline.onoffline_record (mac);
CREATE INDEX IF NOT EXISTS idx_onoffline_device_id ON onoffline.onoffline_record (device_id);
CREATE INDEX IF NOT EXISTS idx_onoffline_room_id ON onoffline.onoffline_record (room_id);
CREATE INDEX IF NOT EXISTS idx_onoffline_current_status ON onoffline.onoffline_record (current_status);
