"""Check the scoped portal condition migration and preserve the native level gate.""" from pathlib import Path import sqlite3 root = Path(__file__).resolve().parents[2] sql = (root / 'sql/custom/world/2026_10_29_03_blasted_lands_portal_conditions.sql').read_text() db = sqlite3.connect(':memory:') columns = ['SourceTypeOrReferenceId','SourceGroup','SourceEntry','SourceId', 'ConditionTypeOrReference','ConditionTarget','ConditionValue1', 'ConditionValue2','NegativeCondition'] db.execute('CREATE TABLE conditions (' + ','.join(c+' INTEGER' for c in columns) + ')') rows = [(17,0,65728,0,27,0,58,3,0), (17,0,65729,0,27,0,58,3,0), (17,0,17334,0,27,0,58,3,0), (17,0,65728,0,27,0,60,3,0), (17,0,65729,0,27,0,58,3,1), (13,0,65728,0,27,0,58,3,0)] db.executemany('INSERT INTO conditions VALUES (?,?,?,?,?,?,?,?,?)',rows) db.executescript(sql) result = db.execute('SELECT * FROM conditions').fetchall() assert result[0][5] == result[1][5] == 1 assert result[2:] == rows[2:] for row in result[:2]: assert row[6:8] == (58,3), 'Native minimum level and comparison must survive' db.executescript(sql) assert db.execute('SELECT * FROM conditions').fetchall() == result print('Portal condition migration: explicit user target, preserved level gate, scoped updates and idempotence passed.') # Only named public static portals change caster; preserve summoned/quest data. db.execute('CREATE TABLE gameobject_template(entry INTEGER,type INTEGER,data2 INTEGER,data6 INTEGER)') rows2=[(183325,22,0,0),(195142,22,0,0),(209538,22,0,0),(210176,22,0,0), (176296,22,1,0),(205268,22,0,0),(183325,22,1,0),(183325,10,0,0)] db.executemany('INSERT INTO gameobject_template VALUES(?,?,?,?)',rows2) public_sql=(root/'sql/custom/world/2026_10_29_04_public_portal_player_cast.sql').read_text() db.executescript(public_sql) after=db.execute('SELECT * FROM gameobject_template').fetchall() assert all(r[3]==1 for r in after[:4]) assert after[4:]==rows2[4:] db.executescript(public_sql) assert db.execute('SELECT * FROM gameobject_template').fetchall()==after print('Public portal caster migration: static allowlist, party/type guards and idempotence passed.')