"""将 auth.users.status 列的 DEFAULT 值从 'pending' 改为 'new'"""
import os
import psycopg2
from dotenv import load_dotenv

load_dotenv()
dsn = os.environ["APP_DB_DSN"]
conn = psycopg2.connect(dsn)
conn.autocommit = True
cur = conn.cursor()

print(f"连接: {dsn.split('@')[1] if '@' in dsn else dsn}")

cur.execute("ALTER TABLE auth.users ALTER COLUMN status SET DEFAULT 'new'")
print("已将 auth.users.status DEFAULT 改为 'new'")

# 验证
cur.execute("""
    SELECT column_default
    FROM information_schema.columns
    WHERE table_schema = 'auth' AND table_name = 'users' AND column_name = 'status'
""")
row = cur.fetchone()
print(f"验证 DEFAULT: {row[0]}")

conn.close()
print("完成")
