def migrate_user(): """ Migrate the user documents to the latest schema """ collection = start_migration(User) if collection is None: return # v0 to v1 # Set _version field to 1 set_if_not_exist(collection, "_version", 1) # v1 to v2 # Add discord_user_id and teamspeak_cldbid fields, and set them to None set_if_not_exist(collection, "discord_user_id", None, version=1) set_if_not_exist(collection, "teamspeak_cldbid", None, version=1) ensure_minimum_version(collection, 2) # v2 to v3 # Set authorized_to_login field to None set_if_not_exist(collection, "authorized_to_login", None, version=2) ensure_minimum_version(collection, 3) # Finally finalize_migration(User)
def migrate_group(): """ Migrate the group documents to the latest schema """ collection = start_migration(Group) if collection is None: return # v0 to v1 # Set _version field to 1 set_if_not_exist(collection, "_version", 1) # v1 to v2 # Rename name field to group_name collection.update_many( {"_version": 1}, {"$rename": {"name": "group_name"}, "$set": {"_version": 2},}, ) # v2 to v3 # Ensures that # * discord_role_id exists (if not, sets it to None) # * teamspeak_sgid exists (if not, sets it to None) # * map_to_discord exists (if not, sets it to True) # * map_to_teamspeak exists (if not, sets it to True) collection.update_one( {"_version": 2, "group_name": "superusers",}, { "$set": { "_version": 3, "discord_role_id": None, "map_to_discord": False, "map_to_teamspeak": False, "teamspeak_sgid": None, }, }, ) set_if_not_exist(collection, "discord_role_id", None, version=2) set_if_not_exist(collection, "teamspeak_sgid", None, version=2) set_if_not_exist(collection, "map_to_discord", True, version=2) set_if_not_exist(collection, "map_to_teamspeak", True, version=2) ensure_minimum_version(collection, 3) # v3 to v4 # Set authorized_to_login field to None set_if_not_exist(collection, "authorized_to_login", None, version=3) ensure_minimum_version(collection, 4) # Finally finalize_migration(Group)
def migrate_state_code(): """ Migrates the ``state_code`` collection """ collection = start_migration(StateCode) if collection is None: return # v0 to v1 # Set _version field to 1 set_if_not_exist(collection, "_version", 1) # v1 to v2 # Set inviting_corporation field to None set_if_not_exist(collection, "inviting_corporation", None, version=1) ensure_minimum_version(collection, 2) finalize_migration(StateCode)
def migrate_character_location() -> None: """ Migrate the ``esi_character_location`` collection """ collection = start_migration(EsiCharacterLocation) if collection is None: return # v0 to v1 # Set _version field to 1 set_if_not_exist(collection, "_version", 1) # v1 to v2 # Set structure_name fields to None set_if_not_exist(collection, "structure_name", None, version=1) ensure_minimum_version(collection, 2) # Finally finalize_migration(EsiCharacterLocation)
def migrate_esi_refresh_token() -> None: """ Run migration tasks on the ``esi_refresh_token`` collection. """ collection = start_migration(EsiRefreshToken) if collection is None: return # v0 to v1 # Set _version field to 1 set_if_not_exist(collection, "_version", 1) # v1 to v2 # Sets the valid field to True set_if_not_exist(collection, "valid", True, version=1) ensure_minimum_version(collection, 2) # Finally finalize_migration(EsiRefreshToken)
def migrate_esi_access_token() -> None: """ Run migration tasks on the ``esi_access_token`` connection. """ collection = start_migration(EsiAccessToken) if collection is None: return # v0 to v1 # Set _version field to 1 set_if_not_exist(collection, "_version", 1) # v1 to v2 # Sets the valid field to True collection.delete_many({"refresh_token": {"$exists": False}}) ensure_minimum_version(collection, 2) # Finally finalize_migration(EsiAccessToken)
def migrate_coalition(): """ Migrate the coalition documents to the latest schema """ collection = start_migration(Coalition) if collection is None: return # v0 to v1 # Set _version field to 1 set_if_not_exist(collection, "_version", 1) # v1 to v2 # Set name field to coalition_name collection.update_many( {"_version": 1}, {"$rename": {"name": "coalition_name"}, "$set": {"_version": 2},}, ) # v2 to v3 # Set authorized_to_login field to None set_if_not_exist(collection, "authorized_to_login", None, version=2) ensure_minimum_version(collection, 3) # v3 to v4 # Set mandatory_esi_scopes to [] set_if_not_exist(collection, "mandatory_esi_scopes", [], version=3) ensure_minimum_version(collection, 4) # v4 to v5 # Set mandatory_esi_scopes to [] set_if_not_exist(collection, "member_corporations", [], version=4) ensure_minimum_version(collection, 5) # v5 to v6 # Rename `members` field to `member_alliances` collection.update_many( {"_version": 5}, {"$rename": {"members": "member_alliances"}, "$set": {"_version": 6},}, ) # Finally finalize_migration(Coalition)
def migrate_alliance(): """ Migrate the alliances documents to the latest schema """ collection = start_migration(Alliance) if collection is None: return # v0 to v1 # Set _version field to 1 set_if_not_exist(collection, "_version", 1) # v1 to v2 # Set authorized_to_login field to None set_if_not_exist(collection, "authorized_to_login", None, version=1) ensure_minimum_version(collection, 2) # v2 to v3 # Set mandatory_esi_scopes to [] set_if_not_exist(collection, "mandatory_esi_scopes", [], version=2) ensure_minimum_version(collection, 3) # Finally finalize_migration(Alliance)