-- task
CREATE TABLE IF NOT EXISTS dat_task
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        TEXT NOT NULL,
    device_sn   TEXT NOT NULL,
    param_json  TEXT NOT NULL,
    result_json TEXT NULL,
    state       INTEGER DEFAULT 0,
    start_time  DATETIME NULL,
    end_time    DATETIME NULL,
    create_time DATETIME NULL,
    update_time DATETIME NULL
);

-- task data
CREATE TABLE IF NOT EXISTS dat_task_progress
(
    id              INTEGER PRIMARY KEY AUTOINCREMENT,
    task_id         INTEGER NOT NULL,
    device_sn       TEXT NOT NULL,
    task_data_json  TEXT NOT NULL,
    create_time     TIMESTAMP DEFAULT (DATETIME(CURRENT_TIMESTAMP, 'localtime'))
);

-- task log
CREATE TABLE IF NOT EXISTS dat_task_log
(
    id              INTEGER PRIMARY KEY AUTOINCREMENT,
    task_id         INTEGER NOT NULL,
    device_sn       TEXT NOT NULL,
    content         TEXT NOT NULL,
    create_time     TIMESTAMP DEFAULT (DATETIME(CURRENT_TIMESTAMP, 'localtime'))
);