feat: support basic user system
This commit is contained in:
53
db/migration/000002_v2.down.sql
Normal file
53
db/migration/000002_v2.down.sql
Normal file
@@ -0,0 +1,53 @@
|
||||
-- remove user reference from orders
|
||||
ALTER TABLE orders
|
||||
DROP COLUMN IF EXISTS user_id;
|
||||
|
||||
-- remove agent columns from validations
|
||||
ALTER TABLE validations
|
||||
DROP COLUMN IF EXISTS agent_risk_notice;
|
||||
|
||||
ALTER TABLE validations
|
||||
DROP COLUMN IF EXISTS agent_delivery_advice;
|
||||
|
||||
ALTER TABLE validations
|
||||
DROP COLUMN IF EXISTS agent_continue_trade_advice;
|
||||
|
||||
ALTER TABLE validations
|
||||
DROP COLUMN IF EXISTS agent_validation_explanation;
|
||||
|
||||
-- remove agent columns from pricing_results
|
||||
ALTER TABLE pricing_results
|
||||
DROP COLUMN IF EXISTS agent_next_action;
|
||||
|
||||
ALTER TABLE pricing_results
|
||||
DROP COLUMN IF EXISTS agent_budget_advice;
|
||||
|
||||
ALTER TABLE pricing_results
|
||||
DROP COLUMN IF EXISTS agent_risk_advice;
|
||||
|
||||
ALTER TABLE pricing_results
|
||||
DROP COLUMN IF EXISTS agent_task_match_explanation;
|
||||
|
||||
-- remove user reference from buyer_requests
|
||||
ALTER TABLE buyer_requests
|
||||
DROP COLUMN IF EXISTS user_id;
|
||||
|
||||
-- remove agent columns from data_assets
|
||||
ALTER TABLE data_assets
|
||||
DROP COLUMN IF EXISTS agent_asset_explanation;
|
||||
|
||||
ALTER TABLE data_assets
|
||||
DROP COLUMN IF EXISTS agent_risk_per_mission_advice;
|
||||
|
||||
ALTER TABLE data_assets
|
||||
DROP COLUMN IF EXISTS agent_recommended_tasks;
|
||||
|
||||
ALTER TABLE data_assets
|
||||
DROP COLUMN IF EXISTS agent_asset_summary;
|
||||
|
||||
-- remove user reference from data_assets
|
||||
ALTER TABLE data_assets
|
||||
DROP COLUMN IF EXISTS user_id;
|
||||
|
||||
-- drop users table
|
||||
DROP TABLE IF EXISTS users;
|
||||
77
db/migration/000002_v2.up.sql
Normal file
77
db/migration/000002_v2.up.sql
Normal file
@@ -0,0 +1,77 @@
|
||||
-- new user table
|
||||
CREATE TABLE IF NOT EXISTS users
|
||||
(
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
username text NOT NULL UNIQUE,
|
||||
password text NOT NULL,
|
||||
role text NOT NULL, -- admin user
|
||||
display_name text NOT NULL,
|
||||
account_status text NOT NULL DEFAULT 'active',
|
||||
last_login_at timestamptz,
|
||||
created_at timestamptz DEFAULT now()
|
||||
);
|
||||
|
||||
-- add user reference to data_assets
|
||||
ALTER TABLE data_assets
|
||||
ADD COLUMN IF NOT EXISTS user_id uuid REFERENCES users (id);
|
||||
|
||||
-- add agent columns to data_assets
|
||||
ALTER TABLE data_assets
|
||||
ADD COLUMN IF NOT EXISTS agent_asset_summary text;
|
||||
COMMENT ON COLUMN data_assets.agent_asset_summary IS '智能助手对当前资产的简短画像总结';
|
||||
|
||||
ALTER TABLE data_assets
|
||||
ADD COLUMN IF NOT EXISTS agent_recommended_tasks jsonb;
|
||||
COMMENT ON COLUMN data_assets.agent_recommended_tasks IS '推荐的适用任务列表';
|
||||
|
||||
ALTER TABLE data_assets
|
||||
ADD COLUMN IF NOT EXISTS agent_risk_per_mission_advice text;
|
||||
COMMENT ON COLUMN data_assets.agent_risk_per_mission_advice IS '当前资产更适合的权限与风险建议';
|
||||
|
||||
ALTER TABLE data_assets
|
||||
ADD COLUMN IF NOT EXISTS agent_asset_explanation text;
|
||||
COMMENT ON COLUMN data_assets.agent_asset_explanation IS '为什么该资产当前基础价值较高/中/低';
|
||||
|
||||
-- add user reference to buyer_requests
|
||||
ALTER TABLE buyer_requests
|
||||
ADD COLUMN IF NOT EXISTS user_id uuid REFERENCES users (id);
|
||||
|
||||
-- add agent to pricing_results
|
||||
ALTER TABLE pricing_results
|
||||
ADD COLUMN IF NOT EXISTS agent_task_match_explanation text;
|
||||
COMMENT ON COLUMN pricing_results.agent_task_match_explanation IS '解释当前数据与任务的匹配关系';
|
||||
|
||||
ALTER TABLE pricing_results
|
||||
ADD COLUMN IF NOT EXISTS agent_risk_advice text;
|
||||
COMMENT ON COLUMN pricing_results.agent_risk_advice IS '解释当前隐私风险与权限建议';
|
||||
|
||||
ALTER TABLE pricing_results
|
||||
ADD COLUMN IF NOT EXISTS agent_budget_advice text;
|
||||
COMMENT ON COLUMN pricing_results.agent_budget_advice IS '根据预算给出的建议';
|
||||
|
||||
ALTER TABLE pricing_results
|
||||
ADD COLUMN IF NOT EXISTS agent_next_action text;
|
||||
COMMENT ON COLUMN pricing_results.agent_next_action IS '建议接下来做什么';
|
||||
|
||||
-- add agent to
|
||||
ALTER TABLE validations
|
||||
ADD COLUMN IF NOT EXISTS agent_validation_explanation text;
|
||||
COMMENT ON COLUMN validations.agent_validation_explanation IS '对当前验证结果的自然语言解释';
|
||||
|
||||
ALTER TABLE validations
|
||||
ADD COLUMN IF NOT EXISTS agent_continue_trade_advice text;
|
||||
COMMENT ON COLUMN validations.agent_continue_trade_advice IS '对是否继续成交的建议';
|
||||
|
||||
ALTER TABLE validations
|
||||
ADD COLUMN IF NOT EXISTS agent_delivery_advice text;
|
||||
COMMENT ON COLUMN validations.agent_delivery_advice IS '对交付方式的建议';
|
||||
|
||||
ALTER TABLE validations
|
||||
ADD COLUMN IF NOT EXISTS agent_risk_notice text;
|
||||
COMMENT ON COLUMN validations.agent_risk_notice IS '对后续交易的风险提示';
|
||||
|
||||
-- add user to order
|
||||
ALTER TABLE orders
|
||||
ADD COLUMN IF NOT EXISTS user_id uuid REFERENCES users (id);
|
||||
|
||||
|
||||
1
db/migration/000003_add_jwt_config.down.sql
Normal file
1
db/migration/000003_add_jwt_config.down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS config;
|
||||
11
db/migration/000003_add_jwt_config.up.sql
Normal file
11
db/migration/000003_add_jwt_config.up.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
-- add config(jwt)
|
||||
CREATE TABLE IF NOT EXISTS config
|
||||
(
|
||||
id integer PRIMARY KEY, -- always 0
|
||||
"Jwt.Alg" text NOT NULL DEFAULT 'HS256',
|
||||
"Jwt.SignKey" text NOT NULL DEFAULT gen_random_uuid(),
|
||||
"Jwt.VerifyKye" text DEFAULT NULL
|
||||
);
|
||||
|
||||
INSERT INTO config (id)
|
||||
VALUES (0);
|
||||
4
db/query/config.sql
Normal file
4
db/query/config.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
-- name: GetConfig :one
|
||||
SELECT *
|
||||
FROM config
|
||||
WHERE id = 0;
|
||||
@@ -53,12 +53,12 @@ WHERE (
|
||||
);
|
||||
|
||||
-- name: GetDataAsset :one
|
||||
SELECT id, asset_name, asset_type, domain, application_scene, data_description, data_scale, collection_method, labeling_status, update_frequency, privacy_level, permission_mode, supports_validation, seller_expected_price_min, seller_expected_price_max, quality_level, scarcity_level, base_value_score, base_price_min, base_price_max, asset_status, created_at, updated_at
|
||||
SELECT *
|
||||
FROM data_assets
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: ListDataAssets :many
|
||||
SELECT id, asset_name, asset_type, domain, application_scene, data_description, data_scale, collection_method, labeling_status, update_frequency, privacy_level, permission_mode, supports_validation, seller_expected_price_min, seller_expected_price_max, quality_level, scarcity_level, base_value_score, base_price_min, base_price_max, asset_status, created_at, updated_at
|
||||
SELECT *
|
||||
FROM data_assets
|
||||
WHERE (
|
||||
NULLIF(sqlc.narg(keyword)::text, '') IS NULL
|
||||
@@ -89,7 +89,7 @@ UPDATE data_assets
|
||||
SET asset_status = $2,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, asset_name, asset_type, domain, application_scene, data_description, data_scale, collection_method, labeling_status, update_frequency, privacy_level, permission_mode, supports_validation, seller_expected_price_min, seller_expected_price_max, quality_level, scarcity_level, base_value_score, base_price_min, base_price_max, asset_status, created_at, updated_at;
|
||||
RETURNING *;
|
||||
|
||||
-- name: CreateBuyerRequest :one
|
||||
INSERT INTO buyer_requests (
|
||||
@@ -104,15 +104,15 @@ INSERT INTO buyer_requests (
|
||||
request_status
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||
RETURNING id, asset_id, task_type, model_type, buyer_budget_min, buyer_budget_max, privacy_requirement, usage_purpose, request_note, request_status, created_at, updated_at;
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetBuyerRequest :one
|
||||
SELECT id, asset_id, task_type, model_type, buyer_budget_min, buyer_budget_max, privacy_requirement, usage_purpose, request_note, request_status, created_at, updated_at
|
||||
SELECT *
|
||||
FROM buyer_requests
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: ListBuyerRequests :many
|
||||
SELECT id, asset_id, task_type, model_type, buyer_budget_min, buyer_budget_max, privacy_requirement, usage_purpose, request_note, request_status, created_at, updated_at
|
||||
SELECT *
|
||||
FROM buyer_requests
|
||||
ORDER BY created_at DESC, id DESC
|
||||
LIMIT $1 OFFSET $2;
|
||||
@@ -133,15 +133,15 @@ INSERT INTO pricing_results (
|
||||
pricing_status
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
||||
RETURNING id, asset_id, request_id, scenario_value_score, scenario_price_min, scenario_price_max, suggested_price, success_probability, pricing_reason_1, pricing_reason_2, pricing_reason_3, verification_suggestion, pricing_status, created_at, updated_at;
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetPricingResult :one
|
||||
SELECT id, asset_id, request_id, scenario_value_score, scenario_price_min, scenario_price_max, suggested_price, success_probability, pricing_reason_1, pricing_reason_2, pricing_reason_3, verification_suggestion, pricing_status, created_at, updated_at
|
||||
SELECT *
|
||||
FROM pricing_results
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: ListPricingResults :many
|
||||
SELECT id, asset_id, request_id, scenario_value_score, scenario_price_min, scenario_price_max, suggested_price, success_probability, pricing_reason_1, pricing_reason_2, pricing_reason_3, verification_suggestion, pricing_status, created_at, updated_at
|
||||
SELECT *
|
||||
FROM pricing_results
|
||||
ORDER BY created_at DESC, id DESC
|
||||
LIMIT $1 OFFSET $2;
|
||||
@@ -160,7 +160,7 @@ INSERT INTO validations (
|
||||
validation_finished_at
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
RETURNING id, asset_id, request_id, validation_type, validation_requested, validation_status, validation_signal, validation_score, risk_warning, continue_recommendation, validation_created_at, validation_finished_at;
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateValidationResult :one
|
||||
UPDATE validations
|
||||
@@ -171,15 +171,15 @@ SET validation_status = $2,
|
||||
continue_recommendation = $6,
|
||||
validation_finished_at = $7
|
||||
WHERE id = $1
|
||||
RETURNING id, asset_id, request_id, validation_type, validation_requested, validation_status, validation_signal, validation_score, risk_warning, continue_recommendation, validation_created_at, validation_finished_at;
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetValidation :one
|
||||
SELECT id, asset_id, request_id, validation_type, validation_requested, validation_status, validation_signal, validation_score, risk_warning, continue_recommendation, validation_created_at, validation_finished_at
|
||||
SELECT *
|
||||
FROM validations
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: ListValidations :many
|
||||
SELECT id, asset_id, request_id, validation_type, validation_requested, validation_status, validation_signal, validation_score, risk_warning, continue_recommendation, validation_created_at, validation_finished_at
|
||||
SELECT *
|
||||
FROM validations
|
||||
ORDER BY validation_created_at DESC, id DESC
|
||||
LIMIT $1 OFFSET $2;
|
||||
@@ -203,15 +203,15 @@ INSERT INTO orders (
|
||||
order_status
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
||||
RETURNING id, asset_id, request_id, pricing_id, validation_id, asset_name, current_price, negotiation_min, negotiation_max, validation_used, delivery_mode, order_status, order_created_at, order_updated_at;
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetOrder :one
|
||||
SELECT id, asset_id, request_id, pricing_id, validation_id, asset_name, current_price, negotiation_min, negotiation_max, validation_used, delivery_mode, order_status, order_created_at, order_updated_at
|
||||
SELECT *
|
||||
FROM orders
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: ListOrders :many
|
||||
SELECT id, asset_id, request_id, pricing_id, validation_id, asset_name, current_price, negotiation_min, negotiation_max, validation_used, delivery_mode, order_status, order_created_at, order_updated_at
|
||||
SELECT *
|
||||
FROM orders
|
||||
WHERE NULLIF(sqlc.narg(order_status)::text, '') IS NULL
|
||||
OR order_status = sqlc.narg(order_status)::text
|
||||
@@ -229,4 +229,4 @@ UPDATE orders
|
||||
SET order_status = $2,
|
||||
order_updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, asset_id, request_id, pricing_id, validation_id, asset_name, current_price, negotiation_min, negotiation_max, validation_used, delivery_mode, order_status, order_created_at, order_updated_at;
|
||||
RETURNING *;
|
||||
|
||||
4
db/query/user.sql
Normal file
4
db/query/user.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
-- name: GetUserByUsername :one
|
||||
SELECT *
|
||||
FROM users
|
||||
WHERE username = $1;
|
||||
Reference in New Issue
Block a user