feat: add model groups, verified registration and CNY credit grants
This commit is contained in:
1 parent
f5ba6cb255
commit
7a18db2123
40 files changed
+1980
-263
No files matched your search
+58
@@ -0,0 +1,58 @@
|
||||
CREATE TABLE model_definitions (
|
||||
id varchar(64) PRIMARY KEY,
|
||||
model_key varchar(160),
|
||||
public_name varchar(160) NOT NULL,
|
||||
model_type varchar(24) NOT NULL,
|
||||
call_mode varchar(16) NOT NULL,
|
||||
description text NOT NULL DEFAULT '',
|
||||
input_types jsonb NOT NULL DEFAULT '[]',
|
||||
output_types jsonb NOT NULL DEFAULT '[]',
|
||||
status varchar(16) NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'disabled')),
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
-- Keep existing route IDs and key grants intact. Do not guess which legacy names are identical models.
|
||||
INSERT INTO model_definitions (id, model_key, public_name, model_type, call_mode, description, input_types, output_types, status)
|
||||
SELECT id, model_key, public_name, model_type, call_mode, description, input_types, output_types, status FROM model_catalog;
|
||||
ALTER TABLE model_catalog ADD COLUMN logical_model_id varchar(64) REFERENCES model_definitions(id);
|
||||
UPDATE model_catalog SET logical_model_id = id;
|
||||
ALTER TABLE model_catalog ALTER COLUMN logical_model_id SET NOT NULL;
|
||||
UPDATE model_catalog SET source_label = '默认分组' WHERE source_label IS NULL OR trim(source_label) = '';
|
||||
CREATE INDEX model_catalog_logical_idx ON model_catalog(logical_model_id);
|
||||
CREATE UNIQUE INDEX model_catalog_group_name_idx ON model_catalog(logical_model_id, source_label);
|
||||
|
||||
CREATE TABLE user_wallets (
|
||||
user_id uuid PRIMARY KEY REFERENCES users(id),
|
||||
balance numeric(20,8) NOT NULL DEFAULT 0 CHECK (balance >= 0),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE TABLE wallet_entries (
|
||||
id uuid PRIMARY KEY,
|
||||
user_id uuid NOT NULL REFERENCES users(id),
|
||||
actor_user_id uuid NOT NULL REFERENCES users(id),
|
||||
request_id uuid NOT NULL UNIQUE,
|
||||
amount numeric(20,8) NOT NULL CHECK (amount > 0),
|
||||
balance_after numeric(20,8) NOT NULL,
|
||||
currency varchar(3) NOT NULL DEFAULT 'CNY' CHECK (currency = 'CNY'),
|
||||
reason varchar(500) NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE INDEX wallet_entries_user_idx ON wallet_entries(user_id, created_at DESC);
|
||||
|
||||
CREATE TABLE registration_codes (
|
||||
account varchar(254) PRIMARY KEY,
|
||||
code_hash char(64) NOT NULL,
|
||||
expires_at timestamptz NOT NULL,
|
||||
attempts integer NOT NULL DEFAULT 0,
|
||||
consumed boolean NOT NULL DEFAULT false,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE TABLE verification_send_events (
|
||||
id uuid PRIMARY KEY,
|
||||
account varchar(254) NOT NULL,
|
||||
ip_address varchar(128) NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE INDEX verification_send_account_idx ON verification_send_events(account, created_at);
|
||||
CREATE INDEX verification_send_ip_idx ON verification_send_events(ip_address, created_at);
|
||||
Reference in new issue
Block a user