-- +goose Up
-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS users(
    id bigserial PRIMARY KEY,
    created_at timestamptz NOT NULL DEFAULT NOW(),
    updated_at timestamptz NOT NULL DEFAULT NOW(),
    deleted_at timestamptz,
    username varchar(255) NOT NULL UNIQUE,
    password varchar(255) NOT NULL,
    roles text[] NOT NULL DEFAULT ARRAY['user'],
    status varchar(50) NOT NULL DEFAULT 'active',
    metas jsonb NOT NULL DEFAULT '{}',
    balance bigint NOT NULL DEFAULT 0,
    balance_frozen bigint NOT NULL DEFAULT 0,
    verified_at timestamptz
);

COMMENT ON COLUMN users.balance IS '全局可用余额：分/最小货币单位；用户在所有已加入租户内共享该余额；默认 0';
COMMENT ON COLUMN users.balance_frozen IS '全局冻结余额：分/最小货币单位；用于下单冻结等；默认 0';

CREATE INDEX IF NOT EXISTS ix_users_balance ON users(balance);
CREATE INDEX IF NOT EXISTS ix_users_balance_frozen ON users(balance_frozen);

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS users;

-- +goose StatementEnd
