Public repository: timo / mitch

Reader

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

Rename Repository to Project

public

Rename Repository to Project
Changesetb1da7291a47c60118ff3966bcc35c0d4814884cd
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parentsb7b1e183d424
Children
Pushlog
by timo via ssh

modified src/mitch/cli/checkout.py +29 −29

@@ -9,7 +9,7 @@
99
 
1010
 from ..errors import MissingMigrationError
1111
 from ..helpers import connection_for
12
-from ..repository import Repository
12
+from ..project import Project
1313
 from ..runner import Runner
1414
 from ..vcs import Add, Copied, Deleted, Modified, Renamed
1515
 from .deploy import IfModifiedOption, run_up
@@ -31,9 +31,9 @@
3131
     root: Annotated[
3232
         Path,
3333
         typer.Option(
34
-            "--repository",
35
-            "-r",
36
-            help="Repository directory.",
34
+            "--project",
35
+            "-p",
36
+            help="Project directory.",
3737
             default_factory=lambda: Path.cwd(),
3838
             dir_okay=True,
3939
             file_okay=False,
@@ -66,13 +66,13 @@
6666
         Literal["git", "hg"] | None,
6767
         typer.Option(
6868
             "--vcs",
69
-            help="Version control backend. Defaults to auto-detection from repository root.",
69
+            help="Version control backend. Defaults to auto-detection from project root.",
7070
         ),
7171
     ] = None,
7272
 ) -> None:
7373
     """Checkout a branch while reverting/deploying migrations as needed."""
74
-    repo = Repository(root)
75
-    vcs_manager = repo.get_migration_manager(vcs)
74
+    project = Project(root)
75
+    vcs_manager = project.get_migration_manager(vcs)
7676
 
7777
     # Policy overview for later review:
7878
     # 1) Branch transition semantics are commit-based (current commit -> target commit).
@@ -86,7 +86,7 @@
8686
     should_pop_stash = allow_dirty and vcs_manager.is_dirty()
8787
     restore_candidate_paths: set[Path] = set()
8888
 
89
-    def _build_branch_transition_plan(repo_before_checkout: Repository) -> BranchTransitionPlan:
89
+    def _build_branch_transition_plan(project_before_checkout: Project) -> BranchTransitionPlan:
9090
         # Build a commit-to-commit transition plan (current commit -> target commit).
9191
         up_modified: set[Migration] = set()
9292
         up_deleted: set[Migration] = set()
@@ -99,24 +99,24 @@
9999
         for entry in vcs_manager.changes(branch):
100100
             match entry:
101101
                 case Deleted(path) if path.suffix == ".sql":
102
-                    up_deleted.add(repo_before_checkout.by_path(path))
102
+                    up_deleted.add(project_before_checkout.by_path(path))
103103
                 case Deleted(path) if path.suffix == ".toml":
104
-                    config_deleted.add(repo_before_checkout.by_path(path))
104
+                    config_deleted.add(project_before_checkout.by_path(path))
105105
                 case Modified(path) if path.suffix == ".sql":
106
-                    up_modified.add(repo_before_checkout.by_path(path))
106
+                    up_modified.add(project_before_checkout.by_path(path))
107107
                 case Modified(path) if path.suffix == ".toml":
108
-                    config_modified.add(repo_before_checkout.by_path(path))
108
+                    config_modified.add(project_before_checkout.by_path(path))
109109
                 case Renamed(old_path, new_path) if old_path.suffix == ".sql" and new_path.suffix == ".sql":
110
-                    up_deleted.add(repo_before_checkout.by_path(old_path))
110
+                    up_deleted.add(project_before_checkout.by_path(old_path))
111111
                     moved_paths[old_path] = new_path
112112
                 case Renamed(old_path, new_path) if old_path.suffix == ".toml" and new_path.suffix == ".toml":
113
-                    config_deleted.add(repo_before_checkout.by_path(old_path))
113
+                    config_deleted.add(project_before_checkout.by_path(old_path))
114114
                     moved_paths[old_path] = new_path
115115
                 case Add(path) if path.suffix == ".sql":
116116
                     target_added_paths.add(path)
117117
                 case Add(path) if path.suffix == ".toml":
118118
                     try:
119
-                        config_added.add(repo_before_checkout.by_path(path.with_suffix("").with_suffix(".up.sql")))
119
+                        config_added.add(project_before_checkout.by_path(path.with_suffix("").with_suffix(".up.sql")))
120120
                     except MissingMigrationError:
121121
                         # Explicitly silenced: config-only target additions without a known current migration
122122
                         # do not participate in pre-checkout reverts.
@@ -125,7 +125,7 @@
125125
                     target_added_paths.add(new_path)
126126
                 case Copied(_, new_path) if new_path.suffix == ".toml":
127127
                     try:
128
-                        config_added.add(repo_before_checkout.by_path(new_path.with_suffix("").with_suffix(".up.sql")))
128
+                        config_added.add(project_before_checkout.by_path(new_path.with_suffix("").with_suffix(".up.sql")))
129129
                     except MissingMigrationError:
130130
                         # Explicitly silenced: copied configs for unknown current migrations are ignored here.
131131
                         pass
@@ -138,7 +138,7 @@
138138
 
139139
     # Step 1: Reconcile dirty local migration edits to current commit state before stashing.
140140
     if should_pop_stash:
141
-        dirty_reverted = revert_dirty_migrations(repo, vcs_manager, database_url)
141
+        dirty_reverted = revert_dirty_migrations(project, vcs_manager, database_url)
142142
         restore_candidate_paths.update(migration.up_script for migration in dirty_reverted)
143143
 
144144
         # Step 2: Stash local changes so file system reflects current commit state.
@@ -147,16 +147,16 @@
147147
         # Step 5: Checkout the target revision.
148148
         # Step 6: Restore stashed local changes.
149149
         with vcs_manager.stashed():
150
-            repo_current = Repository(root)
151
-            reapplied_on_current = reapply_reverted_migrations(repo_current, dirty_reverted, database_url)
150
+            project_current = Project(root)
151
+            reapplied_on_current = reapply_reverted_migrations(project_current, dirty_reverted, database_url)
152152
             restore_candidate_paths.difference_update(migration.up_script for migration in reapplied_on_current)
153153
 
154
-            branch_plan = _build_branch_transition_plan(repo_current)
154
+            branch_plan = _build_branch_transition_plan(project_current)
155155
             with connection_for(database_url) as connection:
156156
                 runner = Runner(connection)
