From 83f57ab10e05bca1d8a554fabefcca2a9f549a73 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 8 Jan 2025 14:46:31 +0100
Subject: [PATCH] Fix DB migration path validation failing due to parsing
 directory name.

---
 plomtask/db.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

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())
-- 
2.30.2