@windrun-huaiin/backend-core 11.0.0 → 11.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  -- 第一步:彻底删除 nextai schema(连里面的表、序列、权限全炸)
2
- DROP SCHEMA IF EXISTS nextai CASCADE;
2
+ -- 为防止误操作,该SQL注释掉,只有初始化时才使用!
3
+ -- DROP SCHEMA IF EXISTS nextai CASCADE;
3
4
 
4
5
  -- 第二步:重新创建干净的 nextai schema
5
6
  CREATE SCHEMA nextai;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windrun-huaiin/backend-core",
3
- "version": "11.0.0",
3
+ "version": "11.0.2",
4
4
  "description": "Shared backend primitives: Prisma schema/client, database services, routing helpers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -86,13 +86,13 @@
86
86
  "dependencies": {
87
87
  "@clerk/nextjs": "^6.19.4",
88
88
  "@prisma/client": "^6.17.1",
89
- "next": "16.0.0",
89
+ "next": "16.0.10",
90
90
  "prisma": "^6.17.1",
91
91
  "stripe": "19.3.0",
92
92
  "svix": "^1.81.0",
93
93
  "zod": "^4.1.12",
94
- "@windrun-huaiin/lib": "^11.0.0",
95
- "@windrun-huaiin/third-ui": "^11.0.0"
94
+ "@windrun-huaiin/lib": "^11.0.1",
95
+ "@windrun-huaiin/third-ui": "^11.0.1"
96
96
  },
