mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 04:31:13 -05:00
Fix: Correct database migrations
This commit is contained in:
@@ -638,6 +638,8 @@ export type Database = {
|
||||
first_reviewed_at: string | null
|
||||
id: string
|
||||
is_test_data: boolean | null
|
||||
last_modified_at: string | null
|
||||
last_modified_by: string | null
|
||||
locked_until: string | null
|
||||
original_submission_id: string | null
|
||||
resolved_at: string | null
|
||||
@@ -664,6 +666,8 @@ export type Database = {
|
||||
first_reviewed_at?: string | null
|
||||
id?: string
|
||||
is_test_data?: boolean | null
|
||||
last_modified_at?: string | null
|
||||
last_modified_by?: string | null
|
||||
locked_until?: string | null
|
||||
original_submission_id?: string | null
|
||||
resolved_at?: string | null
|
||||
@@ -690,6 +694,8 @@ export type Database = {
|
||||
first_reviewed_at?: string | null
|
||||
id?: string
|
||||
is_test_data?: boolean | null
|
||||
last_modified_at?: string | null
|
||||
last_modified_by?: string | null
|
||||
locked_until?: string | null
|
||||
original_submission_id?: string | null
|
||||
resolved_at?: string | null
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
-- Migration: Add conflict tracking to content_submissions
|
||||
|
||||
-- Add columns for optimistic locking
|
||||
ALTER TABLE public.content_submissions
|
||||
ADD COLUMN IF NOT EXISTS last_modified_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
ADD COLUMN IF NOT EXISTS last_modified_by UUID REFERENCES auth.users(id);
|
||||
|
||||
-- Create function to update modification tracking
|
||||
CREATE OR REPLACE FUNCTION public.update_content_submission_modified()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.last_modified_at = NOW();
|
||||
NEW.last_modified_by = auth.uid();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql SECURITY DEFINER SET search_path = public;
|
||||
|
||||
-- Create trigger
|
||||
DROP TRIGGER IF EXISTS trigger_update_submission_modified ON public.content_submissions;
|
||||
CREATE TRIGGER trigger_update_submission_modified
|
||||
BEFORE UPDATE ON public.content_submissions
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION public.update_content_submission_modified();
|
||||
|
||||
-- Add indexes for performance
|
||||
CREATE INDEX IF NOT EXISTS idx_content_submissions_last_modified
|
||||
ON public.content_submissions(last_modified_at);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_content_submissions_last_modified_by
|
||||
ON public.content_submissions(last_modified_by);
|
||||
Reference in New Issue
Block a user