Skip to content

Commit

Permalink
database.upgrade:get_upgrade_function - move below upgrade functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoCampinoti94 committed Aug 20, 2024
1 parent 119e59f commit 35e8dcb
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions acacore/database/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ def set_db_version(conn: Connection, version: Version) -> Version:
return version


def get_upgrade_function(current_version: Version, latest_version: Version) -> Callable[[Connection], Version]:
if current_version < Version("2.0.0"):
return upgrade_1to2
elif current_version < Version("2.0.2"):
return upgrade_2to2_0_2
elif current_version < Version("3.0.0"):
return upgrade_2_0_2to3
elif current_version < Version("3.0.2"):
return upgrade_3to3_0_2
elif current_version < latest_version:
return upgrade_last
else:
return lambda _: latest_version


# noinspection SqlResolve
def upgrade_1to2(conn: Connection) -> Version:
# Add "lock" column if not already present
Expand Down Expand Up @@ -167,6 +152,21 @@ def upgrade_last(conn: Connection) -> Version:
return set_db_version(conn, Version(__version__))


def get_upgrade_function(current_version: Version, latest_version: Version) -> Callable[[Connection], Version]:
if current_version < Version("2.0.0"):
return upgrade_1to2
elif current_version < Version("2.0.2"):
return upgrade_2to2_0_2
elif current_version < Version("3.0.0"):
return upgrade_2_0_2to3
elif current_version < Version("3.0.2"):
return upgrade_3to3_0_2
elif current_version < latest_version:
return upgrade_last
else:
return lambda _: latest_version


def is_latest(db: FileDB, *, raise_on_difference: bool = False) -> bool:
"""
Check if a database is using the latest version of acacore.
Expand Down

0 comments on commit 35e8dcb

Please sign in to comment.