52 lines
3.4 KiB
Diff
52 lines
3.4 KiB
Diff
--- a/import_octo_character.py
|
|
+++ b/import_octo_character.py
|
|
@@ -6,6 +6,13 @@
|
|
- Columns: the intersection by name with the local schema. Octo-only columns are dropped and listed; local-only columns keep their defaults.
|
|
usage: python import_octo_character.py <export.json.gz> <local_account_id> <name> → writes import SQL + report next to the export; --apply runs it."""
|
|
import gzip, json, subprocess, sys
|
|
+import importlib.util
|
|
+from pathlib import Path
|
|
+
|
|
+# This adjacent module is installed from gateway/ops/import_transmog_registry.py.
|
|
+spec = importlib.util.spec_from_file_location('import_transmog_registry', Path(__file__).with_name('import_transmog_registry.py'))
|
|
+registry = importlib.util.module_from_spec(spec)
|
|
+spec.loader.exec_module(registry)
|
|
src, account, name = sys.argv[1], int(sys.argv[2]), sys.argv[3]; apply = '--apply' in sys.argv
|
|
def q(sql):
|
|
r = subprocess.run(['docker', 'exec', 'tortoise-docker-db-1', 'sh', '-c', f"mariadb -uroot -p\"$MYSQL_ROOT_PASSWORD\" -N tw_char -e \"{sql}\""], capture_output=True, text=True, check=True)
|
|
@@ -58,7 +65,13 @@
|
|
return "'" + str(v).replace('\\', '\\\\').replace("'", "\\'") + "'"
|
|
sql = ['SET autocommit=0;', 'START TRANSACTION;', f"UPDATE characters SET name=CONCAT(name,'old') WHERE name={lit(name)} AND guid<>{NEW};"]
|
|
report = dict(new_guid=NEW, old_octo_guid=OLD, items=[item0, item0 + len(imap) - 1], mails=len(mmap), texts=len(tmap), tables={}, dropped_columns={}, skipped_tables=[])
|
|
+evidence = None
|
|
+if '--transmog-evidence' in sys.argv:
|
|
+ evidence = json.loads(Path(sys.argv[sys.argv.index('--transmog-evidence') + 1]).read_text())
|
|
+plan = registry.recovery_plan(data, evidence, q)
|
|
+report['transmog_dependencies'] = plan
|
|
for t, rows in data.items():
|
|
+ if t == 'item_transmogs': continue # global rows are handled by the verified dependency plan
|
|
if not rows: continue
|
|
if t not in cols: report['skipped_tables'].append(t); continue
|
|
keep = [c for c in rows[0] if c in cols[t]]
|
|
@@ -74,11 +87,12 @@
|
|
if apply:
|
|
r = subprocess.run(['docker', 'exec', '-i', 'tortoise-docker-db-1', 'sh', '-c', 'mariadb -uroot -p"$MYSQL_ROOT_PASSWORD" tw_char'], input=open(out + '.local-import.sql').read(), text=True, capture_output=True)
|
|
print('apply rc', r.returncode, r.stderr[-800:])
|
|
- # Catalogue-wide transmog sweep (rules R1-R5, see transmog_integrity.py). Never fix transmogs per character.
|
|
- import glob, os
|
|
- here = os.path.dirname(os.path.abspath(__file__))
|
|
- wdb = sorted(glob.glob(os.path.join(here, '..', 'parity', 'octo-wdb-*', 'itemcache.wdb')))
|
|
- cmd = [sys.executable, '-I', os.path.join(here, 'transmog_integrity.py'), '--apply']
|
|
- for w in wdb: cmd += ['--wdb', w]
|
|
- subprocess.run(cmd)
|
|
- print('NEXT: run import_parity_audit.py, then restart mangosd (item_transmogs loads at startup).')
|
|
+ r.check_returncode()
|
|
+ # This legacy registry uses MyISAM. Complete the character import before materialising
|
|
+ # global rows, and re-read their actual state even if another import took the same serial.
|
|
+ for row in plan['insert_rows']:
|
|
+ q(registry.insert_statement(row))
|
|
+ report['transmog_dependencies'] = registry.recovery_plan(data, evidence, q)
|
|
+ Path(out + '.local-import.report.json').write_text(json.dumps(report, indent=1))
|
|
+ print('Transmog state:', report['transmog_dependencies']['records'])
|
|
+ print('NEXT: run import_parity_audit.py. Newly inserted item_transmogs load at mangosd startup.')
|