mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 10:31:13 -05:00
Fix: Remove deprecated versioning helpers
This commit is contained in:
@@ -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',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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);
|
||||||
Reference in New Issue
Block a user