Verify the migration by comparing document counts
(logger)
| 138 | |
| 139 | |
| 140 | def verify_migration(logger): |
| 141 | """Verify the migration by comparing document counts""" |
| 142 | from questions.db_models import Document as NDBDocument |
| 143 | from questions.db_models import client |
| 144 | from questions.db_models_postgres import Document as PGDocument |
| 145 | from questions.db_models_postgres import SessionLocal |
| 146 | |
| 147 | logger.info("Verifying migration...") |
| 148 | |
| 149 | db = SessionLocal() |
| 150 | |
| 151 | try: |
| 152 | # Count PostgreSQL records |
| 153 | pg_doc_count = db.query(PGDocument).count() |
| 154 | |
| 155 | # Count NDB records |
| 156 | with client.context(): |
| 157 | ndb_doc_count = NDBDocument.query().count() |
| 158 | |
| 159 | logger.info("Migration verification:") |
| 160 | logger.info(f" Documents: NDB={ndb_doc_count}, PostgreSQL={pg_doc_count}") |
| 161 | |
| 162 | if pg_doc_count >= ndb_doc_count: |
| 163 | logger.info("✅ Migration verification successful!") |
| 164 | return True |
| 165 | else: |
| 166 | logger.warning("⚠️ Migration may be incomplete - counts don't match") |
| 167 | return False |
| 168 | |
| 169 | finally: |
| 170 | db.close() |
| 171 | |
| 172 | |
| 173 | def main(): |