Create a backup of the current database file and create new database file with default settings.
()
| 365 | from pgadmin.setup import db_upgrade |
| 366 | |
| 367 | def backup_db_file(): |
| 368 | """ |
| 369 | Create a backup of the current database file |
| 370 | and create new database file with default settings. |
| 371 | """ |
| 372 | backup_file_name = "{0}.{1}".format( |
| 373 | SQLITE_PATH, datetime.now().strftime('%Y%m%d%H%M%S')) |
| 374 | os.rename(SQLITE_PATH, backup_file_name) |
| 375 | app.logger.error('Exception in database migration.') |
| 376 | app.logger.info('Creating new database file.') |
| 377 | try: |
| 378 | db_upgrade(app) |
| 379 | os.environ[ |
| 380 | 'CORRUPTED_DB_BACKUP_FILE'] = backup_file_name |
| 381 | app.logger.info('Database migration completed.') |
| 382 | except Exception: |
| 383 | app.logger.error('Database migration failed') |
| 384 | app.logger.error(traceback.format_exc()) |
| 385 | raise RuntimeError('Migration failed') |
| 386 | |
| 387 | def upgrade_db(): |
| 388 | """ |
no test coverage detected