PRAGMA foreign_keys = OFF;

-- ----------------------------
-- Table structure for audit_record
-- ----------------------------
DROP TABLE IF EXISTS audit_record;
CREATE TABLE audit_record (
    id            INTEGER      NOT NULL PRIMARY KEY,
    user_id       INTEGER,
    user_name     TEXT,
    solution_id   INTEGER,
    solution_name TEXT,
    concentration TEXT,
    channel_id    INTEGER,
    volume        TEXT,
    create_time   DATE         DEFAULT CURRENT_TIMESTAMP,
    update_time   DATE         DEFAULT CURRENT_TIMESTAMP
);

-- ----------------------------
-- Table structure for channel
-- ----------------------------
DROP TABLE IF EXISTS channel;
CREATE TABLE channel (
    id            INTEGER      NOT NULL PRIMARY KEY,
    name          TEXT,
    solution_id   INTEGER,
    solution_name TEXT,
    concentration TEXT,
    code          TEXT,
    volume        DOUBLE,
    create_time   DATE         DEFAULT CURRENT_TIMESTAMP,
    update_time   DATE         DEFAULT CURRENT_TIMESTAMP
);

INSERT OR IGNORE INTO channel (
    id, name, solution_id, solution_name, concentration, code, volume
) VALUES
    (1, '通道一', 1, '盐酸', '15%', 'CHANNEL_1', 5000),
    (2, '通道二', 1, '盐酸', '15%', 'CHANNEL_2', 5000),
    (3, '通道三', 1, '盐酸', '15%', 'CHANNEL_3', 5000),
    (4, '通道四', 1, '盐酸', '15%', 'CHANNEL_4', 5000);

-- ----------------------------
-- Table structure for formulation
-- ----------------------------
DROP TABLE IF EXISTS formulation;
CREATE TABLE formulation (
    id            INTEGER      NOT NULL PRIMARY KEY,
    volume        DOUBLE,
    solution_id   INTEGER,
    solution_name TEXT,
    concentration TEXT,
    scale         DOUBLE,
    revolutions   DOUBLE,
    create_time   DATE         DEFAULT CURRENT_TIMESTAMP,
    update_time   DATE         DEFAULT CURRENT_TIMESTAMP
);

-- ----------------------------
-- Table structure for receive_record
-- ----------------------------
DROP TABLE IF EXISTS receive_record;
CREATE TABLE receive_record (
    id            INTEGER      NOT NULL PRIMARY KEY,
    user_id       INTEGER,
    user_name     TEXT,
    receiver      TEXT,
    receiver_id   INTEGER,
    solution_id   INTEGER,
    solution_name TEXT,
    concentration TEXT,
    channel_id    INTEGER,
    volume        DOUBLE,
    create_time   DATE         DEFAULT CURRENT_TIMESTAMP,
    update_time   DATE         DEFAULT CURRENT_TIMESTAMP
);

-- ----------------------------
-- Table structure for solution
-- ----------------------------
DROP TABLE IF EXISTS solution;
CREATE TABLE solution (
    id          INTEGER      PRIMARY KEY AUTOINCREMENT,
    name        TEXT,
    create_time TIMESTAMP    DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP    DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO solution (id, name) VALUES
    (1, '盐酸'),
    (2, '硫酸');

-- ----------------------------
-- Table structure for system_config
-- ----------------------------
DROP TABLE IF EXISTS system_config;
CREATE TABLE system_config (
    id          INTEGER      PRIMARY KEY AUTOINCREMENT,
    key         TEXT,
    value       TEXT,
    create_time TIMESTAMP    DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP    DEFAULT CURRENT_TIMESTAMP
);

-- ----------------------------
-- Table structure for system_log
-- ----------------------------
DROP TABLE IF EXISTS system_log;
CREATE TABLE system_log (
    id          INTEGER      PRIMARY KEY AUTOINCREMENT,
    title       TEXT,
    content     TEXT,
    create_time TIMESTAMP    DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP    DEFAULT CURRENT_TIMESTAMP
);

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS user;
CREATE TABLE user (
    id          INTEGER      PRIMARY KEY AUTOINCREMENT,
    username    TEXT         UNIQUE,
    nickname    TEXT,
    password    TEXT,
    role        TEXT,
    fixed_user  TEXT         DEFAULT 'DISABLE',
    deleted     TEXT         DEFAULT 'DISABLE',
    create_time TIMESTAMP    DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP    DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO user (
    id, username, nickname, password, role, fixed_user, deleted
) VALUES
      (1, 'admin', 'Admin', '9973', 'ADMIN', 'ENABLE', 'DISABLE'),
      (2, 'test',  'test',  '9973', 'ADMIN', 'ENABLE', 'DISABLE');

-- ----------------------------
-- Table structure for zapp_sub_module_reg_initial_value
-- ----------------------------
DROP TABLE IF EXISTS zapp_sub_module_reg_initial_value;
CREATE TABLE zapp_sub_module_reg_initial_value (
    id           INTEGER      PRIMARY KEY DESC,
    mid          TEXT,
    regIndex     TEXT,
    regInitVal   INTEGER
);

-- ----------------------------
-- Auto increment adjustments
-- ----------------------------
UPDATE sqlite_sequence SET seq = 2  WHERE name = 'solution';
UPDATE sqlite_sequence SET seq = 38 WHERE name = 'user';

PRAGMA foreign_keys = ON;
