Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
0b746501
Commit
0b746501
authored
Apr 16, 2026
by
陈曦
Browse files
1. merge upstream v0.1.113 2.提交migration相关文件
parents
45061102
be7551b9
Changes
225
Show whitespace changes
Inline
Side-by-side
backend/migration_release/095_channel_features.sql
0 → 100644
View file @
0b746501
ALTER
TABLE
channels
ADD
COLUMN
IF
NOT
EXISTS
features
TEXT
NOT
NULL
DEFAULT
''
;
COMMENT
ON
COLUMN
channels
.
features
IS
'渠道特性描述,JSON 数组格式,用于支付页面展示'
;
backend/migration_release/101_add_account_stats_pricing.sql
0 → 100644
View file @
0b746501
-- Account statistics pricing: allow channels to configure custom pricing for account cost tracking.
-- 1. Channel-level toggle
ALTER
TABLE
channels
ADD
COLUMN
IF
NOT
EXISTS
apply_pricing_to_account_stats
BOOLEAN
NOT
NULL
DEFAULT
FALSE
;
-- 2. Account stats pricing rules (ordered list per channel)
CREATE
TABLE
IF
NOT
EXISTS
channel_account_stats_pricing_rules
(
id
BIGSERIAL
PRIMARY
KEY
,
channel_id
BIGINT
NOT
NULL
REFERENCES
channels
(
id
)
ON
DELETE
CASCADE
,
name
VARCHAR
(
100
)
NOT
NULL
DEFAULT
''
,
group_ids
BIGINT
[]
NOT
NULL
DEFAULT
'{}'
,
account_ids
BIGINT
[]
NOT
NULL
DEFAULT
'{}'
,
sort_order
INT
NOT
NULL
DEFAULT
0
,
created_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
(),
updated_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
()
);
CREATE
INDEX
IF
NOT
EXISTS
idx_cas_pricing_rules_channel_id
ON
channel_account_stats_pricing_rules
(
channel_id
);
-- 3. Model pricing for each rule (same structure as channel_model_pricing)
CREATE
TABLE
IF
NOT
EXISTS
channel_account_stats_model_pricing
(
id
BIGSERIAL
PRIMARY
KEY
,
rule_id
BIGINT
NOT
NULL
REFERENCES
channel_account_stats_pricing_rules
(
id
)
ON
DELETE
CASCADE
,
platform
VARCHAR
(
50
)
NOT
NULL
DEFAULT
''
,
models
JSONB
NOT
NULL
DEFAULT
'[]'
,
billing_mode
VARCHAR
(
20
)
NOT
NULL
DEFAULT
'token'
,
input_price
NUMERIC
(
20
,
10
),
output_price
NUMERIC
(
20
,
10
),
cache_write_price
NUMERIC
(
20
,
10
),
cache_read_price
NUMERIC
(
20
,
10
),
image_output_price
NUMERIC
(
20
,
10
),
per_request_price
NUMERIC
(
20
,
10
),
created_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
(),
updated_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
()
);
CREATE
INDEX
IF
NOT
EXISTS
idx_cas_model_pricing_rule_id
ON
channel_account_stats_model_pricing
(
rule_id
);
-- 4. Usage logs: pre-computed account stats cost (NULL = use default formula)
ALTER
TABLE
usage_logs
ADD
COLUMN
IF
NOT
EXISTS
account_stats_cost
NUMERIC
(
20
,
10
);
backend/migration_release/101_add_balance_notify_fields.sql
0 → 100644
View file @
0b746501
-- Balance notification user preferences
ALTER
TABLE
users
ADD
COLUMN
IF
NOT
EXISTS
balance_notify_enabled
BOOLEAN
NOT
NULL
DEFAULT
true
;
ALTER
TABLE
users
ADD
COLUMN
IF
NOT
EXISTS
balance_notify_threshold
DECIMAL
(
20
,
8
)
DEFAULT
NULL
;
ALTER
TABLE
users
ADD
COLUMN
IF
NOT
EXISTS
balance_notify_extra_emails
TEXT
NOT
NULL
DEFAULT
'[]'
;
backend/migration_release/101_add_channel_features_config.sql
0 → 100644
View file @
0b746501
ALTER
TABLE
channels
ADD
COLUMN
IF
NOT
EXISTS
features_config
JSONB
NOT
NULL
DEFAULT
'{}'
;
COMMENT
ON
COLUMN
channels
.
features_config
IS
'渠道特性配置(如 web_search_emulation),JSON 对象格式'
;
backend/migration_release/102_add_balance_notify_threshold_type.sql
0 → 100644
View file @
0b746501
-- Add threshold type support (fixed / percentage) to balance notification
ALTER
TABLE
users
ADD
COLUMN
IF
NOT
EXISTS
balance_notify_threshold_type
VARCHAR
(
10
)
NOT
NULL
DEFAULT
'fixed'
;
-- Track cumulative recharge amount for percentage threshold calculation
ALTER
TABLE
users
ADD
COLUMN
IF
NOT
EXISTS
total_recharged
DECIMAL
(
20
,
8
)
NOT
NULL
DEFAULT
0
;
backend/migration_release/103_add_allow_user_refund.sql
0 → 100644
View file @
0b746501
ALTER
TABLE
payment_provider_instances
ADD
COLUMN
IF
NOT
EXISTS
allow_user_refund
BOOLEAN
NOT
NULL
DEFAULT
false
;
backend/migration_release/104_migrate_notify_emails_to_struct.sql
0 → 100644
View file @
0b746501
-- Migrate notification email lists from old []string format to new []NotifyEmailEntry format
-- Old: ["a@x.com", "b@x.com"]
-- New: [{"email":"a@x.com","disabled":false,"verified":true}, ...]
-- Existing emails are marked as verified=false (unverified), disabled=false (enabled)
-- 1. User balance notification emails
UPDATE
users
SET
balance_notify_extra_emails
=
(
SELECT
COALESCE
(
jsonb_agg
(
jsonb_build_object
(
'email'
,
elem
::
text
,
'disabled'
,
false
,
'verified'
,
false
)),
'[]'
::
jsonb
)::
text
FROM
jsonb_array_elements_text
(
balance_notify_extra_emails
::
jsonb
)
AS
elem
)
WHERE
balance_notify_extra_emails
IS
NOT
NULL
AND
balance_notify_extra_emails
<>
'[]'
AND
balance_notify_extra_emails
<>
''
AND
(
balance_notify_extra_emails
::
jsonb
->
0
)
IS
NOT
NULL
AND
jsonb_typeof
(
balance_notify_extra_emails
::
jsonb
->
0
)
=
'string'
;
-- 2. Admin account quota notification emails
UPDATE
settings
SET
value
=
(
SELECT
COALESCE
(
jsonb_agg
(
jsonb_build_object
(
'email'
,
elem
::
text
,
'disabled'
,
false
,
'verified'
,
false
)),
'[]'
::
jsonb
)::
text
FROM
jsonb_array_elements_text
(
value
::
jsonb
)
AS
elem
)
WHERE
key
=
'account_quota_notify_emails'
AND
value
IS
NOT
NULL
AND
value
<>
'[]'
AND
value
<>
''
AND
(
value
::
jsonb
->
0
)
IS
NOT
NULL
AND
jsonb_typeof
(
value
::
jsonb
->
0
)
=
'string'
;
backend/migration_release/105_migrate_websearch_emulation_to_tristate.sql
0 → 100644
View file @
0b746501
-- Convert old boolean web_search_emulation to tri-state string
-- true → "enabled", false → remove key (becomes "default")
UPDATE
accounts
SET
extra
=
(
extra
-
'web_search_emulation'
)
||
jsonb_build_object
(
'web_search_emulation'
,
'enabled'
)
WHERE
extra
?
'web_search_emulation'
AND
extra
->>
'web_search_emulation'
=
'true'
;
UPDATE
accounts
SET
extra
=
extra
-
'web_search_emulation'
WHERE
extra
?
'web_search_emulation'
AND
extra
->>
'web_search_emulation'
=
'false'
;
backend/migration_release/106_add_account_stats_pricing_intervals.sql
0 → 100644
View file @
0b746501
-- Add intervals table for account stats pricing rules (mirrors channel_pricing_intervals).
CREATE
TABLE
IF
NOT
EXISTS
channel_account_stats_pricing_intervals
(
id
BIGSERIAL
PRIMARY
KEY
,
pricing_id
BIGINT
NOT
NULL
REFERENCES
channel_account_stats_model_pricing
(
id
)
ON
DELETE
CASCADE
,
min_tokens
INT
NOT
NULL
DEFAULT
0
,
max_tokens
INT
,
tier_label
VARCHAR
(
50
),
input_price
NUMERIC
(
20
,
12
),
output_price
NUMERIC
(
20
,
12
),
cache_write_price
NUMERIC
(
20
,
12
),
cache_read_price
NUMERIC
(
20
,
12
),
per_request_price
NUMERIC
(
20
,
12
),
sort_order
INT
NOT
NULL
DEFAULT
0
,
created_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
(),
updated_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
()
);
CREATE
INDEX
IF
NOT
EXISTS
idx_account_stats_pricing_intervals_pricing_id
ON
channel_account_stats_pricing_intervals
(
pricing_id
);
backend/migration_release/107_add_account_cost_to_dashboard_tables.sql
0 → 100644
View file @
0b746501
-- Add account_cost column to dashboard aggregation tables for admin dashboard display.
-- account_cost = SUM(COALESCE(account_stats_cost, total_cost) * COALESCE(account_rate_multiplier, 1))
ALTER
TABLE
usage_dashboard_hourly
ADD
COLUMN
IF
NOT
EXISTS
account_cost
DECIMAL
(
20
,
10
)
NOT
NULL
DEFAULT
0
;
ALTER
TABLE
usage_dashboard_daily
ADD
COLUMN
IF
NOT
EXISTS
account_cost
DECIMAL
(
20
,
10
)
NOT
NULL
DEFAULT
0
;
backend/migrations/095_channel_features.sql
0 → 100644
View file @
0b746501
ALTER
TABLE
channels
ADD
COLUMN
IF
NOT
EXISTS
features
TEXT
NOT
NULL
DEFAULT
''
;
COMMENT
ON
COLUMN
channels
.
features
IS
'渠道特性描述,JSON 数组格式,用于支付页面展示'
;
backend/migrations/101_add_account_stats_pricing.sql
0 → 100644
View file @
0b746501
-- Account statistics pricing: allow channels to configure custom pricing for account cost tracking.
-- 1. Channel-level toggle
ALTER
TABLE
channels
ADD
COLUMN
IF
NOT
EXISTS
apply_pricing_to_account_stats
BOOLEAN
NOT
NULL
DEFAULT
FALSE
;
-- 2. Account stats pricing rules (ordered list per channel)
CREATE
TABLE
IF
NOT
EXISTS
channel_account_stats_pricing_rules
(
id
BIGSERIAL
PRIMARY
KEY
,
channel_id
BIGINT
NOT
NULL
REFERENCES
channels
(
id
)
ON
DELETE
CASCADE
,
name
VARCHAR
(
100
)
NOT
NULL
DEFAULT
''
,
group_ids
BIGINT
[]
NOT
NULL
DEFAULT
'{}'
,
account_ids
BIGINT
[]
NOT
NULL
DEFAULT
'{}'
,
sort_order
INT
NOT
NULL
DEFAULT
0
,
created_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
(),
updated_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
()
);
CREATE
INDEX
IF
NOT
EXISTS
idx_cas_pricing_rules_channel_id
ON
channel_account_stats_pricing_rules
(
channel_id
);
-- 3. Model pricing for each rule (same structure as channel_model_pricing)
CREATE
TABLE
IF
NOT
EXISTS
channel_account_stats_model_pricing
(
id
BIGSERIAL
PRIMARY
KEY
,
rule_id
BIGINT
NOT
NULL
REFERENCES
channel_account_stats_pricing_rules
(
id
)
ON
DELETE
CASCADE
,
platform
VARCHAR
(
50
)
NOT
NULL
DEFAULT
''
,
models
JSONB
NOT
NULL
DEFAULT
'[]'
,
billing_mode
VARCHAR
(
20
)
NOT
NULL
DEFAULT
'token'
,
input_price
NUMERIC
(
20
,
10
),
output_price
NUMERIC
(
20
,
10
),
cache_write_price
NUMERIC
(
20
,
10
),
cache_read_price
NUMERIC
(
20
,
10
),
image_output_price
NUMERIC
(
20
,
10
),
per_request_price
NUMERIC
(
20
,
10
),
created_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
(),
updated_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
()
);
CREATE
INDEX
IF
NOT
EXISTS
idx_cas_model_pricing_rule_id
ON
channel_account_stats_model_pricing
(
rule_id
);
-- 4. Usage logs: pre-computed account stats cost (NULL = use default formula)
ALTER
TABLE
usage_logs
ADD
COLUMN
IF
NOT
EXISTS
account_stats_cost
NUMERIC
(
20
,
10
);
backend/migrations/101_add_balance_notify_fields.sql
0 → 100644
View file @
0b746501
-- Balance notification user preferences
ALTER
TABLE
users
ADD
COLUMN
IF
NOT
EXISTS
balance_notify_enabled
BOOLEAN
NOT
NULL
DEFAULT
true
;
ALTER
TABLE
users
ADD
COLUMN
IF
NOT
EXISTS
balance_notify_threshold
DECIMAL
(
20
,
8
)
DEFAULT
NULL
;
ALTER
TABLE
users
ADD
COLUMN
IF
NOT
EXISTS
balance_notify_extra_emails
TEXT
NOT
NULL
DEFAULT
'[]'
;
backend/migrations/101_add_channel_features_config.sql
0 → 100644
View file @
0b746501
ALTER
TABLE
channels
ADD
COLUMN
IF
NOT
EXISTS
features_config
JSONB
NOT
NULL
DEFAULT
'{}'
;
COMMENT
ON
COLUMN
channels
.
features_config
IS
'渠道特性配置(如 web_search_emulation),JSON 对象格式'
;
backend/migrations/102_add_balance_notify_threshold_type.sql
0 → 100644
View file @
0b746501
-- Add threshold type support (fixed / percentage) to balance notification
ALTER
TABLE
users
ADD
COLUMN
IF
NOT
EXISTS
balance_notify_threshold_type
VARCHAR
(
10
)
NOT
NULL
DEFAULT
'fixed'
;
-- Track cumulative recharge amount for percentage threshold calculation
ALTER
TABLE
users
ADD
COLUMN
IF
NOT
EXISTS
total_recharged
DECIMAL
(
20
,
8
)
NOT
NULL
DEFAULT
0
;
backend/migrations/103_add_allow_user_refund.sql
0 → 100644
View file @
0b746501
ALTER
TABLE
payment_provider_instances
ADD
COLUMN
IF
NOT
EXISTS
allow_user_refund
BOOLEAN
NOT
NULL
DEFAULT
false
;
backend/migrations/104_migrate_notify_emails_to_struct.sql
0 → 100644
View file @
0b746501
-- Migrate notification email lists from old []string format to new []NotifyEmailEntry format
-- Old: ["a@x.com", "b@x.com"]
-- New: [{"email":"a@x.com","disabled":false,"verified":true}, ...]
-- Existing emails are marked as verified=false (unverified), disabled=false (enabled)
-- 1. User balance notification emails
UPDATE
users
SET
balance_notify_extra_emails
=
(
SELECT
COALESCE
(
jsonb_agg
(
jsonb_build_object
(
'email'
,
elem
::
text
,
'disabled'
,
false
,
'verified'
,
false
)),
'[]'
::
jsonb
)::
text
FROM
jsonb_array_elements_text
(
balance_notify_extra_emails
::
jsonb
)
AS
elem
)
WHERE
balance_notify_extra_emails
IS
NOT
NULL
AND
balance_notify_extra_emails
<>
'[]'
AND
balance_notify_extra_emails
<>
''
AND
(
balance_notify_extra_emails
::
jsonb
->
0
)
IS
NOT
NULL
AND
jsonb_typeof
(
balance_notify_extra_emails
::
jsonb
->
0
)
=
'string'
;
-- 2. Admin account quota notification emails
UPDATE
settings
SET
value
=
(
SELECT
COALESCE
(
jsonb_agg
(
jsonb_build_object
(
'email'
,
elem
::
text
,
'disabled'
,
false
,
'verified'
,
false
)),
'[]'
::
jsonb
)::
text
FROM
jsonb_array_elements_text
(
value
::
jsonb
)
AS
elem
)
WHERE
key
=
'account_quota_notify_emails'
AND
value
IS
NOT
NULL
AND
value
<>
'[]'
AND
value
<>
''
AND
(
value
::
jsonb
->
0
)
IS
NOT
NULL
AND
jsonb_typeof
(
value
::
jsonb
->
0
)
=
'string'
;
backend/migrations/105_migrate_websearch_emulation_to_tristate.sql
0 → 100644
View file @
0b746501
-- Convert old boolean web_search_emulation to tri-state string
-- true → "enabled", false → remove key (becomes "default")
UPDATE
accounts
SET
extra
=
(
extra
-
'web_search_emulation'
)
||
jsonb_build_object
(
'web_search_emulation'
,
'enabled'
)
WHERE
extra
?
'web_search_emulation'
AND
extra
->>
'web_search_emulation'
=
'true'
;
UPDATE
accounts
SET
extra
=
extra
-
'web_search_emulation'
WHERE
extra
?
'web_search_emulation'
AND
extra
->>
'web_search_emulation'
=
'false'
;
backend/migrations/106_add_account_stats_pricing_intervals.sql
0 → 100644
View file @
0b746501
-- Add intervals table for account stats pricing rules (mirrors channel_pricing_intervals).
CREATE
TABLE
IF
NOT
EXISTS
channel_account_stats_pricing_intervals
(
id
BIGSERIAL
PRIMARY
KEY
,
pricing_id
BIGINT
NOT
NULL
REFERENCES
channel_account_stats_model_pricing
(
id
)
ON
DELETE
CASCADE
,
min_tokens
INT
NOT
NULL
DEFAULT
0
,
max_tokens
INT
,
tier_label
VARCHAR
(
50
),
input_price
NUMERIC
(
20
,
12
),
output_price
NUMERIC
(
20
,
12
),
cache_write_price
NUMERIC
(
20
,
12
),
cache_read_price
NUMERIC
(
20
,
12
),
per_request_price
NUMERIC
(
20
,
12
),
sort_order
INT
NOT
NULL
DEFAULT
0
,
created_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
(),
updated_at
TIMESTAMPTZ
NOT
NULL
DEFAULT
NOW
()
);
CREATE
INDEX
IF
NOT
EXISTS
idx_account_stats_pricing_intervals_pricing_id
ON
channel_account_stats_pricing_intervals
(
pricing_id
);
backend/migrations/107_add_account_cost_to_dashboard_tables.sql
0 → 100644
View file @
0b746501
-- Add account_cost column to dashboard aggregation tables for admin dashboard display.
-- account_cost = SUM(COALESCE(account_stats_cost, total_cost) * COALESCE(account_rate_multiplier, 1))
ALTER
TABLE
usage_dashboard_hourly
ADD
COLUMN
IF
NOT
EXISTS
account_cost
DECIMAL
(
20
,
10
)
NOT
NULL
DEFAULT
0
;
ALTER
TABLE
usage_dashboard_daily
ADD
COLUMN
IF
NOT
EXISTS
account_cost
DECIMAL
(
20
,
10
)
NOT
NULL
DEFAULT
0
;
Prev
1
…
4
5
6
7
8
9
10
11
12
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment