0.1.0
This commit is contained in:
8
migration/khadhroony-bot2-reference/sql/README.md
Normal file
8
migration/khadhroony-bot2-reference/sql/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
<!-- file: sql/README.md -->
|
||||
<!-- version: 1 -->
|
||||
|
||||
# SQL
|
||||
|
||||
Ce répertoire est réservé aux scripts SQL généraux qui ne sont pas des validations.
|
||||
|
||||
Les migrations propres à PostgreSQL doivent rester dans le crate `kb_store_pg`.
|
||||
2
migration/khadhroony-bot2-reference/sql/schema/.gitignore
vendored
Normal file
2
migration/khadhroony-bot2-reference/sql/schema/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# file: sql/schema/.gitignore
|
||||
# version: 1
|
||||
2
migration/khadhroony-bot2-reference/sql/validation/.gitignore
vendored
Normal file
2
migration/khadhroony-bot2-reference/sql/validation/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# file: sql/validation/.gitignore
|
||||
# version: 1
|
||||
@@ -0,0 +1,107 @@
|
||||
-- file: sql/validation/000_core_integrity.sql
|
||||
-- version: 5
|
||||
|
||||
-- Contrôles d'intégrité raw/core/ledger pour l'extracteur 0.3.4.
|
||||
|
||||
-- 1. Aucune signature raw en double.
|
||||
SELECT signature, COUNT(*) AS duplicate_count
|
||||
FROM kb_sol_raw_transactions
|
||||
GROUP BY signature
|
||||
HAVING COUNT(*) > 1;
|
||||
|
||||
-- 2. Aucune transaction core sans lineage raw valide.
|
||||
SELECT core.signature, core.raw_transaction_id
|
||||
FROM kb_sol_core_transactions core
|
||||
LEFT JOIN kb_sol_raw_transactions raw ON raw.id = core.raw_transaction_id
|
||||
WHERE core.raw_transaction_id IS NULL OR raw.id IS NULL;
|
||||
|
||||
-- 3. Aucune ligne fille orpheline.
|
||||
SELECT 'account_keys' AS child_table, child.id
|
||||
FROM kb_sol_core_account_keys child
|
||||
LEFT JOIN kb_sol_core_transactions core ON core.id = child.transaction_id
|
||||
WHERE core.id IS NULL
|
||||
UNION ALL
|
||||
SELECT 'instructions', child.id
|
||||
FROM kb_sol_core_instructions child
|
||||
LEFT JOIN kb_sol_core_transactions core ON core.id = child.transaction_id
|
||||
WHERE core.id IS NULL
|
||||
UNION ALL
|
||||
SELECT 'inner_instructions', child.id
|
||||
FROM kb_sol_core_inner_instructions child
|
||||
LEFT JOIN kb_sol_core_transactions core ON core.id = child.transaction_id
|
||||
WHERE core.id IS NULL
|
||||
UNION ALL
|
||||
SELECT 'logs', child.id
|
||||
FROM kb_sol_core_logs child
|
||||
LEFT JOIN kb_sol_core_transactions core ON core.id = child.transaction_id
|
||||
WHERE core.id IS NULL
|
||||
UNION ALL
|
||||
SELECT 'balance_changes', child.id
|
||||
FROM kb_sol_core_balance_changes child
|
||||
LEFT JOIN kb_sol_core_transactions core ON core.id = child.transaction_id
|
||||
WHERE core.id IS NULL;
|
||||
|
||||
-- 4. Aucune duplication des indices et chemins stables.
|
||||
SELECT signature, account_index::TEXT AS stable_key, COUNT(*) AS duplicate_count
|
||||
FROM kb_sol_core_account_keys
|
||||
GROUP BY signature, account_index
|
||||
HAVING COUNT(*) > 1
|
||||
UNION ALL
|
||||
SELECT signature, instruction_path, COUNT(*)
|
||||
FROM kb_sol_core_instructions
|
||||
GROUP BY signature, instruction_path
|
||||
HAVING COUNT(*) > 1
|
||||
UNION ALL
|
||||
SELECT signature, instruction_path, COUNT(*)
|
||||
FROM kb_sol_core_inner_instructions
|
||||
GROUP BY signature, instruction_path
|
||||
HAVING COUNT(*) > 1
|
||||
UNION ALL
|
||||
SELECT signature, log_index::TEXT, COUNT(*)
|
||||
FROM kb_sol_core_logs
|
||||
GROUP BY signature, log_index
|
||||
HAVING COUNT(*) > 1
|
||||
UNION ALL
|
||||
SELECT signature, balance_change_index::TEXT, COUNT(*)
|
||||
FROM kb_sol_core_balance_changes
|
||||
GROUP BY signature, balance_change_index
|
||||
HAVING COUNT(*) > 1;
|
||||
|
||||
-- 5. Toute extraction réussie doit avoir une transaction core et une ligne raw core_extracted.
|
||||
SELECT ledger.input_key AS signature, raw.processing_state, core.id AS core_transaction_id
|
||||
FROM kb_sol_ops_processing_ledger ledger
|
||||
LEFT JOIN kb_sol_raw_transactions raw ON raw.signature = ledger.input_key
|
||||
LEFT JOIN kb_sol_core_transactions core ON core.signature = ledger.input_key
|
||||
WHERE ledger.stage = 'core_extraction'
|
||||
AND ledger.processor_name = 'canonical_to_core'
|
||||
AND ledger.status = 'succeeded'
|
||||
AND (raw.processing_state <> 'core_extracted' OR core.id IS NULL);
|
||||
|
||||
-- 6. Toute ligne raw core_extracted doit avoir un graphe core et un succès ledger correspondant au hash courant.
|
||||
SELECT raw.signature, raw.canonical_json_hash
|
||||
FROM kb_sol_raw_transactions raw
|
||||
LEFT JOIN kb_sol_core_transactions core ON core.raw_transaction_id = raw.id
|
||||
LEFT JOIN kb_sol_ops_processing_ledger ledger
|
||||
ON ledger.stage = 'core_extraction'
|
||||
AND ledger.processor_name = 'canonical_to_core'
|
||||
AND ledger.input_key = raw.signature
|
||||
AND ledger.input_hash = raw.canonical_json_hash
|
||||
AND ledger.status = 'succeeded'
|
||||
WHERE raw.processing_state = 'core_extracted'
|
||||
AND (core.id IS NULL OR ledger.id IS NULL);
|
||||
|
||||
-- 7. Les chemins inner doivent référencer un parent top-level existant.
|
||||
SELECT inner_instruction.signature, inner_instruction.parent_instruction_path, inner_instruction.instruction_path
|
||||
FROM kb_sol_core_inner_instructions inner_instruction
|
||||
LEFT JOIN kb_sol_core_instructions parent
|
||||
ON parent.signature = inner_instruction.signature
|
||||
AND parent.instruction_path = inner_instruction.parent_instruction_path
|
||||
WHERE parent.id IS NULL;
|
||||
|
||||
-- 8. Résumé des statuts du processor.
|
||||
SELECT processor_version, status, COUNT(*) AS row_count, SUM(attempt_count) AS attempts
|
||||
FROM kb_sol_ops_processing_ledger
|
||||
WHERE stage = 'core_extraction'
|
||||
AND processor_name = 'canonical_to_core'
|
||||
GROUP BY processor_version, status
|
||||
ORDER BY processor_version, status;
|
||||
Reference in New Issue
Block a user