fix: settle anonymous single-file reservations

This commit is contained in:
237899745
2026-07-26 05:47:54 +08:00
parent 65694cee15
commit 910e60ab59
4 changed files with 563 additions and 38 deletions

View File

@@ -0,0 +1,20 @@
CREATE TABLE anonymous_single_reservations (
task_id UUID PRIMARY KEY,
session_id VARCHAR(100) NOT NULL,
client_ip INET NOT NULL,
quota_date DATE NOT NULL,
units INTEGER NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'pending',
refund_after TIMESTAMPTZ NOT NULL DEFAULT (NOW() + INTERVAL '15 minutes'),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
settled_at TIMESTAMPTZ,
CONSTRAINT anonymous_single_reservations_units_check
CHECK (units > 0),
CONSTRAINT anonymous_single_reservations_status_check
CHECK (status IN ('pending', 'charged', 'refund_pending', 'refunded'))
);
CREATE INDEX anonymous_single_reservations_unsettled
ON anonymous_single_reservations(refund_after, created_at)
WHERE status IN ('pending', 'refund_pending');