-- =====================================================
-- Migration Script: Move Non-Laravel Tables to Archive
-- =====================================================
-- This script creates a new schema 'public_archiv' and
-- moves all tables that were not created by Laravel
-- migrations from the 'public' schema to 'public_archiv'.
-- =====================================================

-- Step 1: Create new schema
CREATE SCHEMA IF NOT EXISTS public_archiv;

-- Step 2: Move tables to public_archiv schema
-- (28 tables that were not created by Laravel migrations)

ALTER TABLE public.alembic_version SET SCHEMA public_archiv;
ALTER TABLE public.bundesanzeiger_cache SET SCHEMA public_archiv;
ALTER TABLE public.companies_view SET SCHEMA public_archiv;
ALTER TABLE public.company_gleif_cache SET SCHEMA public_archiv;
ALTER TABLE public.company_master_data SET SCHEMA public_archiv;
ALTER TABLE public.company_master_data_links SET SCHEMA public_archiv;
ALTER TABLE public.company_opencorporates_cache SET SCHEMA public_archiv;
ALTER TABLE public.company_registry_cache SET SCHEMA public_archiv;
ALTER TABLE public.dpma_cache SET SCHEMA public_archiv;
ALTER TABLE public.entity_corporate_context SET SCHEMA public_archiv;
ALTER TABLE public.eu_sanctions_cache SET SCHEMA public_archiv;
ALTER TABLE public.evidence_registry SET SCHEMA public_archiv;
ALTER TABLE public.genesis_cache SET SCHEMA public_archiv;
ALTER TABLE public.govdata_cache SET SCHEMA public_archiv;
ALTER TABLE public.handelsregister_cache SET SCHEMA public_archiv;
ALTER TABLE public.handelsregister_document_links SET SCHEMA public_archiv;
ALTER TABLE public.handelsregister_documents SET SCHEMA public_archiv;
ALTER TABLE public.handelsregister_entities SET SCHEMA public_archiv;
ALTER TABLE public.handelsregister_entity_transactions SET SCHEMA public_archiv;
ALTER TABLE public.handelsregister_relations SET SCHEMA public_archiv;
ALTER TABLE public.insolvency_cache SET SCHEMA public_archiv;
ALTER TABLE public.pep_cache SET SCHEMA public_archiv;
ALTER TABLE public.prompt_runs SET SCHEMA public_archiv;
ALTER TABLE public.prompt_templates SET SCHEMA public_archiv;
ALTER TABLE public.rss_cache SET SCHEMA public_archiv;
ALTER TABLE public.sanctions_cache SET SCHEMA public_archiv;
ALTER TABLE public.test_transaction_llm SET SCHEMA public_archiv;
ALTER TABLE public.transaction SET SCHEMA public_archiv;
ALTER TABLE public.transaction_outputs SET SCHEMA public_archiv;
ALTER TABLE public.transactions_enriched SET SCHEMA public_archiv;

-- =====================================================
-- Verification Queries
-- =====================================================

-- Check tables in public_archiv schema
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public_archiv'
ORDER BY table_name;

-- Check remaining tables in public schema (should only be Laravel tables)
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY table_name;

-- Count tables per schema
SELECT
    table_schema,
    COUNT(*) as table_count
FROM information_schema.tables
WHERE table_schema IN ('public', 'public_archiv')
GROUP BY table_schema;
