Files
life-echo/api/migrations/add_orders_table.sql
iammm0 e39fd97e06 feat: 新增后端支付模块,支持微信和支付宝
- 新增api/payment/支付服务(微信、支付宝)
- 新增api/routers/payment.py支付路由
- 更新database/models.py支付相关模型
- 新增数据库迁移文件(订单表、用户订阅字段)
- 更新main.py、requirements.txt、.env.production

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-10 14:23:29 +08:00

27 lines
965 B
SQL

-- 添加订单表和用户订阅到期时间字段
-- 执行时间: 2026-02
-- 1. 为 users 表添加 subscription_expires_at 字段
ALTER TABLE users ADD COLUMN IF NOT EXISTS subscription_expires_at TIMESTAMP WITH TIME ZONE DEFAULT NULL;
-- 2. 创建 orders 表
CREATE TABLE IF NOT EXISTS orders (
id VARCHAR NOT NULL PRIMARY KEY,
user_id VARCHAR NOT NULL REFERENCES users(id),
plan_id VARCHAR NOT NULL,
plan_name VARCHAR NOT NULL,
amount INTEGER NOT NULL,
currency VARCHAR DEFAULT 'CNY',
payment_method VARCHAR NOT NULL,
status VARCHAR DEFAULT 'pending',
trade_no VARCHAR,
paid_at TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
expired_at TIMESTAMP WITH TIME ZONE
);
-- 3. 创建索引
CREATE INDEX IF NOT EXISTS ix_orders_user_id ON orders(user_id);
CREATE INDEX IF NOT EXISTS ix_orders_trade_no ON orders(trade_no);
CREATE INDEX IF NOT EXISTS ix_orders_status ON orders(status);