97
97
  "devDependencies": {
98
98
  "@rollup/plugin-alias": "^5.1.1",
@@ -106,7 +106,7 @@
106
106
  "peerDependencies": {
107
107
  "@clerk/nextjs": "^6.19.4",
108
108
  "@prisma/client": "^6.17.1",
109
- "next": "16.0.0",
109
+ "next": "16.0.10",
110
110
  "prisma": "^6.17.1",
111
111
  "stripe": "19.3.0",
112
112
  "svix": "^1.81.0"
@@ -1,13 +0,0 @@
1
- -- Database: nextai
2
-
3
- -- DROP DATABASE IF EXISTS nextai;
4
-
5
- CREATE DATABASE nextai
6
- WITH
7
- OWNER = funeye
8
- ENCODING = 'UTF8'
9
- LC_COLLATE = 'C'
10
- LC_CTYPE = 'C'
11
- TABLESPACE = pg_default
12
- CONNECTION LIMIT = -1
13
- IS_TEMPLATE = False;
@@ -1,27 +0,0 @@
1
- -- 清空所有数据表
2
-
3
- TRUNCATE TABLE
4
- users,
5
- subscriptions,
6
- credits,
7
- credit_audit_log,
8
- transactions,
9
- user_backup,
10
- apilog
11
- RESTART IDENTITY;
12
-
13
- -- 验证结果
14
-
15
- SELECT 'users' AS table_name, COUNT(*) AS row_count FROM users
16
- UNION ALL
17
- SELECT 'subscriptions' AS table_name, COUNT(*) AS row_count FROM subscriptions
18
- UNION ALL
19
- SELECT 'credits' AS table_name, COUNT(*) AS row_count FROM credits
20
- UNION ALL
21
- SELECT 'credit_audit_log' AS table_name, COUNT(*) AS row_count FROM credit_usage
22
- UNION ALL
23
- SELECT 'transactions' AS table_name, COUNT(*) AS row_count FROM transactions
24
- UNION ALL
25
- SELECT 'user_backup' AS table_name, COUNT(*) AS row_count FROM user_backup
26
- UNION ALL
27
- SELECT 'apilog' AS table_name, COUNT(*) AS row_count FROM apilog;
@@ -1,167 +0,0 @@
1
- SELECT
2
- u.id AS user_pk,
3
- u.user_id,
4
- u.status,
5
- u.fingerprint_id,
6
- u.clerk_user_id,
7
- u.stripe_cus_id,
8
- u.email,
9
- u.created_at AS user_created_at,
10
- u.updated_at AS user_updated_at,
11
- c.id AS credit_pk,
12
- c.balance_free,
13
- c.total_free_limit,
14
- c.free_start,
15
- c.free_end,
16
- c.balance_paid,
17
- c.total_paid_limit,
18
- c.paid_start,
19
- c.paid_end,
20
- c.balance_onetime_paid,
21
- c.total_onetime_paid_limit,
22
- c.onetime_paid_start,
23
- c.onetime_paid_end,
24
- c.created_at AS credit_created_at,
25
- c.updated_at AS credit_updated_at,
26
- s.id AS subscription_pk,
27
- s.status AS subscription_status,
28
- s.pay_subscription_id,
29
- s.price_id,
30
- s.price_name,
31
- s.credits_allocated,
32
- s.sub_period_start,
33
- s.sub_period_end,
34
- s.created_at AS subscription_created_at,
35
- s.updated_at AS subscription_updated_at,
36
- s.deleted AS subscription_deleted
37
- FROM public.users u
38
- LEFT JOIN public.credits c ON c.user_id = u.user_id
39
- LEFT JOIN public.subscriptions s ON s.user_id = u.user_id
40
- WHERE u.user_id = '48e4619a-5b9e-47eb-a854-3eeca66856f9';
41
-
42
-
43
- -- PostgreSQL 新增字段·重建表
44
-
45
-
46
- -- ==============================
47
- -- 1. 开始事务
48
- -- ==============================
49
- BEGIN;
50
-
51
- -- ==============================
52
- -- 2. 创建新表(正确字段顺序)
53
- -- ==============================
54
- CREATE TABLE public.transactions_new (
55
- id BIGSERIAL PRIMARY KEY,
56
- user_id UUID NOT NULL,
57
- order_id VARCHAR(255) NOT NULL,
58
- order_status VARCHAR(50) NOT NULL DEFAULT 'created',
59
- order_created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
60
- order_expired_at TIMESTAMPTZ,
61
- order_updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
62
- type VARCHAR(50),
63
- pay_supplier VARCHAR(255),
64
- pay_session_id VARCHAR(255),
65
- pay_transaction_id VARCHAR(255),
66
- pay_subscription_id VARCHAR(255),
67
- sub_period_start TIMESTAMPTZ,
68
- sub_period_end TIMESTAMPTZ,
69
- sub_last_try_cancel_at TIMESTAMPTZ,
70
- sub_period_canceled_at TIMESTAMPTZ,
71
- sub_cancellation_detail TEXT,
72
- price_id VARCHAR(255),
73
- price_name VARCHAR(255),
74
- amount NUMERIC(10, 2),
75
- currency VARCHAR(50),
76
- credits_granted INTEGER NOT NULL DEFAULT 0,
77
- pay_invoice_id VARCHAR(255),
78
- payment_status VARCHAR(50) NOT NULL DEFAULT 'un_paid',
79
- billing_reason VARCHAR(100),
80
- hosted_invoice_url TEXT,
81
- invoice_pdf TEXT,
82
- order_detail TEXT,
83
- paid_email VARCHAR(255),
84
- paid_at TIMESTAMPTZ,
85
- paid_detail TEXT,
86
- pay_updated_at TIMESTAMPTZ,
87
- deleted INTEGER NOT NULL DEFAULT 0
88
- );
89
-
90
- -- ==============================
91
- -- 3. 复制数据
92
- -- ==============================
93
- INSERT INTO public.transactions_new (
94
- id, user_id, order_id, order_status, order_created_at, order_expired_at,
95
- order_updated_at, type, pay_supplier, pay_session_id, pay_transaction_id,
96
- pay_subscription_id, sub_period_start, sub_period_end,
97
- sub_period_canceled_at, sub_cancellation_detail, price_id, price_name,
98
- amount, currency, credits_granted, pay_invoice_id, payment_status,
99
- billing_reason, hosted_invoice_url, invoice_pdf, order_detail,
100
- paid_email, paid_at, paid_detail, pay_updated_at, deleted
101
- )
102
- SELECT
103
- id, user_id, order_id, order_status, order_created_at, order_expired_at,
104
- order_updated_at, type, pay_supplier, pay_session_id, pay_transaction_id,
105
- pay_subscription_id, sub_period_start, sub_period_end,
106
- sub_period_canceled_at, sub_cancellation_detail, price_id, price_name,
107
- amount, currency, credits_granted, pay_invoice_id, payment_status,
108
- billing_reason, hosted_invoice_url, invoice_pdf, order_detail,
109
- paid_email, paid_at, paid_detail, pay_updated_at, deleted
110
- FROM public.transactions;
111
-
112
- -- ==============================
113
- -- 4. 删除旧表(释放约束名 + 旧序列)
114
- -- ==============================
115
- DROP TABLE public.transactions;
116
-
117
- -- ==============================
118
- -- 5. 重命名新表(此时新表已有自己的序列!)
119
- -- ==============================
120
- ALTER TABLE public.transactions_new RENAME TO transactions;
121
-
122
- -- ==============================
123
- -- 6. 重建序列(新表 BIGSERIAL 自动创建了新序列)
124
- -- ==============================
125
- DO $$
126
- DECLARE
127
- max_id BIGINT;
128
- seq_name TEXT;
129
- BEGIN
130
- -- 获取新表自动创建的序列名
131
- SELECT pg_get_serial_sequence('public.transactions', 'id') INTO seq_name;
132
-
133
- -- 计算最大 ID
134
- SELECT COALESCE(MAX(id), 0) INTO max_id FROM public.transactions;
135
-
136
- -- 重启序列
137
- IF seq_name IS NOT NULL THEN
138
- EXECUTE format('ALTER SEQUENCE %s RESTART WITH %s', seq_name, max_id + 1);
139
- END IF;
140
- END $$;
141
-
142
- -- ==============================
143
- -- 7. 添加所有约束(旧约束已随 DROP TABLE 删除)
144
- -- ==============================
145
- ALTER TABLE public.transactions ADD CONSTRAINT transactions_order_id_key UNIQUE (order_id);
146
- ALTER TABLE public.transactions ADD CONSTRAINT transactions_pay_transaction_id_key UNIQUE (pay_transaction_id);
147
-
148
- ALTER TABLE public.transactions ADD CONSTRAINT transactions_order_status_check
149
- CHECK (order_status::text = ANY (ARRAY['created', 'pending_unpaid', 'success', 'refunded', 'canceled', 'failed']::text[]));
150
-
151
- ALTER TABLE public.transactions ADD CONSTRAINT transactions_pay_supplier_check
152
- CHECK (pay_supplier::text = ANY (ARRAY['Stripe', 'Apple', 'Paypal']::text[]));
153
-
154
- ALTER TABLE public.transactions ADD CONSTRAINT transactions_type_check
155
- CHECK (type::text = ANY (ARRAY['subscription', 'one_time']::text[]));
156
-
157
- ALTER TABLE public.transactions ADD CONSTRAINT transactions_payment_status_check
158
- CHECK (payment_status::text = ANY (ARRAY['un_paid', 'paid', 'no_payment_required']::text[]));
159
-
160
- ALTER TABLE public.transactions ADD CONSTRAINT transactions_deleted_check
161
- CHECK (deleted = ANY (ARRAY[0, 1]));
162
-
163
-
164
- -- ==============================
165
- -- 8. 提交
166
- -- ==============================
167
- COMMIT;