migrate_tickets: env creds (secret hors repo) + mode PREVIEW + host défaut 10.100.80.100
Rattrapage 2026-07-06 : 9632 Issues créés (9657 manquants, 25 err données), tickets Δ 9643→11. Reste : rendre récurrent (cron quotidien ou watermark) pour ne pas rouvrir le trou. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
5783ec30b9
commit
224db4527e
|
|
@ -10,16 +10,20 @@ Phase 6: Import tickets → ERPNext Issue + Communication.
|
||||||
Direct PostgreSQL. Detached.
|
Direct PostgreSQL. Detached.
|
||||||
Log: /tmp/migrate_tickets.log
|
Log: /tmp/migrate_tickets.log
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
import pymysql
|
import pymysql
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from html import unescape
|
from html import unescape
|
||||||
|
|
||||||
LEGACY = {"host": "legacy-db", "user": "facturation", "password": "***LEGACY-DB-PW-REDACTED***",
|
# Creds via env (secret hors repo). Défauts alignés sur /opt/targo-sync (sync_services_incremental.py).
|
||||||
"database": "gestionclient", "connect_timeout": 30, "read_timeout": 600}
|
LEGACY = {"host": os.environ.get("LEGACY_HOST", "10.100.80.100"), "user": "facturation",
|
||||||
PG = {"host": "db", "port": 5432, "user": "postgres", "password": "123",
|
"password": os.environ.get("LEGACY_PW", ""), "database": "gestionclient",
|
||||||
"dbname": "_eb65bdc0c4b1b2d6"}
|
"connect_timeout": 30, "read_timeout": 600}
|
||||||
|
PG = {"host": os.environ.get("PG_HOST", "db"), "port": 5432, "user": "postgres",
|
||||||
|
"password": os.environ.get("PG_PW", "123"), "dbname": os.environ.get("PG_DB", "_eb65bdc0c4b1b2d6")}
|
||||||
|
PREVIEW = os.environ.get("PREVIEW", "0") == "1" # compte les manquants + sort, N'ÉCRIT RIEN
|
||||||
|
|
||||||
ADMIN = "Administrator"
|
ADMIN = "Administrator"
|
||||||
COMPANY = "TARGO"
|
COMPANY = "TARGO"
|
||||||
|
|
@ -130,6 +134,21 @@ def main():
|
||||||
|
|
||||||
log(" {} customers mapped, {} staff→user mapped".format(len(cust_map), len(staff_to_user)))
|
log(" {} customers mapped, {} staff→user mapped".format(len(cust_map), len(staff_to_user)))
|
||||||
|
|
||||||
|
# PREVIEW — compte les tickets manquants (pas encore en Issue), par statut, puis SORT sans écrire
|
||||||
|
if PREVIEW:
|
||||||
|
from collections import Counter
|
||||||
|
miss = [t for t in tickets if t["id"] not in existing_issues]
|
||||||
|
by_status = Counter(t.get("status", "?") for t in miss)
|
||||||
|
log("")
|
||||||
|
log("=== PREVIEW (aucune écriture) ===")
|
||||||
|
log(" Tickets F total : {}".format(len(tickets)))
|
||||||
|
log(" Déjà en Issue (skip) : {}".format(len(tickets) - len(miss)))
|
||||||
|
log(" MANQUANTS à importer : {} {}".format(len(miss), dict(by_status)))
|
||||||
|
if miss:
|
||||||
|
log(" plage id manquants : {} … {}".format(min(t["id"] for t in miss), max(t["id"] for t in miss)))
|
||||||
|
pg.close()
|
||||||
|
return
|
||||||
|
|
||||||
# 3. Create Issue Priorities
|
# 3. Create Issue Priorities
|
||||||
for pname in ["Urgent", "High", "Medium", "Low"]:
|
for pname in ["Urgent", "High", "Medium", "Low"]:
|
||||||
if pname not in existing_priorities:
|
if pname not in existing_priorities:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user