From 4ae9ef53ff591d031353e35dc8486ed0cdb0b59b Mon Sep 17 00:00:00 2001 From: yml2213 Date: Fri, 31 Jul 2026 17:19:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=8B=E5=B9=B3=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/database/migrations/001_init.sql | 42 +++++++++---------- .../migrations/002_source_api_nonces.sql | 13 ------ .../migrations/003_drop_fulfillment_jobs.sql | 2 - .../migrations/004_delivery_links.sql | 6 --- .../migrations/005_delivery_links_revoked.sql | 6 --- .../006_order_request_fingerprint.sql | 5 --- 6 files changed, 19 insertions(+), 55 deletions(-) delete mode 100644 backend/internal/database/migrations/002_source_api_nonces.sql delete mode 100644 backend/internal/database/migrations/003_drop_fulfillment_jobs.sql delete mode 100644 backend/internal/database/migrations/004_delivery_links.sql delete mode 100644 backend/internal/database/migrations/005_delivery_links_revoked.sql delete mode 100644 backend/internal/database/migrations/006_order_request_fingerprint.sql diff --git a/backend/internal/database/migrations/001_init.sql b/backend/internal/database/migrations/001_init.sql index 3f4816e..ca3e679 100644 --- a/backend/internal/database/migrations/001_init.sql +++ b/backend/internal/database/migrations/001_init.sql @@ -95,6 +95,17 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_api_nonce ON api_request_nonces (api_clien CREATE INDEX IF NOT EXISTS idx_api_request_nonces_api_client_id ON api_request_nonces (api_client_id); CREATE INDEX IF NOT EXISTS idx_api_request_nonces_expires_at ON api_request_nonces (expires_at); +CREATE TABLE IF NOT EXISTS source_api_nonces ( + id BIGSERIAL PRIMARY KEY, + created_at TIMESTAMPTZ, + api_key VARCHAR(96) NOT NULL, + nonce VARCHAR(64) NOT NULL, + expires_at TIMESTAMPTZ NOT NULL +); + +CREATE UNIQUE INDEX IF NOT EXISTS idx_source_api_nonce ON source_api_nonces (api_key, nonce); +CREATE INDEX IF NOT EXISTS idx_source_api_nonces_expires_at ON source_api_nonces (expires_at); + -- ---------------------------------------------------------------------------- -- 商品目录与商户可售商品 -- ---------------------------------------------------------------------------- @@ -179,7 +190,7 @@ CREATE INDEX IF NOT EXISTS idx_wallet_ledger_entries_type ON wallet_ledger_entri CREATE INDEX IF NOT EXISTS idx_wallet_ledger_entries_reference_no ON wallet_ledger_entries (reference_no); -- ---------------------------------------------------------------------------- --- 履约订单与任务 +-- 履约订单 -- ---------------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS fulfillment_orders ( @@ -203,12 +214,15 @@ CREATE TABLE IF NOT EXISTS fulfillment_orders ( currency VARCHAR(12) NOT NULL DEFAULT 'POINT', order_status VARCHAR(16) NOT NULL DEFAULT 'paid', buyer_reference VARCHAR(128), + request_fingerprint VARCHAR(64) NOT NULL DEFAULT '', request_data TEXT, result_data TEXT, provider_order_no VARCHAR(96), failure_reason VARCHAR(512), cancelled_at TIMESTAMPTZ, - delivered_at TIMESTAMPTZ + delivered_at TIMESTAMPTZ, + delivery_link_expires_at TIMESTAMPTZ, + delivery_link_revoked_at TIMESTAMPTZ ); CREATE UNIQUE INDEX IF NOT EXISTS idx_fulfillment_orders_order_no ON fulfillment_orders (order_no); @@ -217,28 +231,10 @@ CREATE INDEX IF NOT EXISTS idx_fulfillment_orders_deleted_at ON fulfillment_orde CREATE INDEX IF NOT EXISTS idx_fulfillment_orders_merchant_id ON fulfillment_orders (merchant_id); CREATE INDEX IF NOT EXISTS idx_fulfillment_orders_merchant_product_id ON fulfillment_orders (merchant_product_id); CREATE INDEX IF NOT EXISTS idx_fulfillment_orders_order_status ON fulfillment_orders (order_status); +CREATE INDEX IF NOT EXISTS idx_fulfillment_orders_request_fingerprint ON fulfillment_orders (request_fingerprint); CREATE INDEX IF NOT EXISTS idx_fulfillment_orders_provider_order_no ON fulfillment_orders (provider_order_no); - -CREATE TABLE IF NOT EXISTS fulfillment_jobs ( - id BIGSERIAL PRIMARY KEY, - created_at TIMESTAMPTZ, - updated_at TIMESTAMPTZ, - merchant_id BIGINT NOT NULL, - order_id BIGINT NOT NULL, - status VARCHAR(16) NOT NULL DEFAULT 'pending', - attempts BIGINT NOT NULL DEFAULT 0, - next_run_at TIMESTAMPTZ NOT NULL, - provider_order_no VARCHAR(96), - request_payload TEXT, - result_payload TEXT, - last_error VARCHAR(512) -); - -CREATE UNIQUE INDEX IF NOT EXISTS idx_fulfillment_jobs_order_id ON fulfillment_jobs (order_id); -CREATE INDEX IF NOT EXISTS idx_fulfillment_jobs_merchant_id ON fulfillment_jobs (merchant_id); -CREATE INDEX IF NOT EXISTS idx_fulfillment_jobs_status ON fulfillment_jobs (status); -CREATE INDEX IF NOT EXISTS idx_fulfillment_jobs_next_run_at ON fulfillment_jobs (next_run_at); -CREATE INDEX IF NOT EXISTS idx_fulfillment_jobs_provider_order_no ON fulfillment_jobs (provider_order_no); +CREATE INDEX IF NOT EXISTS idx_fulfillment_orders_delivery_link_expires_at ON fulfillment_orders (delivery_link_expires_at); +CREATE INDEX IF NOT EXISTS idx_fulfillment_orders_delivery_link_revoked_at ON fulfillment_orders (delivery_link_revoked_at); -- ---------------------------------------------------------------------------- -- 回调订阅与投递(事务性 outbox) diff --git a/backend/internal/database/migrations/002_source_api_nonces.sql b/backend/internal/database/migrations/002_source_api_nonces.sql deleted file mode 100644 index f699550..0000000 --- a/backend/internal/database/migrations/002_source_api_nonces.sql +++ /dev/null @@ -1,13 +0,0 @@ --- 源头开放接口 nonce 防重,跨进程、跨重启生效。 -CREATE TABLE IF NOT EXISTS source_api_nonces ( - id BIGSERIAL PRIMARY KEY, - created_at TIMESTAMPTZ, - api_key VARCHAR(96) NOT NULL, - nonce VARCHAR(64) NOT NULL, - expires_at TIMESTAMPTZ NOT NULL -); - -CREATE UNIQUE INDEX IF NOT EXISTS idx_source_api_nonce - ON source_api_nonces (api_key, nonce); -CREATE INDEX IF NOT EXISTS idx_source_api_nonces_expires_at - ON source_api_nonces (expires_at); diff --git a/backend/internal/database/migrations/003_drop_fulfillment_jobs.sql b/backend/internal/database/migrations/003_drop_fulfillment_jobs.sql deleted file mode 100644 index aedef7a..0000000 --- a/backend/internal/database/migrations/003_drop_fulfillment_jobs.sql +++ /dev/null @@ -1,2 +0,0 @@ --- 当前履约流程由上游通过 URL 获取订单号后主动查单和回传结果,不再维护独立任务表。 -DROP TABLE IF EXISTS fulfillment_jobs; diff --git a/backend/internal/database/migrations/004_delivery_links.sql b/backend/internal/database/migrations/004_delivery_links.sql deleted file mode 100644 index 8e78d90..0000000 --- a/backend/internal/database/migrations/004_delivery_links.sql +++ /dev/null @@ -1,6 +0,0 @@ --- 为发货链接增加过期时间字段,支持签名短链与手动失效。 -ALTER TABLE fulfillment_orders - ADD COLUMN IF NOT EXISTS delivery_link_expires_at TIMESTAMPTZ; - -CREATE INDEX IF NOT EXISTS idx_fulfillment_orders_delivery_link_expires_at - ON fulfillment_orders (delivery_link_expires_at); diff --git a/backend/internal/database/migrations/005_delivery_links_revoked.sql b/backend/internal/database/migrations/005_delivery_links_revoked.sql deleted file mode 100644 index b624bc4..0000000 --- a/backend/internal/database/migrations/005_delivery_links_revoked.sql +++ /dev/null @@ -1,6 +0,0 @@ --- 为发货链接增加作废时间字段,确保作废后不会自动恢复。 -ALTER TABLE fulfillment_orders - ADD COLUMN IF NOT EXISTS delivery_link_revoked_at TIMESTAMPTZ; - -CREATE INDEX IF NOT EXISTS idx_fulfillment_orders_delivery_link_revoked_at - ON fulfillment_orders (delivery_link_revoked_at); diff --git a/backend/internal/database/migrations/006_order_request_fingerprint.sql b/backend/internal/database/migrations/006_order_request_fingerprint.sql deleted file mode 100644 index 4866221..0000000 --- a/backend/internal/database/migrations/006_order_request_fingerprint.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE fulfillment_orders - ADD COLUMN IF NOT EXISTS request_fingerprint VARCHAR(64) NOT NULL DEFAULT ''; - -CREATE INDEX IF NOT EXISTS idx_fulfillment_orders_request_fingerprint - ON fulfillment_orders (request_fingerprint);