p="cases_db.py"
src=open(p).read()
old='''    for col in ("media_url", "media_kind", "media_source", "source_media_url", "source_media_source", "post_media_url", "post_media_kind", "post_media_source", "post_media_format", "post_media_layout", "post_media_asset_id", "post_media_role", "creative_spec_json"):
        if col not in existing_cols:
            con.execute(f"ALTER TABLE content_items ADD COLUMN {col} TEXT DEFAULT ''")'''
new='''    for col in ("media_url", "media_kind", "media_source", "source_media_url", "source_media_source", "post_media_url", "post_media_kind", "post_media_source", "post_media_format", "post_media_layout", "post_media_asset_id", "post_media_role", "creative_spec_json", "topic_focus", "leitmotiv"):
        if col not in existing_cols:
            con.execute(f"ALTER TABLE content_items ADD COLUMN {col} TEXT DEFAULT ''")'''
assert old in src, "migration loop marker NOT found"
src2=src.replace(old,new,1)
# allowed-felder ergänzen
old2='''               "post_media_format", "post_media_layout", "post_media_asset_id", "post_media_role", "creative_spec_json"}'''
new2='''               "post_media_format", "post_media_layout", "post_media_asset_id", "post_media_role", "creative_spec_json",
               "topic_focus", "leitmotiv"}'''
assert old2 in src2, "allowed marker NOT found"
src2=src2.replace(old2,new2,1)
open(p,"w").write(src2)
print("cases_db migration+allowed GEPATCHT OK")