157157
                 reverted_for_branch_transition = set(
158158
                     runner.revert_migrations(
159
-                        repo_current.with_dependants(branch_plan.revert_candidates),
159
+                        project_current.with_dependants(branch_plan.revert_candidates),
160160
                         before_each=lambda migration, status: rich.print(
161161
                             f"[blue]Reverting:[/blue] Migration '{migration.id}' ({status})"
162162
                         ),
@@ -167,16 +167,16 @@
167167
 
168168
             vcs_manager.checkout(branch)
169169
 
170
-        repo_after = Repository(root)
170
+        project_after = Project(root)
171171
         target_added_paths = branch_plan.target_added_paths
172172
     else:
173173
         # Step 4 (clean worktree): Revert migrations needed for current-commit -> target-commit transition.
174
-        branch_plan = _build_branch_transition_plan(repo)
174
+        branch_plan = _build_branch_transition_plan(project)
175175
         with connection_for(database_url) as connection:
176176
             runner = Runner(connection)
177177
             reverted_for_branch_transition = set(
178178
                 runner.revert_migrations(
179
-                    repo.with_dependants(branch_plan.revert_candidates),
179
+                    project.with_dependants(branch_plan.revert_candidates),
180180
                     before_each=lambda migration, status: rich.print(
181181
                         f"[blue]Reverting:[/blue] Migration '{migration.id}' ({status})"
182182
                     ),
@@ -187,19 +187,19 @@
187187
 
188188
         # Step 5 (clean worktree): Checkout the target revision.
189189
         vcs_manager.checkout(branch)
190
-        repo_after = Repository(root)
190
+        project_after = Project(root)
191191
 
192192
     # Step 7: Apply migrations from the final filesystem state according to policy.
193193
     # - Without --and-up: restore only migrations that were reverted earlier and still exist.
194
-    # - With --and-up: apply pending migrations from the final repository (like `mitch up`).
194
+    # - With --and-up: apply pending migrations from the final project (like `mitch up`).
195195
     if and_up:
196
-        run_up(repo_after.path, database_url, if_modified=IfModifiedOption.IGNORE, watch=False)
196
+        run_up(project_after.path, database_url, if_modified=IfModifiedOption.IGNORE, watch=False)
197197
         return
198198
 
199199
     apply_migrations: set[Migration] = set()
200200
     for path in restore_candidate_paths:
201201
         try:
202
-            apply_migrations.add(repo_after.by_path(path))
202
+            apply_migrations.add(project_after.by_path(path))
203203
         except MissingMigrationError:
204204
             # Reverted migrations missing after checkout+restore stay reverted by design.
205205
             continue
@@ -207,7 +207,7 @@
207207
     with connection_for(database_url) as connection:
208208
         runner = Runner(connection)
209209
         runner.deploy_migrations(
210
-            repo_after.with_dependencies(apply_migrations),
210
+            project_after.with_dependencies(apply_migrations),
211211
             before_each=lambda migration, status: rich.print(
212212
                 f"[green]Deploying:[/green] Migration '{migration.id}' ({status})"
213213
             ),

modified src/mitch/cli/create.py +8 −8

@@ -4,9 +4,9 @@
44
 
55
 import typer
66
 
7
-from ..repository import Repository
7
+from ..project import Project
88
 
9
-app = typer.Typer(help="Add new migrations to the repository.")
9
+app = typer.Typer(help="Add new migrations to the project.")
1010
 
1111
 
1212
 @app.command()
@@ -15,9 +15,9 @@
1515
     root: Annotated[
1616
         Path,
1717
         typer.Option(
18
-            "--repository",
19
-            "-r",
20
-            help="Repository directory.",
18
+            "--project",
19
+            "-p",
20
+            help="Project directory.",
2121
             default_factory=Path.cwd,
2222
             dir_okay=True,
2323
             file_okay=False,
@@ -37,7 +37,7 @@
3737
         bool, typer.Option("--skip-downscript", "-sd", help="Skip creating a downscript for the migration.")
3838
     ] = False,
3939
 ) -> None:
40
-    """Create a new migration scaffold in the repository.
40
+    """Create a new migration scaffold in the project.
4141
 
4242
     Args:
4343
         migration_id: The ID of the new migration.
@@ -46,8 +46,8 @@
4646
     migration_path = Path(root) / migration_id
4747
 
4848
     # Validate dependency IDs
49
-    repo = Repository(root)
50
-    missing_dependencies = [dep for dep in dependencies if dep not in repo.migrations_by_id]
49
+    project = Project(root)
50
+    missing_dependencies = [dep for dep in dependencies if dep not in project.migrations_by_id]
5151
     if missing_dependencies:
5252
         typer.echo(f"Error: Missing dependencies: {', '.join(missing_dependencies)}", err=True)
5353
         raise typer.Exit(1)

modified src/mitch/cli/deploy.py +24 −24

@@ -8,7 +8,7 @@
88
 
99
 from ..helpers import connection_for
1010
 from ..migration import Migration
11
-from ..repository import Repository
11
+from ..project import Project
1212
 from ..runner import DeploymentStatus, Runner
1313
 from ..watcher import EventType
1414
 
@@ -105,12 +105,12 @@
105105
 
106106
 
107107
 def _apply_planned_migrations(
108
-    repo: Repository,
108
+    project: Project,
109109
     runner: Runner,
110110
     covered_migrations: set[Migration],
111111
     redeploy: set[Migration],
112112
 ) -> None:
113
-    to_revert = list(repo.with_dependants(redeploy))
113
+    to_revert = list(project.with_dependants(redeploy))
114114
     _revert_with_feedback(
115115
         runner,
116116
         to_revert,
@@ -124,7 +124,7 @@
124124
         for migration in covered_migrations
125125
         if runner.deployment_status(migration) == "pending"
126126
     }
127
-    to_apply = list(repo.with_dependencies(pending | redeploy))
127
+    to_apply = list(project.with_dependencies(pending | redeploy))
128128
     _deploy_with_feedback(
129129
         runner,
130130
         to_apply,
@@ -135,14 +135,14 @@
135135
 
136136
 
137137
 def _process_watch_changes(
138
-    repo: Repository,
138
+    project: Project,
139139
     runner: Runner,
140140
     covered_migrations: set[Migration],
141141
     changes: Iterable[tuple[EventType, Path]],
142142
     allow_new_migrations: bool,
143143
 ) -> None:
144
-    # Reload repository after receiving events so created files are visible in the index.
145
-    repo.reload()
144
+    # Reload project after receiving events so created files are visible in the index.
145
+    project.reload()
146146
 
147147
     applied_and_modified = set()
148148
     added_and_pending = set()
@@ -150,18 +150,18 @@
150150
         if action == EventType.MODIFIED and (
151151
             path.name.endswith(".up.sql") or path.name.endswith(".config.toml")
152152
         ):
153
-            migration = repo.by_path(path)
153
+            migration = project.by_path(path)
154154
             if migration not in covered_migrations:
155155
                 continue
156156
             if runner.deployment_status(migration) in ("modified", "applied"):
157157
                 applied_and_modified.add(migration)
158158
 
159159
         if allow_new_migrations and action == EventType.CREATED and path.name.endswith(".up.sql"):
160
-            migration = repo.by_path(path)
160
+            migration = project.by_path(path)
161161
             if runner.deployment_status(migration) == "pending":
162162
                 added_and_pending.add(migration)
163163
 
164
-    to_revert = list(repo.with_dependants(applied_and_modified))
164
+    to_revert = list(project.with_dependants(applied_and_modified))
165165
     _revert_with_feedback(
166166
         runner,
167167
         to_revert,
@@ -170,7 +170,7 @@
170170
         ),
171171
     )
172172
 
173
-    to_apply = list(repo.with_dependencies(applied_and_modified | added_and_pending))
173
+    to_apply = list(project.with_dependencies(applied_and_modified | added_and_pending))
174174
     _deploy_with_feedback(
175175
         runner,
176176
         to_apply,
@@ -188,26 +188,26 @@
188188
     watch: bool,
189189
     allow_new_migrations: bool,
190190
 ) -> None:
191
-    repo = Repository(root)
192
-    covered_migrations = set(repo.by_ids_with_dependencies(migration_ids))
191
+    project = Project(root)
192
+    covered_migrations = set(project.by_ids_with_dependencies(migration_ids))
193193
     if_modified = _resolve_if_modified_policy(if_modified, watch)
194194
 
195195
     with connection_for(database_url) as connection:
196196
         runner = Runner(connection)
197197
         redeploy = _collect_redeploy_migrations(runner, covered_migrations, if_modified)
198
-        _apply_planned_migrations(repo, runner, covered_migrations, redeploy)
198
+        _apply_planned_migrations(project, runner, covered_migrations, redeploy)
199199
 
200200
         if not watch:
201201
             return
202202
 
203
-        incoming_changes = repo.watch_for_changes()
203
+        incoming_changes = project.watch_for_changes()
204204
         while True:
205205
             try:
206206
                 changes = next(incoming_changes)
207207
             except StopIteration:
208208
                 break
209209
             _process_watch_changes(
210
-                repo,
210
+                project,
211211
                 runner,
212212
                 covered_migrations,
213213
                 changes,
@@ -218,7 +218,7 @@
218218
 @app.command(name="add")
219219
 def add(
220220
     migration_ids: list[str],
221
-    root: Annotated[Path, typer.Option("--repository", "-r", help="Repository directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
221
+    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
222222
     database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database connection URL.")] = None,
223223
     if_modified: Annotated[
224224
         IfModifiedOption | None,
@@ -233,10 +233,10 @@
233233
     ] = None,
234234
     watch: Annotated[
235235
         bool,
236
-        typer.Option("--watch", help="Watch the repository and re-run deployments on changes."),
236
+        typer.Option("--watch", help="Watch the project and re-run deployments on changes."),
237237
     ] = False,
238238
 ) -> None:
239
-    """Apply the specified migrations in the repository."""
239
+    """Apply the specified migrations in the project."""
240240
     run_deploy(migration_ids, root, database_url, if_modified, watch, allow_new_migrations=False)
241241
 
242242
 
@@ -246,13 +246,13 @@
246246
     if_modified: IfModifiedOption | None = None,
247247
     watch: bool = False,
248248
 ) -> None:
249
-    repo = Repository(root)
250
-    run_deploy([m.id for m in repo.migrations], root, database_url, if_modified, watch, allow_new_migrations=True)
249
+    project = Project(root)
250
+    run_deploy([m.id for m in project.migrations], root, database_url, if_modified, watch, allow_new_migrations=True)
251251
 
252252
 
253253
 @app.command()
254254
 def up(
255
-    root: Annotated[Path, typer.Option("--repository", "-r", help="Repository directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
255
+    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
256256
     database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database connection URL.")] = None,
257257
     if_modified: Annotated[
258258
         IfModifiedOption | None,
@@ -267,8 +267,8 @@
267267
     ] = None,
268268
     watch: Annotated[
269269
         bool,
270
-        typer.Option("--watch", help="Watch the repository and re-run deployments on changes."),
270
+        typer.Option("--watch", help="Watch the project and re-run deployments on changes."),
271271
     ] = False,
272272
 ) -> None:
273
-    """Apply all pending migrations in the repository."""
273
+    """Apply all pending migrations in the project."""
274274
     run_up(root, database_url, if_modified, watch)

modified src/mitch/cli/log.py +7 −7

@@ -8,10 +8,10 @@
88
 
99
 from ..errors import MissingMigrationError
1010
 from ..helpers import connection_for
11
-from ..repository import Repository
11
+from ..project import Project
1212
 from ..runner import Runner
1313
 
14
-app = typer.Typer(help="Show applied migrations in the repository.")
14
+app = typer.Typer(help="Show applied migrations in the project.")
1515
 
1616
 
1717
 def _format_applied_at(value: object) -> str:
@@ -37,9 +37,9 @@
3737
     root: Annotated[
3838
         Path,
3939
         typer.Option(
40
-            "--repository",
41
-            "-r",
42
-            help="Repository directory.",
40
+            "--project",
41
+            "-p",
42
+            help="Project directory.",
4343
             default_factory=lambda: Path.cwd(),
4444
             dir_okay=True,
4545
             file_okay=False,
@@ -56,7 +56,7 @@
5656
     ] = None,
5757
 ) -> None:
5858
     """Print all currently applied migrations with deployment time and on-disk status."""
59
-    repo = Repository(root)
59
+    project = Project(root)
6060
 
6161
     with connection_for(database_url) as connection:
6262
         runner = Runner(connection)
@@ -79,7 +79,7 @@
7979
         for row in rows:
8080
             migration_id = row.id
8181
             try:
82
-                migration = repo.by_id(migration_id)
82
+                migration = project.by_id(migration_id)
8383
             except MissingMigrationError:
8484
                 status = "missing"
8585
             else:

modified src/mitch/cli/revert.py +12 −12

@@ -5,38 +5,38 @@
55
 import typer
66
 
77
 from ..helpers import connection_for
8
-from ..repository import Repository
8
+from ..project import Project
99
 from ..runner import Runner
1010
 
11
-app = typer.Typer(help="Revert migrations in the repository.")
11
+app = typer.Typer(help="Revert migrations in the project.")
1212
 
1313
 
14
-@app.command(name="down", help="Revert all applied migrations in the repository.")
14
+@app.command(name="down", help="Revert all applied migrations in the project.")
1515
 def down(
16
-    root: Annotated[Path, typer.Option("--repository", "-r", help="Repository directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
16
+    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
1717
     database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database URL. Can also be set via MITCH_DATABASE_URL or DATABASE_URL environment variable.")] = None,
1818
 ) -> None:
19
-    """Revert all applied migrations in the repository."""
20
-    repo = Repository(root)
21
-    drop([migration.id for migration in repo.migrations], root, database_url)
19
+    """Revert all applied migrations in the project."""
20
+    project = Project(root)
21
+    drop([migration.id for migration in project.migrations], root, database_url)
2222
 
2323
 
2424
 @app.command(
2525
     name="drop",
26
-    help="Revert the specified migrations and their dependants in the repository.",
26
+    help="Revert the specified migrations and their dependants in the project.",
2727
 )
2828
 def drop(
2929
     migration_ids: list[str],
30
-    root: Annotated[Path, typer.Option("--repository", "-r", help="Repository directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
30
+    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
3131
     database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database URL. Can also be set via MITCH_DATABASE_URL or DATABASE_URL environment variable.")] = None,
3232
 ) -> None:
33
-    """Revert the specified migrations and their dependants in the repository."""
34
-    repo = Repository(root)
33
+    """Revert the specified migrations and their dependants in the project."""
34
+    project = Project(root)
3535
     with connection_for(database_url) as connection:
3636
         runner = Runner(connection)
3737
         applied_migrations = list(
3838
             migration
39
-            for migration in repo.by_ids_with_dependants(migration_ids)
39
+            for migration in project.by_ids_with_dependants(migration_ids)
4040
             if runner.deployment_status(migration) in ("applied", "modified")
4141
         )
4242
         runner.revert_migrations(

modified src/mitch/cli/stash.py +21 −21

@@ -7,7 +7,7 @@
77
 from ..errors import MissingMigrationError
88
 from ..helpers import connection_for
99
 from ..migration import Migration
10
-from ..repository import Repository
10
+from ..project import Project
1111
 from ..runner import Runner
1212
 from ..vcs import Add, Copied, Modified, Renamed, VersionControlManagerProtocol
1313
 
@@ -15,7 +15,7 @@
1515
 
1616
 
1717
 def _collect_dirty_reconcile_candidates(
18
-    repo_with_local_changes: Repository,
18
+    project_with_local_changes: Project,
1919
     vcs_manager: VersionControlManagerProtocol,
2020
 ) -> set[Migration]:
2121
     # Identify local migration edits that must be reconciled to current commit before stashing.
@@ -24,21 +24,21 @@
2424
     for entry in vcs_manager.local_changes():
2525
         match entry:
2626
             case Modified(path) if path.suffix in (".sql", ".toml"):
27
-                dirty_candidates.add(repo_with_local_changes.by_path(path))
27
+                dirty_candidates.add(project_with_local_changes.by_path(path))
2828
             case Add(path) if path.suffix in (".sql", ".toml"):
2929
                 try:
30
-                    dirty_candidates.add(repo_with_local_changes.by_path(path))
30
+                    dirty_candidates.add(project_with_local_changes.by_path(path))
3131
                 except MissingMigrationError:
3232
                     # Explicitly silenced: a lone local config file without an up script cannot be reconciled.
3333
                     pass
3434
             case Copied(_, new_path) if new_path.suffix in (".sql", ".toml"):
3535
                 try:
36
-                    dirty_candidates.add(repo_with_local_changes.by_path(new_path))
36
+                    dirty_candidates.add(project_with_local_changes.by_path(new_path))
3737
                 except MissingMigrationError:
3838
                     # Explicitly silenced: copied config without a resolvable migration is ignored.
3939
                     pass
4040
             case Renamed(_, new_path) if new_path.suffix in (".sql", ".toml"):
41
-                dirty_candidates.add(repo_with_local_changes.by_path(new_path))
41
+                dirty_candidates.add(project_with_local_changes.by_path(new_path))
4242
             case _:
4343
                 continue
4444
 
@@ -46,17 +46,17 @@
4646
 
4747
 
4848
 def revert_dirty_migrations(
49
-    repo_with_local_changes: Repository,
49
+    project_with_local_changes: Project,
5050
     vcs_manager: VersionControlManagerProtocol,
5151
     database_url: str | None,
5252
 ) -> set[Migration]:
53
-    dirty_candidates = _collect_dirty_reconcile_candidates(repo_with_local_changes, vcs_manager)
53
+    dirty_candidates = _collect_dirty_reconcile_candidates(project_with_local_changes, vcs_manager)
5454
 
5555
     with connection_for(database_url) as connection:
5656
         runner = Runner(connection)
5757
         return set(
5858
             runner.revert_migrations(
59
-                repo_with_local_changes.with_dependants(dirty_candidates),
59
+                project_with_local_changes.with_dependants(dirty_candidates),
6060
                 before_each=lambda migration, status: rich.print(
6161
                     f"[blue]Reverting:[/blue] Migration '{migration.id}' ({status})"
6262
                 ),
@@ -65,14 +65,14 @@
6565
 
6666
 
6767
 def reapply_reverted_migrations(
68
-    repo_with_committed_files: Repository,
68
+    project_with_committed_files: Project,
6969
     reverted_migrations: set[Migration],
7070
     database_url: str | None,
7171
 ) -> set[Migration]:
7272
     reapply_candidates: set[Migration] = set()
7373
     for migration in reverted_migrations:
7474
         try:
75
-            reapply_candidates.add(repo_with_committed_files.by_path(migration.up_script))
75
+            reapply_candidates.add(project_with_committed_files.by_path(migration.up_script))
7676
         except MissingMigrationError:
7777
             # Local-only migrations are intentionally not re-applied in committed state.
7878
             continue
@@ -81,7 +81,7 @@
8181
         runner = Runner(connection)
8282
         return set(
8383
             runner.deploy_migrations(
84
-                repo_with_committed_files.with_dependencies(reapply_candidates),
84
+                project_with_committed_files.with_dependencies(reapply_candidates),
8585
                 before_each=lambda migration, status: rich.print(
8686
                     f"[green]Deploying:[/green] Migration '{migration.id}' ({status})"
8787
                 ),
@@ -94,9 +94,9 @@
9494
     root: Annotated[
9595
         Path,
9696
         typer.Option(
97
-            "--repository",
98
-            "-r",
99
-            help="Repository directory.",
97
+            "--project",
98
+            "-p",
99
+            help="Project directory.",
100100
             default_factory=lambda: Path.cwd(),
101101
             dir_okay=True,
102102
             file_okay=False,
@@ -115,18 +115,18 @@
115115
         Literal["git", "hg"] | None,
116116
         typer.Option(
117117
             "--vcs",
118
-            help="Version control backend. Defaults to auto-detection from repository root.",
118
+            help="Version control backend. Defaults to auto-detection from project root.",
119119
         ),
120120
     ] = None,
121121
 ) -> None:
122
-    repo = Repository(root)
123
-    vcs_manager = repo.get_migration_manager(vcs)
122
+    project = Project(root)
123
+    vcs_manager = project.get_migration_manager(vcs)
124124
 
125125
     if not vcs_manager.is_dirty():
126126
         rich.print("[yellow]No local changes to stash.[/yellow]")
127127
         return
128128
 
129
-    reverted = revert_dirty_migrations(repo, vcs_manager, database_url)
129
+    reverted = revert_dirty_migrations(project, vcs_manager, database_url)
130130
     vcs_manager.stash_changes("stash before mitch stash")
131
-    repo_with_committed_files = Repository(root)
132
-    reapply_reverted_migrations(repo_with_committed_files, reverted, database_url)
131
+    project_with_committed_files = Project(root)
132
+    reapply_reverted_migrations(project_with_committed_files, reverted, database_url)

modified src/mitch/cli/status.py +14 −14

@@ -8,7 +8,7 @@
88
 
99
 from ..errors import MissingMigrationError
1010
 from ..helpers import connection_for
11
-from ..repository import Repository
11
+from ..project import Project
1212
 from ..runner import Runner
1313
 
1414
 app = typer.Typer(help="Show migration integrity and availability status.")
@@ -21,7 +21,7 @@
2121
 
2222
 
2323
 def collect_integrity_report(
24
-    repo: Repository,
24
+    project: Project,
2525
     runner: Runner,
2626
     selected_ids: set[str] | None = None,
2727
 ) -> IntegrityReport:
@@ -34,20 +34,20 @@
3434
 
3535
     # Identify missings
3636
     # Note: applied IDs are already sorted by SQL
37
-    missing = [id_ for id_ in applied_ids if id_ not in repo.migrations_by_id]
37
+    missing = [id_ for id_ in applied_ids if id_ not in project.migrations_by_id]
3838
 
39
-    # Identify modified and available migrations among those present in the repository.
39
+    # Identify modified and available migrations among those present in the project.
4040
     modified: list[str] = []
4141
     available: list[str] = []
4242
 
4343
     # Use selected IDs, if provided, for status reporting.
44
-    # Otherwise, consider all migrations of the repository.
45
-    # Note: If selected IDs are provided, some of them may not be present in the repository.
44
+    # Otherwise, consider all migrations of the project.
45
+    # Note: If selected IDs are provided, some of them may not be present in the project.
4646
     # They will be reported as missing if they are applied, or simply ignored if they are not applied.
47
-    for migration_id in sorted(selected_ids or repo.migrations_by_id.keys()):
48
-        # If the migration ID is not present in the repository, it cannot be modified or available.
47
+    for migration_id in sorted(selected_ids or project.migrations_by_id.keys()):
48
+        # If the migration ID is not present in the project, it cannot be modified or available.
4949
         # If it is applied, it will be caught by the missing check above.
50
-        if not (migration := repo.migrations_by_id.get(migration_id)):
50
+        if not (migration := project.migrations_by_id.get(migration_id)):
5151
             continue
5252
 
5353
         match runner.deployment_status(migration):
@@ -93,9 +93,9 @@
9393
     root: Annotated[
9494
         Path,
9595
         typer.Option(
96
-            "--repository",
97
-            "-r",
98
-            help="Repository directory.",
96
+            "--project",
97
+            "-p",
98
+            help="Project directory.",
9999
             default_factory=lambda: Path.cwd(),
100100
             dir_okay=True,
101101
             file_okay=False,
@@ -132,11 +132,11 @@
132132
     ] = None,
133133
 ) -> None:
134134
     try:
135
-        repo = Repository(root)
135
+        project = Project(root)
136136
         selected_ids = set(migration_ids) if migration_ids is not None else None
137137
         with connection_for(database_url) as connection:
138138
             runner = Runner(connection)
139
-            report = collect_integrity_report(repo, runner, selected_ids)
139
+            report = collect_integrity_report(project, runner, selected_ids)
140140
     except MissingMigrationError:
141141
         raise
142142
     except typer.Exit:

modified src/mitch/errors.py +1 −1

@@ -4,7 +4,7 @@
44
 
55
 
66
 class DuplicateMigrationIdError(Exception):
7
-    """Raised when duplicate migration IDs are found in the repository."""
7
+    """Raised when duplicate migration IDs are found in the project."""
88
     def __init__(self, duplicates: dict[str, list[Migration]]):
99
         self.duplicates = duplicates
1010
         message = self._build_message()

renamed src/mitch/repository.py → src/mitch/project.py +4 −4

@@ -13,7 +13,7 @@
1313
 from .vcs import GitManager, MercurialManager, VersionControlManagerProtocol
1414
 
1515
 
16
-class Repository:
16
+class Project:
1717
     def __init__(self, root_folder: Path | str = Path.cwd()) -> None:
1818
         self.path = Path(root_folder).resolve()
1919
         self._load_migrations()
@@ -222,19 +222,19 @@
222222
 
223223
         if vcs == "git":
224224
             typer.echo(
225
-                "Error: no git repository found at or above the selected repository path.",
225
+                "Error: no git repository found at or above the selected project path.",
226226
                 err=True,
227227
             )
228228
             raise typer.Exit(1)
229229
         if vcs == "hg":
230230
             typer.echo(
231
-                "Error: no Mercurial repository found at or above the selected repository path.",
231
+                "Error: no Mercurial repository found at or above the selected project path.",
232232
                 err=True,
233233
             )
234234
             raise typer.Exit(1)
235235
 
236236
         typer.echo(
237
-            "Error: no supported VCS metadata found at or above repository root (expected .git or .hg).",
237
+            "Error: no supported VCS metadata found at or above project root (expected .git or .hg).",
238238
             err=True,
239239
         )
240240
         raise typer.Exit(1)

modified src/mitch/watcher.py +6 −6

@@ -9,7 +9,7 @@
99
 from watchdog.events import PatternMatchingEventHandler
1010
 from watchdog.observers import Observer
1111
 
12
-from .repository import Repository
12
+from .project import Project
1313
 
1414
 if TYPE_CHECKING:
1515
     class QueueProtocol[T](Protocol):
@@ -124,10 +124,10 @@
124124
 
125125
 
126126
 class Handler(PatternMatchingEventHandler):
127
-    def __init__(self, repo: Repository, debounce: float = 0.3) -> None:
127
+    def __init__(self, project: Project, debounce: float = 0.3) -> None:
128128
         super().__init__(patterns=["*.up.sql", "*.down.sql", "*.config.toml"], ignore_directories=True)
129129
         self._queue: DebouncedQueue[Event] = DebouncedQueue(debounce_time=debounce)
130
-        self._repo = repo
130
+        self._project = project
131131
         self._reload_requested = False
132132
 
133133
     @staticmethod
@@ -165,10 +165,10 @@
165165
             self._queue.task_done()
166166
 
167167
 
168
-def wait_for_changes(repo: Repository, debounce: float) -> Iterable[list[Event]]:
169
-    handler = Handler(repo, debounce)
168
+def wait_for_changes(project: Project, debounce: float) -> Iterable[list[Event]]:
169
+    handler = Handler(project, debounce)
170170
     observer = Observer()
171
-    observer.schedule(handler, str(repo.path), recursive=True)
171
+    observer.schedule(handler, str(project.path), recursive=True)
172172
     observer.start()
173173
     try:
174174
         while True:

renamed tests/repository-with-duplicate-ids/001-migration.config.toml → tests/project-with-duplicate-ids/001-migration.config.toml +0 −0

renamed tests/repository-with-duplicate-ids/001-migration.up.sql → tests/project-with-duplicate-ids/001-migration.up.sql +0 −0

renamed tests/repository-with-duplicate-ids/002-migration.config.toml → tests/project-with-duplicate-ids/002-migration.config.toml +0 −0

renamed tests/repository-with-duplicate-ids/002-migration.up.sql → tests/project-with-duplicate-ids/002-migration.up.sql +0 −0

modified tests/test_checkout_hg.py +2 −2

@@ -61,7 +61,7 @@
6161
         app,
6262
         [
6363
             "up",
64
-            "--repository",
64
+            "--project",
6565
             str(repo_path),
6666
             "--database",
6767
             database_url,
@@ -81,7 +81,7 @@
8181
         [
8282
             "checkout",
8383
             "target",
84
-            "--repository",
84
+            "--project",
8585
             str(repo_path),
8686
             "--database",
8787
             database_url,

modified tests/test_cli.py +68 −68

@@ -6,7 +6,7 @@
66
 from typer.testing import CliRunner
77
 
88
 from mitch.cli import app
9
-from mitch.repository import Repository
9
+from mitch.project import Project
1010
 from mitch.watcher import EventType
1111
 
1212
 runner = CliRunner()
@@ -53,7 +53,7 @@
5353
     result = runner.invoke(app, ["add", "--help"])
5454
 
5555
     assert result.exit_code == 0
56
-    assert "Apply the specified migrations in the repository." in result.output
56
+    assert "Apply the specified migrations in the project." in result.output
5757
 
5858
 
5959
 def test_up_help_includes_watch_options():
@@ -68,10 +68,10 @@
6868
     drop_help = runner.invoke(app, ["drop", "--help"])
6969
 
7070
     assert down_help.exit_code == 0
71
-    assert "Revert all applied migrations in the repository." in down_help.output
71
+    assert "Revert all applied migrations in the project." in down_help.output
7272
 
7373
     assert drop_help.exit_code == 0
74
-    assert "Revert the specified migrations and their dependants in the repository." in drop_help.output
74
+    assert "Revert the specified migrations and their dependants in the project." in drop_help.output
7575
 
7676
 
7777
 def test_stash_help_mentions_stashing_behavior():
@@ -98,7 +98,7 @@
9898
         [
9999
             "add",
100100
             "001-init",
101
-            "--repository",
101
+            "--project",
102102
             "tests/migrations",
103103
             "--database",
104104
             database_url,
@@ -125,7 +125,7 @@
125125
         [
126126
             "create",
127127
             "001-init",
128
-            "--repository",
128
+            "--project",
129129
             str(tmp_path),
130130
         ],
131131
     )
@@ -152,7 +152,7 @@
152152
         [
153153
             "create",
154154
             "001-init",
155
-            "--repository",
155
+            "--project",
156156
             str(tmp_path),
157157
             "--dependency",
158158
             "missing-migration",
@@ -169,7 +169,7 @@
169169
         [
170170
             "create",
171171
             "001-init",
172
-            "--repository",
172
+            "--project",
173173
             str(tmp_path),
174174
             "--skip-config",
175175
             "--skip-downscript",
@@ -200,14 +200,14 @@
200200
         )
201201
         yield [(EventType.CREATED, repo_path / "002-add.up.sql")]
202202
 
203
-    monkeypatch.setattr(Repository, "watch_for_changes", fake_watch_for_changes)
203
+    monkeypatch.setattr(Project, "watch_for_changes", fake_watch_for_changes)
204204
 
205205
     result = runner.invoke(
206206
         app,
207207
         [
208208
             "up",
209209
             "--watch",
210
-            "--repository",
210
+            "--project",
211211
             str(repo_path),
212212
             "--database",
213213
             database_url,
@@ -234,7 +234,7 @@
234234
         app,
235235
         [
236236
             "up",
237
-            "--repository",
237
+            "--project",
238238
             "tests/migrations",
239239
             "--database",
240240
             database_url,
@@ -287,7 +287,7 @@
287287
         app,
288288
         [
289289
             "up",
290
-            "--repository",
290
+            "--project",
291291
             str(repo_path),
292292
             "--database",
293293
             database_url,
@@ -302,7 +302,7 @@
302302
         [
303303
             "drop",
304304
             "002-next",
305
-            "--repository",
305
+            "--project",
306306
             str(repo_path),
307307
             "--database",
308308
             database_url,
@@ -334,7 +334,7 @@
334334
         app,
335335
         [
336336
             "up",
337
-            "--repository",
337
+            "--project",
338338
             "tests/migrations",
339339
             "--database",
340340
             database_url,
@@ -348,7 +348,7 @@
348348
         app,
349349
         [
350350
             "log",
351
-            "--repository",
351
+            "--project",
352352
             "tests/migrations",
353353
             "--database",
354354
             database_url,
@@ -380,7 +380,7 @@
380380
         app,
381381
         [
382382
             "up",
383
-            "--repository",
383
+            "--project",
384384
             str(repo_path),
385385
             "--database",
386386
             database_url,
@@ -399,7 +399,7 @@
399399
         app,
400400
         [
401401
             "log",
402
-            "--repository",
402
+            "--project",
403403
             str(repo_path),
404404
             "--database",
405405
             database_url,
@@ -437,7 +437,7 @@
437437
         app,
438438
         [
439439
             "up",
440
-            "--repository",
440
+            "--project",
441441
             str(repo_path),
442442
             "--database",
443443
             database_url,
@@ -453,7 +453,7 @@
453453
         app,
454454
         [
455455
             "stash",
456
-            "--repository",
456
+            "--project",
457457
             str(repo_path),
458458
             "--database",
459459
             database_url,
@@ -491,7 +491,7 @@
491491
         app,
492492
         [
493493
             "stash",
494
-            "--repository",
494
+            "--project",
495495
             str(repo_path),
496496
             "--database",
497497
             database_url,
@@ -515,7 +515,7 @@
515515
         app,
516516
         [
517517
             "up",
518
-            "--repository",
518
+            "--project",
519519
             str(repo_path),
520520
             "--database",
521521
             database_url,
@@ -539,7 +539,7 @@
539539
         app,
540540
         [
541541
             "status",
542
-            "--repository",
542
+            "--project",
543543
             str(repo_path),
544544
             "--database",
545545
             database_url,
@@ -564,7 +564,7 @@
564564
         app,
565565
         [
566566
             "up",
567
-            "--repository",
567
+            "--project",
568568
             str(repo_path),
569569
             "--database",
570570
             database_url,
@@ -590,7 +590,7 @@
590590
             "status",
591591
             "002-next",
592592
             "003-pending",
593
-            "--repository",
593
+            "--project",
594594
             str(repo_path),
595595
             "--database",
596596
             database_url,
@@ -615,7 +615,7 @@
615615
         app,
616616
         [
617617
             "up",
618
-            "--repository",
618
+            "--project",
619619
             str(repo_path),
620620
             "--database",
621621
             database_url,
@@ -632,7 +632,7 @@
632632
         [
633633
             "status",
634634
             "--ci",
635
-            "--repository",
635
+            "--project",
636636
             str(repo_path),
637637
             "--database",
638638
             database_url,
@@ -655,7 +655,7 @@
655655
         app,
656656
         [
657657
             "up",
658
-            "--repository",
658
+            "--project",
659659
             str(repo_path),
660660
             "--database",
661661
             database_url,
@@ -676,7 +676,7 @@
676676
             "status",
677677
             "--ci",
678678
             "--strict",
679
-            "--repository",
679
+            "--project",
680680
             str(repo_path),
681681
             "--database",
682682
             database_url,
@@ -699,7 +699,7 @@
699699
         app,
700700
         [
701701
             "up",
702
-            "--repository",
702
+            "--project",
703703
             str(repo_path),
704704
             "--database",
705705
             database_url,
@@ -721,7 +721,7 @@
721721
             "status",
722722
             "--ci",
723723
             "--strict",
724
-            "--repository",
724
+            "--project",
725725
             str(repo_path),
726726
             "--database",
727727
             database_url,
@@ -745,7 +745,7 @@
745745
         app,
746746
         [
747747
             "up",
748
-            "--repository",
748
+            "--project",
749749
             str(repo_path),
750750
             "--database",
751751
             database_url,
@@ -762,7 +762,7 @@
762762
         app,
763763
         [
764764
             "status",
765
-            "--repository",
765
+            "--project",
766766
             str(repo_path),
767767
             "--database",
768768
             database_url,
@@ -784,7 +784,7 @@
784784
         app,
785785
         [
786786
             "up",
787
-            "--repository",
787
+            "--project",
788788
             str(repo_path),
789789
             "--database",
790790
             database_url,
@@ -802,7 +802,7 @@
802802
         [
803803
             "status",
804804
             "--no-ci",
805
-            "--repository",
805
+            "--project",
806806
             str(repo_path),
807807
             "--database",
808808
             database_url,
@@ -837,7 +837,7 @@
837837
         app,
838838
         [
839839
             "up",
840
-            "--repository",
840
+            "--project",
841841
             str(repo_path),
842842
             "--database",
843843
             database_url,
@@ -857,7 +857,7 @@
857857
         [
858858
             "checkout",
859859
             "target",
860
-            "--repository",
860
+            "--project",
861861
             str(repo_path),
862862
             "--database",
863863
             database_url,
@@ -878,7 +878,7 @@
878878
     assert table is None
879879
 
880880
 
881
-def test_checkout_works_when_repository_is_subfolder_of_git_repo(tmp_path):
881
+def test_checkout_works_when_project_is_subfolder_of_git_repo(tmp_path):
882882
     repo_path = tmp_path / "repo"
883883
     repo_path.mkdir()
884884
     _init_git_repo(repo_path)
@@ -904,7 +904,7 @@
904904
         app,
905905
         [
906906
             "up",
907
-            "--repository",
907
+            "--project",
908908
             str(migrations_path),
909909
             "--database",
910910
             database_url,
@@ -924,7 +924,7 @@
924924
         [
925925
             "checkout",
926926
             "target",
927
-            "--repository",
927
+            "--project",
928928
             str(migrations_path),
929929
             "--database",
930930
             database_url,
@@ -965,7 +965,7 @@
965965
         app,
966966
         [
967967
             "up",
968
-            "--repository",
968
+            "--project",
969969
             str(repo_path),
970970
             "--database",
971971
             database_url,
@@ -994,7 +994,7 @@
994994
         [
995995
             "checkout",
996996
             "target",
997
-            "--repository",
997
+            "--project",
998998
             str(repo_path),
999999
             "--database",
10001000
             database_url,
@@ -1041,7 +1041,7 @@
10411041
         app,
10421042
         [
10431043
             "up",
1044
-            "--repository",
1044
+            "--project",
10451045
             str(repo_path),
10461046
             "--database",
10471047
             database_url,
@@ -1062,7 +1062,7 @@
10621062
         [
10631063
             "checkout",
10641064
             "target",
1065
-            "--repository",
1065
+            "--project",
10661066
             str(repo_path),
10671067
             "--database",
10681068
             database_url,
@@ -1103,7 +1103,7 @@
11031103
         app,
11041104
         [
11051105
             "up",
1106
-            "--repository",
1106
+            "--project",
11071107
             str(repo_path),
11081108
             "--database",
11091109
             database_url,
@@ -1126,7 +1126,7 @@
11261126
         [
11271127
             "checkout",
11281128
             "target",
1129
-            "--repository",
1129
+            "--project",
11301130
             str(repo_path),
11311131
             "--database",
11321132
             database_url,
@@ -1174,7 +1174,7 @@
11741174
         app,
11751175
         [
11761176
             "up",
1177
-            "--repository",
1177
+            "--project",
11781178
             str(repo_path),
11791179
             "--database",
11801180
             database_url,
@@ -1204,7 +1204,7 @@
12041204
         [
12051205
             "checkout",
12061206
             "target",
1207
-            "--repository",
1207
+            "--project",
12081208
             str(repo_path),
12091209
             "--database",
12101210
             database_url,
@@ -1261,7 +1261,7 @@
12611261
         app,
12621262
         [
12631263
             "up",
1264
-            "--repository",
1264
+            "--project",
12651265
             str(repo_path),
12661266
             "--database",
12671267
             database_url,
@@ -1288,7 +1288,7 @@
12881288
         [
12891289
             "checkout",
12901290
             "target",
1291
-            "--repository",
1291
+            "--project",
12921292
             str(repo_path),
12931293
             "--database",
12941294
             database_url,
@@ -1345,7 +1345,7 @@
13451345
         app,
13461346
         [
13471347
             "up",
1348
-            "--repository",
1348
+            "--project",
13491349
             str(repo_path),
13501350
             "--database",
13511351
             database_url,
@@ -1366,7 +1366,7 @@
13661366
         [
13671367
             "checkout",
13681368
             "target",
1369
-            "--repository",
1369
+            "--project",
13701370
             str(repo_path),
13711371
             "--database",
13721372
             database_url,
@@ -1422,7 +1422,7 @@
14221422
         [
14231423
             "checkout",
14241424
             "target",
1425
-            "--repository",
1425
+            "--project",
14261426
             str(repo_path),
14271427
             "--database",
14281428
             database_url,
@@ -1468,7 +1468,7 @@
14681468
         app,
14691469
         [
14701470
             "up",
1471
-            "--repository",
1471
+            "--project",
14721472
             str(repo_path),
14731473
             "--database",
14741474
             database_url,
@@ -1496,7 +1496,7 @@
14961496
         [
14971497
             "checkout",
14981498
             "target",
1499
-            "--repository",
1499
+            "--project",
15001500
             str(repo_path),
15011501
             "--database",
15021502
             database_url,
@@ -1540,7 +1540,7 @@
15401540
         app,
15411541
         [
15421542
             "up",
1543
-            "--repository",
1543
+            "--project",
15441544
             str(repo_path),
15451545
             "--database",
15461546
             database_url,
@@ -1568,7 +1568,7 @@
15681568
         [
15691569
             "checkout",
15701570
             "target",
1571
-            "--repository",
1571
+            "--project",
15721572
             str(repo_path),
15731573
             "--database",
15741574
             database_url,
@@ -1625,7 +1625,7 @@
16251625
         app,
16261626
         [
16271627
             "up",
1628
-            "--repository",
1628
+            "--project",
16291629
             str(repo_path),
16301630
             "--database",
16311631
             database_url,
@@ -1649,7 +1649,7 @@
16491649
         [
16501650
             "checkout",
16511651
             "target",
1652
-            "--repository",
1652
+            "--project",
16531653
             str(repo_path),
16541654
             "--database",
16551655
             database_url,
@@ -1701,7 +1701,7 @@
17011701
         app,
17021702
         [
17031703
             "up",
1704
-            "--repository",
1704
+            "--project",
17051705
             str(repo_path),
17061706
             "--database",
17071707
             database_url,
@@ -1725,7 +1725,7 @@
17251725
         [
17261726
             "checkout",
17271727
             "target",
1728
-            "--repository",
1728
+            "--project",
17291729
             str(repo_path),
17301730
             "--database",
17311731
             database_url,
@@ -1766,7 +1766,7 @@
17661766
         app,
17671767
         [
17681768
             "up",
1769
-            "--repository",
1769
+            "--project",
17701770
             str(repo_path),
17711771
             "--database",
17721772
             database_url,
@@ -1790,7 +1790,7 @@
17901790
         [
17911791
             "checkout",
17921792
             "target",
1793
-            "--repository",
1793
+            "--project",
17941794
             str(repo_path),
17951795
             "--database",
17961796
             database_url,
@@ -1835,7 +1835,7 @@
18351835
         app,
18361836
         [
18371837
             "up",
1838
-            "--repository",
1838
+            "--project",
18391839
             str(repo_path),
18401840
             "--database",
18411841
             database_url,
@@ -1855,7 +1855,7 @@
18551855
         [
18561856
             "checkout",
18571857
             "target",
1858
-            "--repository",
1858
+            "--project",
18591859
             str(repo_path),
18601860
             "--database",
18611861
             database_url,
@@ -1904,7 +1904,7 @@
19041904
         app,
19051905
         [
19061906
             "up",
1907
-            "--repository",
1907
+            "--project",
19081908
             str(repo_path),
19091909
             "--database",
19101910
             database_url,
@@ -1930,7 +1930,7 @@
19301930
         [
19311931
             "checkout",
19321932
             "target",
1933
-            "--repository",
1933
+            "--project",
19341934
             str(repo_path),
19351935
             "--database",
19361936
             database_url,
@@ -1976,7 +1976,7 @@
19761976
         app,
19771977
         [
19781978
             "up",
1979
-            "--repository",
1979
+            "--project",
19801980
             str(repo_path),
19811981
             "--database",
19821982
             database_url,
@@ -2006,7 +2006,7 @@
20062006
         [
20072007
             "checkout",
20082008
             "target",
2009
-            "--repository",
2009
+            "--project",
20102010
             str(repo_path),
20112011
             "--database",
20122012
             database_url,

modified tests/test_errors.py +4 −4

@@ -3,12 +3,12 @@
33
 import pytest
44
 
55
 from mitch.errors import DuplicateMigrationIdError, MissingMigrationError
6
-from mitch.repository import Repository
6
+from mitch.project import Project
77
 
88
 
99
 def test_duplicate_migration_ids_raise():
1010
     with pytest.raises(DuplicateMigrationIdError) as exc_info:
11
-        Repository(Path("tests/repository-with-duplicate-ids"))
11
+        Project(Path("tests/project-with-duplicate-ids"))
1212
 
1313
     duplicates = exc_info.value.duplicates
1414
     assert "same-id" in duplicates
@@ -16,9 +16,9 @@
1616
 
1717
 
1818
 def test_missing_migration_error_message():
19
-    repo = Repository("tests/migrations")
19
+    project = Project("tests/migrations")
2020
 
2121
     with pytest.raises(MissingMigrationError) as exc_info:
22
-        repo.by_id("missing-id")
22
+        project.by_id("missing-id")
2323
 
2424
     assert "missing-id" in str(exc_info.value)

renamed tests/test_repository.py → tests/test_project.py +18 −18

@@ -4,7 +4,7 @@
44
 from typer import Exit
55
 
66
 from mitch.errors import MissingMigrationError
7
-from mitch.repository import Repository
7
+from mitch.project import Project
88
 from mitch.vcs import GitManager
99
 
1010
 
@@ -24,10 +24,10 @@
2424
     _run_git(path, "init")
2525
 
2626
 
27
-def test_load_repository():
28
-    repo = Repository("tests/migrations")
27
+def test_load_project():
28
+    project = Project("tests/migrations")
2929
 
30
-    migration = repo.by_id("001-init")
30
+    migration = project.by_id("001-init")
3131
     assert migration is not None
3232
 
3333
     assert migration.id == "001-init"
@@ -39,16 +39,16 @@
3939
     assert migration.dependencies == set()
4040
 
4141
 
42
-def test_load_repository_with_dependencies():
43
-    repo = Repository("tests/migrations")
44
-    migrations = list(repo.by_ids_with_dependencies(["002-add-column"]))
42
+def test_load_project_with_dependencies():
43
+    project = Project("tests/migrations")
44
+    migrations = list(project.by_ids_with_dependencies(["002-add-column"]))
4545
     assert migrations[0].id == "001-init"
4646
     assert migrations[1].id == "002-add-column"
4747
 
4848
 
49
-def test_load_repository_with_dependants():
50
-    repo = Repository("tests/migrations")
51
-    migrations = list(repo.by_ids_with_dependants(["001-init"]))
49
+def test_load_project_with_dependants():
50
+    project = Project("tests/migrations")
51
+    migrations = list(project.by_ids_with_dependants(["001-init"]))
5252
     assert migrations[0].id == "002-add-column"
5353
     assert migrations[1].id == "001-init"
5454
 
@@ -63,18 +63,18 @@
6363
     (tmp_path / "004-new.up.sql").write_text("SELECT 1;", encoding="utf-8")
6464
     (tmp_path / "004-new.config.toml").write_text("created_at = 2020-01-02\n", encoding="utf-8")
6565
 
66
-    repo = Repository(tmp_path)
67
-    migrations = list(repo.by_ids_with_dependencies(["001-init", "002-second", "003-old", "004-new"]))
66
+    project = Project(tmp_path)
67
+    migrations = list(project.by_ids_with_dependencies(["001-init", "002-second", "003-old", "004-new"]))
6868
 
6969
     assert [m.id for m in migrations] == ["003-old", "004-new", "001-init", "002-second"]
7070
 
7171
 
7272
 def test_by_paths_raises_if_any_path_is_missing():
73
-    repo = Repository("tests/migrations")
73
+    project = Project("tests/migrations")
7474
 
7575
     with pytest.raises(MissingMigrationError):
7676
         list(
77
-            repo.by_paths(
77
+            project.by_paths(
7878
                 [
7979
                     "tests/migrations/001-init.up.sql",
8080
                     "tests/migrations/does-not-exist.up.sql",
@@ -92,15 +92,15 @@
9292
     migrations_path.mkdir()
9393
     (migrations_path / "001-init.up.sql").write_text("SELECT 1;", encoding="utf-8")
9494
 
95
-    repo = Repository(migrations_path)
95
+    project = Project(migrations_path)
9696
 
97
-    manager = repo.get_migration_manager()
97
+    manager = project.get_migration_manager()
9898
 
9999
     assert isinstance(manager, GitManager)
100100
 
101101
 
102102
 def test_get_migration_manager_raises_when_no_repository_metadata(tmp_path):
103
-    repo = Repository(tmp_path)
103
+    project = Project(tmp_path)
104104
 
105105
     with pytest.raises(Exit):
106
-        repo.get_migration_manager()
106
+        project.get_migration_manager()

modified tests/test_runner.py +16 −16

@@ -9,21 +9,21 @@
99
 
1010
 from mitch.helpers import batch_transactional_migrations
1111
 from mitch.migration import Migration
12
-from mitch.repository import Repository
12
+from mitch.project import Project
1313
 from mitch.runner import Runner
1414
 
1515
 
1616
 @pytest.fixture
17
-def repo():
18
-    yield Repository(Path("tests/migrations"))
17
+def project():
18
+    yield Project(Path("tests/migrations"))
1919
 
2020
 
2121
 @pytest.fixture
22
-def cloned_repo(tmp_path):
22
+def cloned_project(tmp_path):
2323
     source = Path("tests/migrations")
2424
     dest = tmp_path / "migrations"
2525
     shutil.copytree(source, dest)
26
-    yield Repository(dest)
26
+    yield Project(dest)
2727
 
2828
 
2929
 @pytest.fixture
@@ -40,8 +40,8 @@
4040
 
4141
 
4242
 
43
-def test_runner_apply_migration(repo, runner, connection):
44
-    due_migrations = list(repo.by_ids_with_dependencies(["001-init"]))
43
+def test_runner_apply_migration(project, runner, connection):
44
+    due_migrations = list(project.by_ids_with_dependencies(["001-init"]))
4545
 
4646
     # Check that the migrations are marked as applied
4747
     for migration in due_migrations:
@@ -129,11 +129,11 @@
129129
     assert statements == []
130130
 
131131
 
132
-def test_setup_project_copies_migrations_isolated(cloned_repo):
132
+def test_setup_project_copies_migrations_isolated(cloned_project):
133133
     original_sql = Path("tests/migrations/001-init.up.sql").read_text(encoding="utf-8")
134134
 
135
-    assert cloned_repo.path.is_relative_to(Path(tempfile.gettempdir()))
136
-    migration = cloned_repo.by_id("001-init")
135
+    assert cloned_project.path.is_relative_to(Path(tempfile.gettempdir()))
136
+    migration = cloned_project.by_id("001-init")
137137
     modified_sql = original_sql + "\n-- mutated during test\n"
138138
     migration.up_script.write_text(modified_sql, encoding="utf-8")
139139
     assert migration.up_script.read_text(encoding="utf-8") == modified_sql
@@ -142,8 +142,8 @@
142142
     assert unchanged_sql == original_sql
143143
 
144144
 
145
-def test_runner_reapply_modified_migration_raises(cloned_repo, runner):
146
-    migration = cloned_repo.by_id("001-init")
145
+def test_runner_reapply_modified_migration_raises(cloned_project, runner):
146
+    migration = cloned_project.by_id("001-init")
147147
     runner.apply_migration(migration)
148148
 
149149
     modified_sql = (
@@ -156,8 +156,8 @@
156156
         runner.apply_migration(migration)
157157
 
158158
 
159
-def test_runner_reapply_with_only_comments_or_whitespace_is_ok(cloned_repo, runner):
160
-    migration = cloned_repo.by_id("001-init")
159
+def test_runner_reapply_with_only_comments_or_whitespace_is_ok(cloned_project, runner):
160
+    migration = cloned_project.by_id("001-init")
161161
     runner.apply_migration(migration)
162162
 
163163
     original_sql = migration.up_script.read_text(encoding="utf-8")
@@ -219,8 +219,8 @@
219219
             raise RuntimeError("boom")
220220
 
221221
 
222
-def test_runner_deployment_status_updates_normalized_hash(cloned_repo, runner, connection):
223
-    migration = cloned_repo.by_id("001-init")
222
+def test_runner_deployment_status_updates_normalized_hash(cloned_project, runner, connection):
223
+    migration = cloned_project.by_id("001-init")
224224
     runner.apply_migration(migration)
225225
 
226226
     connection.execute(