feat: implement brand asset cleanup event handling and reconciliation logic
Backend CI / Backend (push) Failing after 6m54s
Backend CI / Backend (push) Failing after 6m54s
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
DROP INDEX IF EXISTS idx_brands_deleting_cleanup_candidate;
|
||||
DROP INDEX IF EXISTS idx_brand_asset_cleanup_events_processing;
|
||||
|
||||
DROP TABLE IF EXISTS brand_asset_cleanup_events;
|
||||
@@ -0,0 +1,36 @@
|
||||
CREATE TABLE IF NOT EXISTS brand_asset_cleanup_events (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
tenant_id BIGINT NOT NULL,
|
||||
brand_id BIGINT NOT NULL,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'pending',
|
||||
attempts INT NOT NULL DEFAULT 0,
|
||||
next_attempt_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
last_error TEXT,
|
||||
locked_at TIMESTAMPTZ,
|
||||
locked_by TEXT,
|
||||
processed_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CHECK (status IN ('pending', 'processing', 'success', 'failed'))
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uk_brand_asset_cleanup_events_active
|
||||
ON brand_asset_cleanup_events (tenant_id, brand_id)
|
||||
WHERE status IN ('pending', 'processing', 'failed');
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_brand_asset_cleanup_events_pending
|
||||
ON brand_asset_cleanup_events (next_attempt_at, id)
|
||||
INCLUDE (tenant_id, brand_id)
|
||||
WHERE status IN ('pending', 'failed');
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_brand_asset_cleanup_events_processing
|
||||
ON brand_asset_cleanup_events (locked_at, id)
|
||||
INCLUDE (tenant_id, brand_id)
|
||||
WHERE status = 'processing'
|
||||
AND locked_at IS NOT NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_brands_deleting_cleanup_candidate
|
||||
ON brands (deleted_at, id)
|
||||
INCLUDE (tenant_id)
|
||||
WHERE status = 'deleting'
|
||||
AND deleted_at IS NOT NULL;
|
||||
Reference in New Issue
Block a user