Public repository: timo / mitch

Reader

A migration stitcher (therefore mitch) for PostgreSQL, SQLite, MariaDB, and others

Minor fixes for compatibility with Pylance

public

Minor fixes for compatibility with Pylance
Changeseta4e197e3760e5430ca81b0b06c193a833c266cfb
Author (claimed)Timo Stolz <timo.stolz@nullachtvierzehn.de>,
Parents8205eaa27112
Children
Pushlog
by timo via ssh

modified src/mitch/cli/deploy.py +3 −2

@@ -37,7 +37,8 @@
3737
     # Resolve database URL
3838
     resolved_database_url = database_url or os.getenv("MITCH_DATABASE_URL") or os.getenv("DATABASE_URL")
3939
     if not resolved_database_url:
40
-        raise typer.Exit(1, "Database URL must be provided via --database option or MITCH_DATABASE_URL/DATABASE_URL environment variable.")
40
+        typer.echo("Error: Database URL must be provided via --database option or MITCH_DATABASE_URL/DATABASE_URL environment variable.", err=True)
41
+        raise typer.Exit(1)
4142
     engine = sa.create_engine(resolved_database_url)
4243
     
4344
     # Fetch due migrations
@@ -88,7 +89,7 @@
8889
 
8990
         # Prepare to redeploy modified migrations, together with the 
9091
         if migrations_to_revert:
91
-            due_ids = set(migration_ids) + set(m.id for m in migrations_to_revert)
92
+            due_ids = set(migration_ids) | {m.id for m in migrations_to_revert}
9293
             due_migrations = list(repo.by_ids_with_dependencies(*due_ids))
9394
         
9495
         # Deploy due and reverted migrations

modified src/mitch/helpers.py +5 −3

@@ -1,11 +1,13 @@
11
 from itertools import groupby, count
2
-from collections import namedtuple
2
+from typing import NamedTuple, Iterable
33
 
44
 from .migration import Migration
55
 
6
-Batch = namedtuple('Batch', ['transactional', 'migrations'])
6
+class Batch(NamedTuple):
7
+    transactional: bool
8
+    migrations: Iterable[Migration]
79
 
8
-def batch_transactional_migrations(migrations: iter[Migration]) -> iter[iter[Migration]]:
10
+def batch_transactional_migrations(migrations: Iterable[Migration]) -> Iterable[Batch]:
911
     """Splits a list of migrations into batches based on their transactional property.
1012
     
1113
     Each batch is a list of migrations that can be run together in a single transaction.

modified src/mitch/repository.py +6 −5

@@ -2,6 +2,7 @@
22
 from pathlib import Path
33
 from graphlib import TopologicalSorter
44
 from weakref import WeakValueDictionary
5
+from typing import Iterable
56
 import tomllib
67
 
78
 from .migration import Migration
@@ -18,7 +19,7 @@
1819
                 return tomllib.load(f)
1920
         return {}
2021
 
21
-    def _load_migrations(self) -> iter[Migration]:
22
+    def _load_migrations(self):
2223
         # Fetch migrations
2324
         self.migrations = []
2425
         for up_script in self.path.rglob("*.up.sql"):
@@ -53,7 +54,7 @@
5354
                 dependency.dependants.add(migration.id)
5455
 
5556
     
56
-    def _iter_sorter(self, sorter: TopologicalSorter) -> iter[Migration]:
57
+    def _iter_sorter(self, sorter: TopologicalSorter) -> Iterable[Migration]:
5758
         sorter.prepare()
5859
         while sorter.is_active():
5960
             level = (self.by_id(id_) for id_ in sorter.get_ready())
@@ -67,14 +68,14 @@
6768
         except KeyError:
6869
             raise MissingMigrationError(migration_id)
6970
 
70
-    def by_ids(self, *migration_id: str) -> iter[Migration]:
71
+    def by_ids(self, *migration_id: str) -> Iterable[Migration]:
7172
         for id_ in migration_id:
7273
             yield self.by_id(id_)
7374
 
74
-    def by_ids_with_dependencies(self, *migration_id: str) -> iter[Migration]:
75
+    def by_ids_with_dependencies(self, *migration_id: str) -> Iterable[Migration]:
7576
         sorter = TopologicalSorter({ m.id: m.dependencies for m in self.by_ids(*migration_id) })
7677
         yield from self._iter_sorter(sorter)
7778
 
78
-    def by_ids_with_dependants(self, *migration_id: str) -> iter[Migration]:
79
+    def by_ids_with_dependants(self, *migration_id: str) -> Iterable[Migration]:
7980
         sorter = TopologicalSorter({ m.id: m.dependants for m in self.by_ids(*migration_id) })
8081
         yield from self._iter_sorter(sorter)