(db, old_ver)
| 962 | |
| 963 | |
| 964 | def database_migrate(db, old_ver): |
| 965 | # Update database schema version |
| 966 | Versions.update(val=db_schema_version).where(Versions.key == 'schema_version').execute() |
| 967 | |
| 968 | log.info("Detected database version %i, updating to %i", old_ver, db_schema_version) |
| 969 | |
| 970 | # Perform migrations here |
| 971 | migrator = None |
| 972 | if args.db_type == 'mysql': |
| 973 | migrator = MySQLMigrator(db) |
| 974 | else: |
| 975 | migrator = SqliteMigrator(db) |
| 976 | |
| 977 | # No longer necessary, we're doing this at schema 4 as well |
| 978 | # if old_ver < 1: |
| 979 | # db.drop_tables([ScannedLocation]) |
| 980 | |
| 981 | if old_ver < 2: |
| 982 | migrate(migrator.add_column('pokestop', 'encounter_id', CharField(max_length=50, null=True))) |
| 983 | |
| 984 | if old_ver < 3: |
| 985 | migrate( |
| 986 | migrator.add_column('pokestop', 'active_fort_modifier', CharField(max_length=50, null=True)), |
| 987 | migrator.drop_column('pokestop', 'encounter_id'), |
| 988 | migrator.drop_column('pokestop', 'active_pokemon_id') |
| 989 | ) |
| 990 | |
| 991 | if old_ver < 4: |
| 992 | db.drop_tables([ScannedLocation]) |
| 993 | |
| 994 | if old_ver < 5: |
| 995 | # Some pokemon were added before the 595 bug was "fixed" |
| 996 | # Clean those up for a better UX |
| 997 | query = (Pokemon |
| 998 | .delete() |
| 999 | .where(Pokemon.disappear_time > |
| 1000 | (datetime.utcnow() - timedelta(hours=24)))) |
| 1001 | query.execute() |
| 1002 | |
| 1003 | if old_ver < 6: |
| 1004 | migrate( |
| 1005 | migrator.add_column('gym', 'last_scanned', DateTimeField(null=True)), |
| 1006 | ) |
| 1007 | |
| 1008 | if old_ver < 7: |
| 1009 | migrate( |
| 1010 | migrator.drop_column('gymdetails', 'description'), |
| 1011 | migrator.add_column('gymdetails', 'description', TextField(null=True, default="")) |
| 1012 | ) |
no outgoing calls
no test coverage detected