-- Drop old JSONB versioning system completely
-- This removes all deprecated tables and functions

-- Drop dependent tables first
DROP TABLE IF EXISTS public.version_diffs CASCADE;
DROP TABLE IF EXISTS public.entity_relationships_history CASCADE;
DROP TABLE IF EXISTS public.entity_field_history CASCADE;

-- Drop main legacy table (archive remains)
DROP TABLE IF EXISTS public.entity_versions CASCADE;

-- Drop old RPC functions
DROP FUNCTION IF EXISTS public.create_entity_version(
  text, uuid, jsonb, uuid, text, uuid, version_change_type
) CASCADE;

DROP FUNCTION IF EXISTS public.compare_versions(uuid, uuid) CASCADE;

DROP FUNCTION IF EXISTS public.create_field_history_entries(uuid, jsonb, jsonb) CASCADE;

-- Note: We keep rollback_to_version as it's been updated for relational system