Fix: Remove deprecated versioning helpers

This commit is contained in:
gpt-engineer-app[bot]
2025-10-15 18:14:42 +00:00
parent 8f56f608f7
commit 455c1da203
2 changed files with 30 additions and 44 deletions

View File

@@ -240,6 +240,13 @@ export async function approveSubmissionItems(
/** /**
* Create version history for approved submission item * Create version history for approved submission item
*
* NOTE: Versions are now created automatically via database triggers.
* This function is no longer needed since the relational versioning system
* handles version creation automatically when entities are inserted/updated.
*
* The trigger `create_relational_version()` reads session variables set by
* the edge function and creates versions in the appropriate `*_versions` table.
*/ */
async function createVersionForApprovedItem( async function createVersionForApprovedItem(
itemType: string, itemType: string,
@@ -248,50 +255,14 @@ async function createVersionForApprovedItem(
submissionId: string, submissionId: string,
isEdit: boolean isEdit: boolean
): Promise<void> { ): Promise<void> {
const { captureCurrentState, createEntityVersion } = await import('./versioningHelpers'); // No-op: Versions are created automatically by triggers
// The edge function sets:
// Map item_type to entity_type // - app.current_user_id = original submitter
let entityType: 'park' | 'ride' | 'company' | 'ride_model'; // - app.submission_id = submission ID
switch (itemType) { // Then the trigger creates the version automatically
case 'park': console.debug(
entityType = 'park'; `Version will be created automatically by trigger for ${itemType} ${entityId}`
break; );
case 'ride':
entityType = 'ride';
break;
case 'manufacturer':
case 'operator':
case 'property_owner':
case 'designer':
entityType = 'company';
break;
case 'ride_model':
entityType = 'ride_model';
break;
default:
console.warn(`Unknown entity type for versioning: ${itemType}`);
return;
}
// Capture current state
const currentState = await captureCurrentState(entityType, entityId);
if (!currentState) {
console.warn(`Failed to capture state for ${entityType} ${entityId}`);
return;
}
// Create version
await createEntityVersion({
entityType,
entityId,
versionData: currentState,
changedBy: userId,
changeReason: isEdit
? `Approved edit from submission #${submissionId.slice(0, 8)}`
: `Created via submission #${submissionId.slice(0, 8)}`,
submissionId,
changeType: isEdit ? 'updated' : 'created',
});
} }
/** /**

View File

@@ -0,0 +1,15 @@
-- Enable RLS on the archive table
ALTER TABLE public.entity_versions_archive ENABLE ROW LEVEL SECURITY;
-- Create RLS policies for the archive table (same as original)
CREATE POLICY "Moderators can view all archived versions"
ON public.entity_versions_archive
FOR SELECT
TO authenticated
USING (is_moderator(auth.uid()));
CREATE POLICY "Public can view current archived versions"
ON public.entity_versions_archive
FOR SELECT
TO authenticated
USING (is_current = true);