"""Apply and verify the API 0.6.7 post columns before deployment.""" from sqlalchemy import inspect, text from .database import engine POST_COLUMNS = { "content_format": "VARCHAR(10) NOT NULL DEFAULT 'plain'", "feeling": "VARCHAR(50) NULL", "location_name": "VARCHAR(255) NULL", "location_latitude": "DOUBLE NULL", "location_longitude": "DOUBLE NULL", } def main() -> None: if engine.dialect.name != "mysql": raise RuntimeError("Post migration requires MySQL") existing = {column["name"] for column in inspect(engine).get_columns("posts")} with engine.begin() as connection: for name, definition in POST_COLUMNS.items(): if name not in existing: connection.execute(text(f"ALTER TABLE posts ADD COLUMN {name} {definition}")) connection.execute(text("SELECT 1")) actual = {column["name"] for column in inspect(engine).get_columns("posts")} missing = POST_COLUMNS.keys() - actual if missing: raise RuntimeError(f"Post migration incomplete: {sorted(missing)}") print("POST_COMPOSER_MIGRATION_OK") if __name__ == "__main__": main()