Remove old approval flow

Implement the destructive migration plan to remove the old approval flow entirely. This includes deleting the legacy edge function, removing the toggle component, simplifying frontend code, and updating documentation.
This commit is contained in:
gpt-engineer-app[bot]
2025-11-06 21:14:59 +00:00
parent 406edc96df
commit bd2f9a5a9e
8 changed files with 197 additions and 3124 deletions

View File

@@ -178,41 +178,31 @@ export async function approvePhotoSubmission(
* @returns Action result
*/
/**
* Feature flag: Use new atomic transaction RPC for approvals (v2)
* Approve submission items using atomic transaction RPC.
*
* ✅ DEFAULT: NEW atomic transaction flow (100% ROLLOUT)
* This function uses PostgreSQL's ACID transaction guarantees to ensure
* all-or-nothing approval with automatic rollback on any error.
*
* Benefits of v2:
* The approval process is handled entirely within a single database transaction
* via the process_approval_transaction() RPC function, which guarantees:
* - True atomic transactions (all-or-nothing)
* - Automatic rollback on ANY error
* - Network-resilient (edge function crash = auto rollback)
* - Eliminates orphaned entities
*
* To disable NEW flow (emergency rollback): localStorage.setItem('use_rpc_approval', 'false')
* To re-enable NEW flow: localStorage.removeItem('use_rpc_approval')
* - Zero orphaned entities
*/
const USE_RPC_APPROVAL = typeof window !== 'undefined' &&
localStorage.getItem('use_rpc_approval') !== 'false';
export async function approveSubmissionItems(
supabase: SupabaseClient,
submissionId: string,
itemIds: string[]
): Promise<ModerationActionResult> {
try {
// Use v2 edge function if feature flag is enabled
const edgeFunctionName = USE_RPC_APPROVAL
? 'process-selective-approval-v2'
: 'process-selective-approval';
console.log(`[Approval] Using edge function: ${edgeFunctionName}`, {
console.log(`[Approval] Processing ${itemIds.length} items via atomic transaction`, {
submissionId,
itemCount: itemIds.length,
useRpcApproval: USE_RPC_APPROVAL
itemCount: itemIds.length
});
const { data: approvalData, error: approvalError, requestId } = await invokeWithTracking(
edgeFunctionName,
'process-selective-approval',
{
itemIds,
submissionId,