fix: move SQL queries from database/ to docs/queries
SQL query files (playground, test queries) are development documentation, not production database files. They belong in docs/ alongside other documentation.
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
-- =====================================================
|
||||
-- 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;
|
||||
@@ -1,18 +0,0 @@
|
||||
SELECT * FROM public.test_transaction_llm
|
||||
ORDER BY id ASC ;
|
||||
|
||||
|
||||
select * from backend.transactions;
|
||||
|
||||
Select * from
|
||||
backend.transactions as t
|
||||
left join backend.transaction_outputs as tout on t.id = tout.transaction_id
|
||||
left join backend.prompt_templates as prt on tout.prompt_id = prt.prompt_id
|
||||
--where t.id = 2
|
||||
order by transaction_id, tout.prompt_id;
|
||||
|
||||
select * from backend.prompt_templates;
|
||||
|
||||
Select * from public.companies;
|
||||
|
||||
select * from public.transactions;
|
||||
@@ -1,51 +0,0 @@
|
||||
Select * from
|
||||
backend2.transactions as t
|
||||
left join backend2.transaction_outputs as tout on t.id = tout.transaction_id
|
||||
--where t.id = 1 and tout.prompt_id = 98
|
||||
--where t.created_at like '2025-11-12%' and tout.prompt_id = 98
|
||||
order by transaction_id, prompt_id;
|
||||
|
||||
|
||||
select * from public.transactions
|
||||
order by "requires_review" desc, "risk_score" desc, "executed_at" desc
|
||||
limit 12 offset 0;
|
||||
|
||||
|
||||
SELECT * FROM information_schema.columns
|
||||
WHERE table_schema = 'public' and table_name = 'transactions';
|
||||
|
||||
/* Abfrage von Werten in JSONB */
|
||||
select content_json->'answer' as answer , content_json->
|
||||
from public.transaction_outputs
|
||||
where transaction_id = 2 --and prompt_id = 2
|
||||
order by transaction_id, prompt_id;
|
||||
|
||||
|
||||
-- Einer von mehreren Keys existiert?
|
||||
SELECT * FROM public.transaction_outputs
|
||||
WHERE content_json ?| array['risk_score', 'risk_level', 'risk_details_json'];
|
||||
|
||||
select * from backend2.transaction_outputs;
|
||||
|
||||
|
||||
/* Kopieren einer Tabelle von einem Schema in ein neues Schema */
|
||||
CREATE TABLE public.transaction_outputs AS
|
||||
SELECT * FROM backend.transaction_outputs;
|
||||
/* Prüfen ob alle Daten valides Json sind*/
|
||||
SELECT content from public.transaction_outputs
|
||||
WHERE content IS NOT NULL
|
||||
AND content::jsonb IS NULL;
|
||||
/* Neue Spalte zur kopierten Tabelle hinzufügen*/
|
||||
ALTER TABLE public.transaction_outputs
|
||||
ADD COLUMN content_json jsonb;
|
||||
/* Kopieren der String Daten in die JSONB Spalte*/
|
||||
UPDATE public.transaction_outputs
|
||||
SET content_json = content::jsonb
|
||||
WHERE content IS NOT NULL;
|
||||
/* Index erstellen*/
|
||||
CREATE INDEX idx_content_json ON public.transaction_outputs USING gin(content_json);
|
||||
CREATE INDEX idx_data_gin ON tablename USING gin(data);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
-- Test Query: Simuliert den Sync Query
|
||||
-- Führe diese Query aus um zu sehen, welche Daten synchronisiert werden
|
||||
|
||||
-- 1. Zeige Anzahl der Transaktionen mit status='done'
|
||||
SELECT
|
||||
'backend.transactions (done)' as table_name,
|
||||
COUNT(*) as record_count
|
||||
FROM backend.transactions
|
||||
WHERE status = 'done'
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 2. Zeige Anzahl der transaction_outputs für 'done' Transaktionen
|
||||
SELECT
|
||||
'backend.transaction_outputs (for done transactions)' as table_name,
|
||||
COUNT(*) as record_count
|
||||
FROM backend.transaction_outputs tout
|
||||
JOIN backend.transactions t ON t.id = tout.transaction_id
|
||||
WHERE t.status = 'done'
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 3. Zeige JOIN Resultat (das wird synchronisiert)
|
||||
SELECT
|
||||
'JOIN Result (will be synced)' as table_name,
|
||||
COUNT(*) as record_count
|
||||
FROM backend.transactions t
|
||||
LEFT JOIN backend.transaction_outputs tout ON t.id = tout.transaction_id
|
||||
WHERE t.status = 'done';
|
||||
|
||||
-- ==========================================
|
||||
|
||||
-- 4. Zeige erste 5 Datensätze die synchronisiert werden
|
||||
SELECT
|
||||
t.id as transaction_id,
|
||||
t.corporate_entity,
|
||||
t.corporate_counterparty,
|
||||
t.tx_date,
|
||||
t.tx_amount,
|
||||
t.tx_currency,
|
||||
t.status,
|
||||
tout.prompt_id,
|
||||
tout.output_key,
|
||||
LEFT(tout.content, 100) as content_preview,
|
||||
tout.run_id
|
||||
FROM backend.transactions t
|
||||
LEFT JOIN backend.transaction_outputs tout ON t.id = tout.transaction_id
|
||||
WHERE t.status = 'done'
|
||||
ORDER BY t.id, tout.prompt_id
|
||||
LIMIT 5;
|
||||
|
||||
-- ==========================================
|
||||
|
||||
-- 5. Zeige Verteilung der output_keys
|
||||
SELECT
|
||||
tout.output_key,
|
||||
COUNT(*) as count
|
||||
FROM backend.transaction_outputs tout
|
||||
JOIN backend.transactions t ON t.id = tout.transaction_id
|
||||
WHERE t.status = 'done'
|
||||
GROUP BY tout.output_key
|
||||
ORDER BY count DESC
|
||||
LIMIT 20;
|
||||
|
||||
-- ==========================================
|
||||
|
||||
-- 6. Zeige Transactions ohne Outputs (LEFT JOIN NULL)
|
||||
SELECT
|
||||
t.id,
|
||||
t.corporate_entity,
|
||||
t.status
|
||||
FROM backend.transactions t
|
||||
LEFT JOIN backend.transaction_outputs tout ON t.id = tout.transaction_id
|
||||
WHERE t.status = 'done'
|
||||
AND tout.transaction_id IS NULL
|
||||
LIMIT 10;
|
||||
Reference in New Issue
Block a user