Files
life-echo/api/migrations_legacy/add_users_subscription_columns.sql

27 lines
1.1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 为 users 表添加订阅相关列subscription_type, subscription_expires_at
-- 若列已存在则跳过,可重复执行。
-- 执行方式: psql -U <user> -d <database> -f api/migrations/add_users_subscription_columns.sql
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'users' AND column_name = 'subscription_type'
) THEN
ALTER TABLE users ADD COLUMN subscription_type VARCHAR DEFAULT 'free';
RAISE NOTICE '已添加 users.subscription_type 列';
ELSE
RAISE NOTICE 'users.subscription_type 列已存在,跳过';
END IF;
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'users' AND column_name = 'subscription_expires_at'
) THEN
ALTER TABLE users ADD COLUMN subscription_expires_at TIMESTAMP WITH TIME ZONE DEFAULT NULL;
RAISE NOTICE '已添加 users.subscription_expires_at 列';
ELSE
RAISE NOTICE 'users.subscription_expires_at 列已存在,跳过';
END IF;
END $$;