-- 用户表，插入时判断账户是否已存在
CREATE TABLE IF NOT EXISTS user (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT,
    nickname TEXT,
    password TEXT,
    role TEXT,
    fixed_user TEXT,
    deleted TEXT,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO user (username,nickname, password, role, fixed_user, deleted)
SELECT 'admin','Admin', '123456', 'ADMIN', 'ENABLE','DISABLE'
    WHERE NOT EXISTS (SELECT 1 FROM user WHERE username = 'admin');


-- 创建 ores 矿石 表
CREATE TABLE IF NOT EXISTS ores
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        VARCHAR NOT NULL,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 创建 crafts 工艺 表
CREATE TABLE IF NOT EXISTS crafts
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        VARCHAR NOT NULL,
    steps       TEXT,
    ores_id     INTEGER,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);