clean docs
This commit is contained in:
78
scripts/README.md
Normal file
78
scripts/README.md
Normal file
@@ -0,0 +1,78 @@
|
||||
# Migration Scripts
|
||||
|
||||
Utility scripts per la gestione della migrazione.
|
||||
|
||||
## sync_migration_state.py
|
||||
|
||||
Sincronizza la tabella `migration_state` con i dati effettivamente presenti in PostgreSQL.
|
||||
|
||||
### Quando usare
|
||||
|
||||
Usa questo script quando `migration_state` non è sincronizzato con i dati reali, ad esempio:
|
||||
- Dopo inserimenti manuali in PostgreSQL
|
||||
- Dopo corruzione dello stato
|
||||
- Prima di eseguire migrazione incrementale su dati già esistenti
|
||||
|
||||
### Come funziona
|
||||
|
||||
Per ogni tabella (rawdatacor, elabdatadisp):
|
||||
1. Trova la riga con MAX(created_at) - l'ultima riga inserita
|
||||
2. Estrae la consolidation key da quella riga
|
||||
3. Aggiorna `migration_state._global` con quella chiave
|
||||
|
||||
### Utilizzo
|
||||
|
||||
```bash
|
||||
# Eseguire dalla root del progetto
|
||||
python scripts/sync_migration_state.py
|
||||
```
|
||||
|
||||
### Output
|
||||
|
||||
```
|
||||
Syncing migration_state with actual PostgreSQL data...
|
||||
================================================================================
|
||||
|
||||
ELABDATADISP:
|
||||
Most recently inserted row (by created_at):
|
||||
created_at: 2025-12-30 11:58:24
|
||||
event_timestamp: 2025-12-30 14:58:24
|
||||
Consolidation key: (ID0290, DT0007, 2025-12-30, 14:58:24)
|
||||
✓ Updated migration_state with this key
|
||||
|
||||
RAWDATACOR:
|
||||
Most recently inserted row (by created_at):
|
||||
created_at: 2025-12-30 11:13:29
|
||||
event_timestamp: 2025-12-30 11:11:39
|
||||
Consolidation key: (ID0304, DT0024, 2025-12-30, 11:11:39)
|
||||
✓ Updated migration_state with this key
|
||||
|
||||
================================================================================
|
||||
✓ Done! Incremental migration will now start from the correct position.
|
||||
```
|
||||
|
||||
### Effetti
|
||||
|
||||
Dopo aver eseguito questo script:
|
||||
- `migration_state._global` sarà aggiornato con l'ultima chiave migrata
|
||||
- `python main.py migrate incremental` partirà dalla posizione corretta
|
||||
- Non verranno create duplicazioni (usa ON CONFLICT DO NOTHING)
|
||||
|
||||
### Avvertenze
|
||||
|
||||
- Esclude automaticamente dati corrotti (unit_name come `[Ljava.lang.String;@...`)
|
||||
- Usa `created_at` per trovare l'ultima riga inserita (non `event_timestamp`)
|
||||
- Sovrascrive lo stato globale esistente
|
||||
|
||||
### Verifica
|
||||
|
||||
Dopo aver eseguito lo script, verifica lo stato:
|
||||
|
||||
```sql
|
||||
SELECT table_name, partition_name, last_key
|
||||
FROM migration_state
|
||||
WHERE partition_name = '_global'
|
||||
ORDER BY table_name;
|
||||
```
|
||||
|
||||
Dovrebbe mostrare le chiavi più recenti per entrambe le tabelle.
|
||||
Reference in New Issue
Block a user