Exemple #1
0
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)
Exemple #2
0
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)