dbname = get_module_dbname('llmage') db = DBPools() async with db.sqlorContext(dbname) as sor: # Create table sql = """ CREATE TABLE IF NOT EXISTS llm_catalog_rel ( id VARCHAR(32) NOT NULL PRIMARY KEY, llmid VARCHAR(32) NOT NULL, llmcatelogid VARCHAR(32) NOT NULL, INDEX idx_llm (llmid), INDEX idx_catelog (llmcatelogid) ) """ try: await sor.sqlExe(sql, {}) print("Table llm_catalog_rel created or exists.") except Exception as e: print(f"Create table error: {e}") # Migrate data sql = "select id, llmcatelogid from llm where llmcatelogid is not null and llmcatelogid != ''" rows = await sor.sqlExe(sql, {}) print(f"Found {len(rows)} records to migrate.") for r in rows: data = { 'llmid': r['id'], 'llmcatelogid': r['llmcatelogid'] } try: await sor.C('llm_catalog_rel', data) except Exception as e: print(f"Insert error: {e}") print("Migration complete.") # Drop column try: await sor.sqlExe("alter table llm drop column llmcatelogid", {}) print("Column llmcatelogid dropped.") except Exception as e: print(f"Drop column error: {e}") return {'status': 'ok'}