-- 创建用户和数据库
CREATE USER user_service WITH PASSWORD 'password';
CREATE DATABASE user_db OWNER user_service;
GRANT ALL PRIVILEGES ON DATABASE user_db TO user_service;

-- 连接到 user_db 并创建表
\c user_db;

CREATE TABLE IF NOT EXISTS users (
    id SERIAL PRIMARY KEY,
    username VARCHAR(255) UNIQUE NOT NULL,
    password_hash VARCHAR(255) NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
