-- 设置时区为东八区
SET TIMEZONE = 'Asia/Shanghai';

-- 创建 user_main 表
CREATE TABLE IF NOT EXISTS user_main (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    deleted BOOLEAN DEFAULT false,
    create_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

-- 创建 user_login_account 表
CREATE TABLE IF NOT EXISTS user_login_account (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES user_main(id),
    account VARCHAR(255) NOT NULL,
    deleted BOOLEAN DEFAULT false,
    create_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(account)
);

-- 创建 user_login_password 表
CREATE TABLE IF NOT EXISTS user_login_password (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES user_main(id),
    password VARCHAR(255) NOT NULL,
    deleted BOOLEAN DEFAULT false,
    create_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

-- 创建索引
CREATE INDEX IF NOT EXISTS idx_user_login_account_user_id ON user_login_account(user_id);
CREATE INDEX IF NOT EXISTS idx_user_login_account_account ON user_login_account(account);
CREATE INDEX IF NOT EXISTS idx_user_login_password_user_id ON user_login_password(user_id);
