From: Christian Heller Date: Wed, 8 Jan 2025 13:46:31 +0000 (+0100) Subject: Fix DB migration path validation failing due to parsing directory name. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/decks/edit?a=commitdiff_plain;h=83f57ab10e05bca1d8a554fabefcca2a9f549a73;p=plomtask Fix DB migration path validation failing due to parsing directory name. --- diff --git a/plomtask/db.py b/plomtask/db.py index 5076e85..fd393b8 100644 --- a/plomtask/db.py +++ b/plomtask/db.py @@ -1,7 +1,7 @@ """Database management.""" from __future__ import annotations from os import listdir -from os.path import isfile +from os.path import basename, isfile from difflib import Differ from sqlite3 import ( connect as sql_connect, Connection as SqlConnection, Cursor, Row) @@ -30,7 +30,7 @@ class DatabaseMigration: post_sql_steps: Callable[[SqlConnection], None] | None ) -> None: if sql_path: - start_tok = str(sql_path).split('_', maxsplit=1)[0] + start_tok = str(basename(sql_path)).split('_', maxsplit=1)[0] if (not start_tok.isdigit()) or int(start_tok) != target_version: raise HandledException(f'migration to {target_version} mapped ' f'to bad path {sql_path}') @@ -76,7 +76,7 @@ class DatabaseMigration: return migs def perform(self, conn: SqlConnection) -> None: - """Do 1) script at sql_path, 2) after_sql_steps, 3) version setting.""" + """Do 1) script at sql_path, 2) post_sql_steps, 3) version setting.""" if self._sql_path: with open(self._sql_path, 'r', encoding='utf8') as f: conn.executescript(f.read())