Rename Repository to Project
public
Rename Repository to Project
| Changeset | b1da7291a47c60118ff3966bcc35c0d4814884cd |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | b7b1e183d424 |
| Children | |
| Pushlog | by timo via ssh |
modified src/mitch/cli/checkout.py +29 −29
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | from ..errors import MissingMigrationError |
| 11 | 11 | from ..helpers import connection_for |
| 12 | -from ..repository import Repository | |
| 12 | +from ..project import Project | |
| 13 | 13 | from ..runner import Runner |
| 14 | 14 | from ..vcs import Add, Copied, Deleted, Modified, Renamed |
| 15 | 15 | from .deploy import IfModifiedOption, run_up |
| @@ -31,9 +31,9 @@ | ||
| 31 | 31 | root: Annotated[ |
| 32 | 32 | Path, |
| 33 | 33 | typer.Option( |
| 34 | - "--repository", | |
| 35 | - "-r", | |
| 36 | - help="Repository directory.", | |
| 34 | + "--project", | |
| 35 | + "-p", | |
| 36 | + help="Project directory.", | |
| 37 | 37 | default_factory=lambda: Path.cwd(), |
| 38 | 38 | dir_okay=True, |
| 39 | 39 | file_okay=False, |
| @@ -66,13 +66,13 @@ | ||
| 66 | 66 | Literal["git", "hg"] | None, |
| 67 | 67 | typer.Option( |
| 68 | 68 | "--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.", | |
| 70 | 70 | ), |
| 71 | 71 | ] = None, |
| 72 | 72 | ) -> None: |
| 73 | 73 | """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) | |
| 76 | 76 | |
| 77 | 77 | # Policy overview for later review: |
| 78 | 78 | # 1) Branch transition semantics are commit-based (current commit -> target commit). |
| @@ -86,7 +86,7 @@ | ||
| 86 | 86 | should_pop_stash = allow_dirty and vcs_manager.is_dirty() |
| 87 | 87 | restore_candidate_paths: set[Path] = set() |
| 88 | 88 | |
| 89 | - def _build_branch_transition_plan(repo_before_checkout: Repository) -> BranchTransitionPlan: | |
| 89 | + def _build_branch_transition_plan(project_before_checkout: Project) -> BranchTransitionPlan: | |
| 90 | 90 | # Build a commit-to-commit transition plan (current commit -> target commit). |
| 91 | 91 | up_modified: set[Migration] = set() |
| 92 | 92 | up_deleted: set[Migration] = set() |
| @@ -99,24 +99,24 @@ | ||
| 99 | 99 | for entry in vcs_manager.changes(branch): |
| 100 | 100 | match entry: |
| 101 | 101 | 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)) | |
| 103 | 103 | 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)) | |
| 105 | 105 | 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)) | |
| 107 | 107 | 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)) | |
| 109 | 109 | 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)) | |
| 111 | 111 | moved_paths[old_path] = new_path |
| 112 | 112 | 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)) | |
| 114 | 114 | moved_paths[old_path] = new_path |
| 115 | 115 | case Add(path) if path.suffix == ".sql": |
| 116 | 116 | target_added_paths.add(path) |
| 117 | 117 | case Add(path) if path.suffix == ".toml": |
| 118 | 118 | 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"))) | |
| 120 | 120 | except MissingMigrationError: |
| 121 | 121 | # Explicitly silenced: config-only target additions without a known current migration |
| 122 | 122 | # do not participate in pre-checkout reverts. |
| @@ -125,7 +125,7 @@ | ||
| 125 | 125 | target_added_paths.add(new_path) |
| 126 | 126 | case Copied(_, new_path) if new_path.suffix == ".toml": |
| 127 | 127 | 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"))) | |
| 129 | 129 | except MissingMigrationError: |
| 130 | 130 | # Explicitly silenced: copied configs for unknown current migrations are ignored here. |
| 131 | 131 | pass |
| @@ -138,7 +138,7 @@ | ||
| 138 | 138 | |
| 139 | 139 | # Step 1: Reconcile dirty local migration edits to current commit state before stashing. |
| 140 | 140 | 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) | |
| 142 | 142 | restore_candidate_paths.update(migration.up_script for migration in dirty_reverted) |
| 143 | 143 | |
| 144 | 144 | # Step 2: Stash local changes so file system reflects current commit state. |
| @@ -147,16 +147,16 @@ | ||
| 147 | 147 | # Step 5: Checkout the target revision. |
| 148 | 148 | # Step 6: Restore stashed local changes. |
| 149 | 149 | 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) | |
| 152 | 152 | restore_candidate_paths.difference_update(migration.up_script for migration in reapplied_on_current) |
| 153 | 153 | |
| 154 | - branch_plan = _build_branch_transition_plan(repo_current) | |
| 154 | + branch_plan = _build_branch_transition_plan(project_current) | |
| 155 | 155 | with connection_for(database_url) as connection: |
| 156 | 156 | runner = Runner(connection) |
| 157 | 157 | reverted_for_branch_transition = set( |
| 158 | 158 | runner.revert_migrations( |
| 159 | - repo_current.with_dependants(branch_plan.revert_candidates), | |
| 159 | + project_current.with_dependants(branch_plan.revert_candidates), | |
| 160 | 160 | before_each=lambda migration, status: rich.print( |
| 161 | 161 | f"[blue]Reverting:[/blue] Migration '{migration.id}' ({status})" |
| 162 | 162 | ), |
| @@ -167,16 +167,16 @@ | ||
| 167 | 167 | |
| 168 | 168 | vcs_manager.checkout(branch) |
| 169 | 169 | |
| 170 | - repo_after = Repository(root) | |
| 170 | + project_after = Project(root) | |
| 171 | 171 | target_added_paths = branch_plan.target_added_paths |
| 172 | 172 | else: |
| 173 | 173 | # 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) | |
| 175 | 175 | with connection_for(database_url) as connection: |
| 176 | 176 | runner = Runner(connection) |
| 177 | 177 | reverted_for_branch_transition = set( |
| 178 | 178 | runner.revert_migrations( |
| 179 | - repo.with_dependants(branch_plan.revert_candidates), | |
| 179 | + project.with_dependants(branch_plan.revert_candidates), | |
| 180 | 180 | before_each=lambda migration, status: rich.print( |
| 181 | 181 | f"[blue]Reverting:[/blue] Migration '{migration.id}' ({status})" |
| 182 | 182 | ), |
| @@ -187,19 +187,19 @@ | ||
| 187 | 187 | |
| 188 | 188 | # Step 5 (clean worktree): Checkout the target revision. |
| 189 | 189 | vcs_manager.checkout(branch) |
| 190 | - repo_after = Repository(root) | |
| 190 | + project_after = Project(root) | |
| 191 | 191 | |
| 192 | 192 | # Step 7: Apply migrations from the final filesystem state according to policy. |
| 193 | 193 | # - 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`). | |
| 195 | 195 | 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) | |
| 197 | 197 | return |
| 198 | 198 | |
| 199 | 199 | apply_migrations: set[Migration] = set() |
| 200 | 200 | for path in restore_candidate_paths: |
| 201 | 201 | try: |
| 202 | - apply_migrations.add(repo_after.by_path(path)) | |
| 202 | + apply_migrations.add(project_after.by_path(path)) | |
| 203 | 203 | except MissingMigrationError: |
| 204 | 204 | # Reverted migrations missing after checkout+restore stay reverted by design. |
| 205 | 205 | continue |
| @@ -207,7 +207,7 @@ | ||
| 207 | 207 | with connection_for(database_url) as connection: |
| 208 | 208 | runner = Runner(connection) |
| 209 | 209 | runner.deploy_migrations( |
| 210 | - repo_after.with_dependencies(apply_migrations), | |
| 210 | + project_after.with_dependencies(apply_migrations), | |
| 211 | 211 | before_each=lambda migration, status: rich.print( |
| 212 | 212 | f"[green]Deploying:[/green] Migration '{migration.id}' ({status})" |
| 213 | 213 | ), |
modified src/mitch/cli/create.py +8 −8
| @@ -4,9 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | import typer |
| 6 | 6 | |
| 7 | -from ..repository import Repository | |
| 7 | +from ..project import Project | |
| 8 | 8 | |
| 9 | -app = typer.Typer(help="Add new migrations to the repository.") | |
| 9 | +app = typer.Typer(help="Add new migrations to the project.") | |
| 10 | 10 | |
| 11 | 11 | |
| 12 | 12 | @app.command() |
| @@ -15,9 +15,9 @@ | ||
| 15 | 15 | root: Annotated[ |
| 16 | 16 | Path, |
| 17 | 17 | typer.Option( |
| 18 | - "--repository", | |
| 19 | - "-r", | |
| 20 | - help="Repository directory.", | |
| 18 | + "--project", | |
| 19 | + "-p", | |
| 20 | + help="Project directory.", | |
| 21 | 21 | default_factory=Path.cwd, |
| 22 | 22 | dir_okay=True, |
| 23 | 23 | file_okay=False, |
| @@ -37,7 +37,7 @@ | ||
| 37 | 37 | bool, typer.Option("--skip-downscript", "-sd", help="Skip creating a downscript for the migration.") |
| 38 | 38 | ] = False, |
| 39 | 39 | ) -> None: |
| 40 | - """Create a new migration scaffold in the repository. | |
| 40 | + """Create a new migration scaffold in the project. | |
| 41 | 41 | |
| 42 | 42 | Args: |
| 43 | 43 | migration_id: The ID of the new migration. |
| @@ -46,8 +46,8 @@ | ||
| 46 | 46 | migration_path = Path(root) / migration_id |
| 47 | 47 | |
| 48 | 48 | # 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] | |
| 51 | 51 | if missing_dependencies: |
| 52 | 52 | typer.echo(f"Error: Missing dependencies: {', '.join(missing_dependencies)}", err=True) |
| 53 | 53 | raise typer.Exit(1) |
modified src/mitch/cli/deploy.py +24 −24
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | |
| 9 | 9 | from ..helpers import connection_for |
| 10 | 10 | from ..migration import Migration |
| 11 | -from ..repository import Repository | |
| 11 | +from ..project import Project | |
| 12 | 12 | from ..runner import DeploymentStatus, Runner |
| 13 | 13 | from ..watcher import EventType |
| 14 | 14 | |
| @@ -105,12 +105,12 @@ | ||
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | def _apply_planned_migrations( |
| 108 | - repo: Repository, | |
| 108 | + project: Project, | |
| 109 | 109 | runner: Runner, |
| 110 | 110 | covered_migrations: set[Migration], |
| 111 | 111 | redeploy: set[Migration], |
| 112 | 112 | ) -> None: |
| 113 | - to_revert = list(repo.with_dependants(redeploy)) | |
| 113 | + to_revert = list(project.with_dependants(redeploy)) | |
| 114 | 114 | _revert_with_feedback( |
| 115 | 115 | runner, |
| 116 | 116 | to_revert, |
| @@ -124,7 +124,7 @@ | ||
| 124 | 124 | for migration in covered_migrations |
| 125 | 125 | if runner.deployment_status(migration) == "pending" |
| 126 | 126 | } |
| 127 | - to_apply = list(repo.with_dependencies(pending | redeploy)) | |
| 127 | + to_apply = list(project.with_dependencies(pending | redeploy)) | |
| 128 | 128 | _deploy_with_feedback( |
| 129 | 129 | runner, |
| 130 | 130 | to_apply, |
| @@ -135,14 +135,14 @@ | ||
| 135 | 135 | |
| 136 | 136 | |
| 137 | 137 | def _process_watch_changes( |
| 138 | - repo: Repository, | |
| 138 | + project: Project, | |
| 139 | 139 | runner: Runner, |
| 140 | 140 | covered_migrations: set[Migration], |
| 141 | 141 | changes: Iterable[tuple[EventType, Path]], |
| 142 | 142 | allow_new_migrations: bool, |
| 143 | 143 | ) -> 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() | |
| 146 | 146 | |
| 147 | 147 | applied_and_modified = set() |
| 148 | 148 | added_and_pending = set() |
| @@ -150,18 +150,18 @@ | ||
| 150 | 150 | if action == EventType.MODIFIED and ( |
| 151 | 151 | path.name.endswith(".up.sql") or path.name.endswith(".config.toml") |
| 152 | 152 | ): |
| 153 | - migration = repo.by_path(path) | |
| 153 | + migration = project.by_path(path) | |
| 154 | 154 | if migration not in covered_migrations: |
| 155 | 155 | continue |
| 156 | 156 | if runner.deployment_status(migration) in ("modified", "applied"): |
| 157 | 157 | applied_and_modified.add(migration) |
| 158 | 158 | |
| 159 | 159 | 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) | |
| 161 | 161 | if runner.deployment_status(migration) == "pending": |
| 162 | 162 | added_and_pending.add(migration) |
| 163 | 163 | |
| 164 | - to_revert = list(repo.with_dependants(applied_and_modified)) | |
| 164 | + to_revert = list(project.with_dependants(applied_and_modified)) | |
| 165 | 165 | _revert_with_feedback( |
| 166 | 166 | runner, |
| 167 | 167 | to_revert, |
| @@ -170,7 +170,7 @@ | ||
| 170 | 170 | ), |
| 171 | 171 | ) |
| 172 | 172 | |
| 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)) | |
| 174 | 174 | _deploy_with_feedback( |
| 175 | 175 | runner, |
| 176 | 176 | to_apply, |
| @@ -188,26 +188,26 @@ | ||
| 188 | 188 | watch: bool, |
| 189 | 189 | allow_new_migrations: bool, |
| 190 | 190 | ) -> 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)) | |
| 193 | 193 | if_modified = _resolve_if_modified_policy(if_modified, watch) |
| 194 | 194 | |
| 195 | 195 | with connection_for(database_url) as connection: |
| 196 | 196 | runner = Runner(connection) |
| 197 | 197 | 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) | |
| 199 | 199 | |
| 200 | 200 | if not watch: |
| 201 | 201 | return |
| 202 | 202 | |
| 203 | - incoming_changes = repo.watch_for_changes() | |
| 203 | + incoming_changes = project.watch_for_changes() | |
| 204 | 204 | while True: |
| 205 | 205 | try: |
| 206 | 206 | changes = next(incoming_changes) |
| 207 | 207 | except StopIteration: |
| 208 | 208 | break |
| 209 | 209 | _process_watch_changes( |
| 210 | - repo, | |
| 210 | + project, | |
| 211 | 211 | runner, |
| 212 | 212 | covered_migrations, |
| 213 | 213 | changes, |
| @@ -218,7 +218,7 @@ | ||
| 218 | 218 | @app.command(name="add") |
| 219 | 219 | def add( |
| 220 | 220 | 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)], | |
| 222 | 222 | database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database connection URL.")] = None, |
| 223 | 223 | if_modified: Annotated[ |
| 224 | 224 | IfModifiedOption | None, |
| @@ -233,10 +233,10 @@ | ||
| 233 | 233 | ] = None, |
| 234 | 234 | watch: Annotated[ |
| 235 | 235 | 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."), | |
| 237 | 237 | ] = False, |
| 238 | 238 | ) -> None: |
| 239 | - """Apply the specified migrations in the repository.""" | |
| 239 | + """Apply the specified migrations in the project.""" | |
| 240 | 240 | run_deploy(migration_ids, root, database_url, if_modified, watch, allow_new_migrations=False) |
| 241 | 241 | |
| 242 | 242 | |
| @@ -246,13 +246,13 @@ | ||
| 246 | 246 | if_modified: IfModifiedOption | None = None, |
| 247 | 247 | watch: bool = False, |
| 248 | 248 | ) -> 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) | |
| 251 | 251 | |
| 252 | 252 | |
| 253 | 253 | @app.command() |
| 254 | 254 | 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)], | |
| 256 | 256 | database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database connection URL.")] = None, |
| 257 | 257 | if_modified: Annotated[ |
| 258 | 258 | IfModifiedOption | None, |
| @@ -267,8 +267,8 @@ | ||
| 267 | 267 | ] = None, |
| 268 | 268 | watch: Annotated[ |
| 269 | 269 | 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."), | |
| 271 | 271 | ] = False, |
| 272 | 272 | ) -> None: |
| 273 | - """Apply all pending migrations in the repository.""" | |
| 273 | + """Apply all pending migrations in the project.""" | |
| 274 | 274 | run_up(root, database_url, if_modified, watch) |
modified src/mitch/cli/log.py +7 −7
| @@ -8,10 +8,10 @@ | ||
| 8 | 8 | |
| 9 | 9 | from ..errors import MissingMigrationError |
| 10 | 10 | from ..helpers import connection_for |
| 11 | -from ..repository import Repository | |
| 11 | +from ..project import Project | |
| 12 | 12 | from ..runner import Runner |
| 13 | 13 | |
| 14 | -app = typer.Typer(help="Show applied migrations in the repository.") | |
| 14 | +app = typer.Typer(help="Show applied migrations in the project.") | |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | def _format_applied_at(value: object) -> str: |
| @@ -37,9 +37,9 @@ | ||
| 37 | 37 | root: Annotated[ |
| 38 | 38 | Path, |
| 39 | 39 | typer.Option( |
| 40 | - "--repository", | |
| 41 | - "-r", | |
| 42 | - help="Repository directory.", | |
| 40 | + "--project", | |
| 41 | + "-p", | |
| 42 | + help="Project directory.", | |
| 43 | 43 | default_factory=lambda: Path.cwd(), |
| 44 | 44 | dir_okay=True, |
| 45 | 45 | file_okay=False, |
| @@ -56,7 +56,7 @@ | ||
| 56 | 56 | ] = None, |
| 57 | 57 | ) -> None: |
| 58 | 58 | """Print all currently applied migrations with deployment time and on-disk status.""" |
| 59 | - repo = Repository(root) | |
| 59 | + project = Project(root) | |
| 60 | 60 | |
| 61 | 61 | with connection_for(database_url) as connection: |
| 62 | 62 | runner = Runner(connection) |
| @@ -79,7 +79,7 @@ | ||
| 79 | 79 | for row in rows: |
| 80 | 80 | migration_id = row.id |
| 81 | 81 | try: |
| 82 | - migration = repo.by_id(migration_id) | |
| 82 | + migration = project.by_id(migration_id) | |
| 83 | 83 | except MissingMigrationError: |
| 84 | 84 | status = "missing" |
| 85 | 85 | else: |
modified src/mitch/cli/revert.py +12 −12
| @@ -5,38 +5,38 @@ | ||
| 5 | 5 | import typer |
| 6 | 6 | |
| 7 | 7 | from ..helpers import connection_for |
| 8 | -from ..repository import Repository | |
| 8 | +from ..project import Project | |
| 9 | 9 | from ..runner import Runner |
| 10 | 10 | |
| 11 | -app = typer.Typer(help="Revert migrations in the repository.") | |
| 11 | +app = typer.Typer(help="Revert migrations in the project.") | |
| 12 | 12 | |
| 13 | 13 | |
| 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.") | |
| 15 | 15 | 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)], | |
| 17 | 17 | 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, |
| 18 | 18 | ) -> 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) | |
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | @app.command( |
| 25 | 25 | 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.", | |
| 27 | 27 | ) |
| 28 | 28 | def drop( |
| 29 | 29 | 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)], | |
| 31 | 31 | 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, |
| 32 | 32 | ) -> 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) | |
| 35 | 35 | with connection_for(database_url) as connection: |
| 36 | 36 | runner = Runner(connection) |
| 37 | 37 | applied_migrations = list( |
| 38 | 38 | migration |
| 39 | - for migration in repo.by_ids_with_dependants(migration_ids) | |
| 39 | + for migration in project.by_ids_with_dependants(migration_ids) | |
| 40 | 40 | if runner.deployment_status(migration) in ("applied", "modified") |
| 41 | 41 | ) |
| 42 | 42 | runner.revert_migrations( |
modified src/mitch/cli/stash.py +21 −21
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | from ..errors import MissingMigrationError |
| 8 | 8 | from ..helpers import connection_for |
| 9 | 9 | from ..migration import Migration |
| 10 | -from ..repository import Repository | |
| 10 | +from ..project import Project | |
| 11 | 11 | from ..runner import Runner |
| 12 | 12 | from ..vcs import Add, Copied, Modified, Renamed, VersionControlManagerProtocol |
| 13 | 13 | |
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | def _collect_dirty_reconcile_candidates( |
| 18 | - repo_with_local_changes: Repository, | |
| 18 | + project_with_local_changes: Project, | |
| 19 | 19 | vcs_manager: VersionControlManagerProtocol, |
| 20 | 20 | ) -> set[Migration]: |
| 21 | 21 | # Identify local migration edits that must be reconciled to current commit before stashing. |
| @@ -24,21 +24,21 @@ | ||
| 24 | 24 | for entry in vcs_manager.local_changes(): |
| 25 | 25 | match entry: |
| 26 | 26 | 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)) | |
| 28 | 28 | case Add(path) if path.suffix in (".sql", ".toml"): |
| 29 | 29 | try: |
| 30 | - dirty_candidates.add(repo_with_local_changes.by_path(path)) | |
| 30 | + dirty_candidates.add(project_with_local_changes.by_path(path)) | |
| 31 | 31 | except MissingMigrationError: |
| 32 | 32 | # Explicitly silenced: a lone local config file without an up script cannot be reconciled. |
| 33 | 33 | pass |
| 34 | 34 | case Copied(_, new_path) if new_path.suffix in (".sql", ".toml"): |
| 35 | 35 | 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)) | |
| 37 | 37 | except MissingMigrationError: |
| 38 | 38 | # Explicitly silenced: copied config without a resolvable migration is ignored. |
| 39 | 39 | pass |
| 40 | 40 | 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)) | |
| 42 | 42 | case _: |
| 43 | 43 | continue |
| 44 | 44 | |
| @@ -46,17 +46,17 @@ | ||
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | def revert_dirty_migrations( |
| 49 | - repo_with_local_changes: Repository, | |
| 49 | + project_with_local_changes: Project, | |
| 50 | 50 | vcs_manager: VersionControlManagerProtocol, |
| 51 | 51 | database_url: str | None, |
| 52 | 52 | ) -> 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) | |
| 54 | 54 | |
| 55 | 55 | with connection_for(database_url) as connection: |
| 56 | 56 | runner = Runner(connection) |
| 57 | 57 | return set( |
| 58 | 58 | runner.revert_migrations( |
| 59 | - repo_with_local_changes.with_dependants(dirty_candidates), | |
| 59 | + project_with_local_changes.with_dependants(dirty_candidates), | |
| 60 | 60 | before_each=lambda migration, status: rich.print( |
| 61 | 61 | f"[blue]Reverting:[/blue] Migration '{migration.id}' ({status})" |
| 62 | 62 | ), |
| @@ -65,14 +65,14 @@ | ||
| 65 | 65 | |
| 66 | 66 | |
| 67 | 67 | def reapply_reverted_migrations( |
| 68 | - repo_with_committed_files: Repository, | |
| 68 | + project_with_committed_files: Project, | |
| 69 | 69 | reverted_migrations: set[Migration], |
| 70 | 70 | database_url: str | None, |
| 71 | 71 | ) -> set[Migration]: |
| 72 | 72 | reapply_candidates: set[Migration] = set() |
| 73 | 73 | for migration in reverted_migrations: |
| 74 | 74 | 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)) | |
| 76 | 76 | except MissingMigrationError: |
| 77 | 77 | # Local-only migrations are intentionally not re-applied in committed state. |
| 78 | 78 | continue |
| @@ -81,7 +81,7 @@ | ||
| 81 | 81 | runner = Runner(connection) |
| 82 | 82 | return set( |
| 83 | 83 | runner.deploy_migrations( |
| 84 | - repo_with_committed_files.with_dependencies(reapply_candidates), | |
| 84 | + project_with_committed_files.with_dependencies(reapply_candidates), | |
| 85 | 85 | before_each=lambda migration, status: rich.print( |
| 86 | 86 | f"[green]Deploying:[/green] Migration '{migration.id}' ({status})" |
| 87 | 87 | ), |
| @@ -94,9 +94,9 @@ | ||
| 94 | 94 | root: Annotated[ |
| 95 | 95 | Path, |
| 96 | 96 | typer.Option( |
| 97 | - "--repository", | |
| 98 | - "-r", | |
| 99 | - help="Repository directory.", | |
| 97 | + "--project", | |
| 98 | + "-p", | |
| 99 | + help="Project directory.", | |
| 100 | 100 | default_factory=lambda: Path.cwd(), |
| 101 | 101 | dir_okay=True, |
| 102 | 102 | file_okay=False, |
| @@ -115,18 +115,18 @@ | ||
| 115 | 115 | Literal["git", "hg"] | None, |
| 116 | 116 | typer.Option( |
| 117 | 117 | "--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.", | |
| 119 | 119 | ), |
| 120 | 120 | ] = None, |
| 121 | 121 | ) -> 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) | |
| 124 | 124 | |
| 125 | 125 | if not vcs_manager.is_dirty(): |
| 126 | 126 | rich.print("[yellow]No local changes to stash.[/yellow]") |
| 127 | 127 | return |
| 128 | 128 | |
| 129 | - reverted = revert_dirty_migrations(repo, vcs_manager, database_url) | |
| 129 | + reverted = revert_dirty_migrations(project, vcs_manager, database_url) | |
| 130 | 130 | 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 @@ | ||
| 8 | 8 | |
| 9 | 9 | from ..errors import MissingMigrationError |
| 10 | 10 | from ..helpers import connection_for |
| 11 | -from ..repository import Repository | |
| 11 | +from ..project import Project | |
| 12 | 12 | from ..runner import Runner |
| 13 | 13 | |
| 14 | 14 | app = typer.Typer(help="Show migration integrity and availability status.") |
| @@ -21,7 +21,7 @@ | ||
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | def collect_integrity_report( |
| 24 | - repo: Repository, | |
| 24 | + project: Project, | |
| 25 | 25 | runner: Runner, |
| 26 | 26 | selected_ids: set[str] | None = None, |
| 27 | 27 | ) -> IntegrityReport: |
| @@ -34,20 +34,20 @@ | ||
| 34 | 34 | |
| 35 | 35 | # Identify missings |
| 36 | 36 | # 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] | |
| 38 | 38 | |
| 39 | - # Identify modified and available migrations among those present in the repository. | |
| 39 | + # Identify modified and available migrations among those present in the project. | |
| 40 | 40 | modified: list[str] = [] |
| 41 | 41 | available: list[str] = [] |
| 42 | 42 | |
| 43 | 43 | # 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. | |
| 46 | 46 | # 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. | |
| 49 | 49 | # 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)): | |
| 51 | 51 | continue |
| 52 | 52 | |
| 53 | 53 | match runner.deployment_status(migration): |
| @@ -93,9 +93,9 @@ | ||
| 93 | 93 | root: Annotated[ |
| 94 | 94 | Path, |
| 95 | 95 | typer.Option( |
| 96 | - "--repository", | |
| 97 | - "-r", | |
| 98 | - help="Repository directory.", | |
| 96 | + "--project", | |
| 97 | + "-p", | |
| 98 | + help="Project directory.", | |
| 99 | 99 | default_factory=lambda: Path.cwd(), |
| 100 | 100 | dir_okay=True, |
| 101 | 101 | file_okay=False, |
| @@ -132,11 +132,11 @@ | ||
| 132 | 132 | ] = None, |
| 133 | 133 | ) -> None: |
| 134 | 134 | try: |
| 135 | - repo = Repository(root) | |
| 135 | + project = Project(root) | |
| 136 | 136 | selected_ids = set(migration_ids) if migration_ids is not None else None |
| 137 | 137 | with connection_for(database_url) as connection: |
| 138 | 138 | runner = Runner(connection) |
| 139 | - report = collect_integrity_report(repo, runner, selected_ids) | |
| 139 | + report = collect_integrity_report(project, runner, selected_ids) | |
| 140 | 140 | except MissingMigrationError: |
| 141 | 141 | raise |
| 142 | 142 | except typer.Exit: |
modified src/mitch/errors.py +1 −1
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | 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.""" | |
| 8 | 8 | def __init__(self, duplicates: dict[str, list[Migration]]): |
| 9 | 9 | self.duplicates = duplicates |
| 10 | 10 | message = self._build_message() |
renamed src/mitch/repository.py → src/mitch/project.py +4 −4
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | from .vcs import GitManager, MercurialManager, VersionControlManagerProtocol |
| 14 | 14 | |
| 15 | 15 | |
| 16 | -class Repository: | |
| 16 | +class Project: | |
| 17 | 17 | def __init__(self, root_folder: Path | str = Path.cwd()) -> None: |
| 18 | 18 | self.path = Path(root_folder).resolve() |
| 19 | 19 | self._load_migrations() |
| @@ -222,19 +222,19 @@ | ||
| 222 | 222 | |
| 223 | 223 | if vcs == "git": |
| 224 | 224 | 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.", | |
| 226 | 226 | err=True, |
| 227 | 227 | ) |
| 228 | 228 | raise typer.Exit(1) |
| 229 | 229 | if vcs == "hg": |
| 230 | 230 | 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.", | |
| 232 | 232 | err=True, |
| 233 | 233 | ) |
| 234 | 234 | raise typer.Exit(1) |
| 235 | 235 | |
| 236 | 236 | 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).", | |
| 238 | 238 | err=True, |
| 239 | 239 | ) |
| 240 | 240 | raise typer.Exit(1) |
modified src/mitch/watcher.py +6 −6
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | from watchdog.events import PatternMatchingEventHandler |
| 10 | 10 | from watchdog.observers import Observer |
| 11 | 11 | |
| 12 | -from .repository import Repository | |
| 12 | +from .project import Project | |
| 13 | 13 | |
| 14 | 14 | if TYPE_CHECKING: |
| 15 | 15 | class QueueProtocol[T](Protocol): |
| @@ -124,10 +124,10 @@ | ||
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | 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: | |
| 128 | 128 | super().__init__(patterns=["*.up.sql", "*.down.sql", "*.config.toml"], ignore_directories=True) |
| 129 | 129 | self._queue: DebouncedQueue[Event] = DebouncedQueue(debounce_time=debounce) |
| 130 | - self._repo = repo | |
| 130 | + self._project = project | |
| 131 | 131 | self._reload_requested = False |
| 132 | 132 | |
| 133 | 133 | @staticmethod |
| @@ -165,10 +165,10 @@ | ||
| 165 | 165 | self._queue.task_done() |
| 166 | 166 | |
| 167 | 167 | |
| 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) | |
| 170 | 170 | observer = Observer() |
| 171 | - observer.schedule(handler, str(repo.path), recursive=True) | |
| 171 | + observer.schedule(handler, str(project.path), recursive=True) | |
| 172 | 172 | observer.start() |
| 173 | 173 | try: |
| 174 | 174 | 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 @@ | ||
| 61 | 61 | app, |
| 62 | 62 | [ |
| 63 | 63 | "up", |
| 64 | - "--repository", | |
| 64 | + "--project", | |
| 65 | 65 | str(repo_path), |
| 66 | 66 | "--database", |
| 67 | 67 | database_url, |
| @@ -81,7 +81,7 @@ | ||
| 81 | 81 | [ |
| 82 | 82 | "checkout", |
| 83 | 83 | "target", |
| 84 | - "--repository", | |
| 84 | + "--project", | |
| 85 | 85 | str(repo_path), |
| 86 | 86 | "--database", |
| 87 | 87 | database_url, |
modified tests/test_cli.py +68 −68
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | from typer.testing import CliRunner |
| 7 | 7 | |
| 8 | 8 | from mitch.cli import app |
| 9 | -from mitch.repository import Repository | |
| 9 | +from mitch.project import Project | |
| 10 | 10 | from mitch.watcher import EventType |
| 11 | 11 | |
| 12 | 12 | runner = CliRunner() |
| @@ -53,7 +53,7 @@ | ||
| 53 | 53 | result = runner.invoke(app, ["add", "--help"]) |
| 54 | 54 | |
| 55 | 55 | 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 | |
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | def test_up_help_includes_watch_options(): |
| @@ -68,10 +68,10 @@ | ||
| 68 | 68 | drop_help = runner.invoke(app, ["drop", "--help"]) |
| 69 | 69 | |
| 70 | 70 | 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 | |
| 72 | 72 | |
| 73 | 73 | 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 | |
| 75 | 75 | |
| 76 | 76 | |
| 77 | 77 | def test_stash_help_mentions_stashing_behavior(): |
| @@ -98,7 +98,7 @@ | ||
| 98 | 98 | [ |
| 99 | 99 | "add", |
| 100 | 100 | "001-init", |
| 101 | - "--repository", | |
| 101 | + "--project", | |
| 102 | 102 | "tests/migrations", |
| 103 | 103 | "--database", |
| 104 | 104 | database_url, |
| @@ -125,7 +125,7 @@ | ||
| 125 | 125 | [ |
| 126 | 126 | "create", |
| 127 | 127 | "001-init", |
| 128 | - "--repository", | |
| 128 | + "--project", | |
| 129 | 129 | str(tmp_path), |
| 130 | 130 | ], |
| 131 | 131 | ) |
| @@ -152,7 +152,7 @@ | ||
| 152 | 152 | [ |
| 153 | 153 | "create", |
| 154 | 154 | "001-init", |
| 155 | - "--repository", | |
| 155 | + "--project", | |
| 156 | 156 | str(tmp_path), |
| 157 | 157 | "--dependency", |
| 158 | 158 | "missing-migration", |
| @@ -169,7 +169,7 @@ | ||
| 169 | 169 | [ |
| 170 | 170 | "create", |
| 171 | 171 | "001-init", |
| 172 | - "--repository", | |
| 172 | + "--project", | |
| 173 | 173 | str(tmp_path), |
| 174 | 174 | "--skip-config", |
| 175 | 175 | "--skip-downscript", |
| @@ -200,14 +200,14 @@ | ||
| 200 | 200 | ) |
| 201 | 201 | yield [(EventType.CREATED, repo_path / "002-add.up.sql")] |
| 202 | 202 | |
| 203 | - monkeypatch.setattr(Repository, "watch_for_changes", fake_watch_for_changes) | |
| 203 | + monkeypatch.setattr(Project, "watch_for_changes", fake_watch_for_changes) | |
| 204 | 204 | |
| 205 | 205 | result = runner.invoke( |
| 206 | 206 | app, |
| 207 | 207 | [ |
| 208 | 208 | "up", |
| 209 | 209 | "--watch", |
| 210 | - "--repository", | |
| 210 | + "--project", | |
| 211 | 211 | str(repo_path), |
| 212 | 212 | "--database", |
| 213 | 213 | database_url, |
| @@ -234,7 +234,7 @@ | ||
| 234 | 234 | app, |
| 235 | 235 | [ |
| 236 | 236 | "up", |
| 237 | - "--repository", | |
| 237 | + "--project", | |
| 238 | 238 | "tests/migrations", |
| 239 | 239 | "--database", |
| 240 | 240 | database_url, |
| @@ -287,7 +287,7 @@ | ||
| 287 | 287 | app, |
| 288 | 288 | [ |
| 289 | 289 | "up", |
| 290 | - "--repository", | |
| 290 | + "--project", | |
| 291 | 291 | str(repo_path), |
| 292 | 292 | "--database", |
| 293 | 293 | database_url, |
| @@ -302,7 +302,7 @@ | ||
| 302 | 302 | [ |
| 303 | 303 | "drop", |
| 304 | 304 | "002-next", |
| 305 | - "--repository", | |
| 305 | + "--project", | |
| 306 | 306 | str(repo_path), |
| 307 | 307 | "--database", |
| 308 | 308 | database_url, |
| @@ -334,7 +334,7 @@ | ||
| 334 | 334 | app, |
| 335 | 335 | [ |
| 336 | 336 | "up", |
| 337 | - "--repository", | |
| 337 | + "--project", | |
| 338 | 338 | "tests/migrations", |
| 339 | 339 | "--database", |
| 340 | 340 | database_url, |
| @@ -348,7 +348,7 @@ | ||
| 348 | 348 | app, |
| 349 | 349 | [ |
| 350 | 350 | "log", |
| 351 | - "--repository", | |
| 351 | + "--project", | |
| 352 | 352 | "tests/migrations", |
| 353 | 353 | "--database", |
| 354 | 354 | database_url, |
| @@ -380,7 +380,7 @@ | ||
| 380 | 380 | app, |
| 381 | 381 | [ |
| 382 | 382 | "up", |
| 383 | - "--repository", | |
| 383 | + "--project", | |
| 384 | 384 | str(repo_path), |
| 385 | 385 | "--database", |
| 386 | 386 | database_url, |
| @@ -399,7 +399,7 @@ | ||
| 399 | 399 | app, |
| 400 | 400 | [ |
| 401 | 401 | "log", |
| 402 | - "--repository", | |
| 402 | + "--project", | |
| 403 | 403 | str(repo_path), |
| 404 | 404 | "--database", |
| 405 | 405 | database_url, |
| @@ -437,7 +437,7 @@ | ||
| 437 | 437 | app, |
| 438 | 438 | [ |
| 439 | 439 | "up", |
| 440 | - "--repository", | |
| 440 | + "--project", | |
| 441 | 441 | str(repo_path), |
| 442 | 442 | "--database", |
| 443 | 443 | database_url, |
| @@ -453,7 +453,7 @@ | ||
| 453 | 453 | app, |
| 454 | 454 | [ |
| 455 | 455 | "stash", |
| 456 | - "--repository", | |
| 456 | + "--project", | |
| 457 | 457 | str(repo_path), |
| 458 | 458 | "--database", |
| 459 | 459 | database_url, |
| @@ -491,7 +491,7 @@ | ||
| 491 | 491 | app, |
| 492 | 492 | [ |
| 493 | 493 | "stash", |
| 494 | - "--repository", | |
| 494 | + "--project", | |
| 495 | 495 | str(repo_path), |
| 496 | 496 | "--database", |
| 497 | 497 | database_url, |
| @@ -515,7 +515,7 @@ | ||
| 515 | 515 | app, |
| 516 | 516 | [ |
| 517 | 517 | "up", |
| 518 | - "--repository", | |
| 518 | + "--project", | |
| 519 | 519 | str(repo_path), |
| 520 | 520 | "--database", |
| 521 | 521 | database_url, |
| @@ -539,7 +539,7 @@ | ||
| 539 | 539 | app, |
| 540 | 540 | [ |
| 541 | 541 | "status", |
| 542 | - "--repository", | |
| 542 | + "--project", | |
| 543 | 543 | str(repo_path), |
| 544 | 544 | "--database", |
| 545 | 545 | database_url, |
| @@ -564,7 +564,7 @@ | ||
| 564 | 564 | app, |
| 565 | 565 | [ |
| 566 | 566 | "up", |
| 567 | - "--repository", | |
| 567 | + "--project", | |
| 568 | 568 | str(repo_path), |
| 569 | 569 | "--database", |
| 570 | 570 | database_url, |
| @@ -590,7 +590,7 @@ | ||
| 590 | 590 | "status", |
| 591 | 591 | "002-next", |
| 592 | 592 | "003-pending", |
| 593 | - "--repository", | |
| 593 | + "--project", | |
| 594 | 594 | str(repo_path), |
| 595 | 595 | "--database", |
| 596 | 596 | database_url, |
| @@ -615,7 +615,7 @@ | ||
| 615 | 615 | app, |
| 616 | 616 | [ |
| 617 | 617 | "up", |
| 618 | - "--repository", | |
| 618 | + "--project", | |
| 619 | 619 | str(repo_path), |
| 620 | 620 | "--database", |
| 621 | 621 | database_url, |
| @@ -632,7 +632,7 @@ | ||
| 632 | 632 | [ |
| 633 | 633 | "status", |
| 634 | 634 | "--ci", |
| 635 | - "--repository", | |
| 635 | + "--project", | |
| 636 | 636 | str(repo_path), |
| 637 | 637 | "--database", |
| 638 | 638 | database_url, |
| @@ -655,7 +655,7 @@ | ||
| 655 | 655 | app, |
| 656 | 656 | [ |
| 657 | 657 | "up", |
| 658 | - "--repository", | |
| 658 | + "--project", | |
| 659 | 659 | str(repo_path), |
| 660 | 660 | "--database", |
| 661 | 661 | database_url, |
| @@ -676,7 +676,7 @@ | ||
| 676 | 676 | "status", |
| 677 | 677 | "--ci", |
| 678 | 678 | "--strict", |
| 679 | - "--repository", | |
| 679 | + "--project", | |
| 680 | 680 | str(repo_path), |
| 681 | 681 | "--database", |
| 682 | 682 | database_url, |
| @@ -699,7 +699,7 @@ | ||
| 699 | 699 | app, |
| 700 | 700 | [ |
| 701 | 701 | "up", |
| 702 | - "--repository", | |
| 702 | + "--project", | |
| 703 | 703 | str(repo_path), |
| 704 | 704 | "--database", |
| 705 | 705 | database_url, |
| @@ -721,7 +721,7 @@ | ||
| 721 | 721 | "status", |
| 722 | 722 | "--ci", |
| 723 | 723 | "--strict", |
| 724 | - "--repository", | |
| 724 | + "--project", | |
| 725 | 725 | str(repo_path), |
| 726 | 726 | "--database", |
| 727 | 727 | database_url, |
| @@ -745,7 +745,7 @@ | ||
| 745 | 745 | app, |
| 746 | 746 | [ |
| 747 | 747 | "up", |
| 748 | - "--repository", | |
| 748 | + "--project", | |
| 749 | 749 | str(repo_path), |
| 750 | 750 | "--database", |
| 751 | 751 | database_url, |
| @@ -762,7 +762,7 @@ | ||
| 762 | 762 | app, |
| 763 | 763 | [ |
| 764 | 764 | "status", |
| 765 | - "--repository", | |
| 765 | + "--project", | |
| 766 | 766 | str(repo_path), |
| 767 | 767 | "--database", |
| 768 | 768 | database_url, |
| @@ -784,7 +784,7 @@ | ||
| 784 | 784 | app, |
| 785 | 785 | [ |
| 786 | 786 | "up", |
| 787 | - "--repository", | |
| 787 | + "--project", | |
| 788 | 788 | str(repo_path), |
| 789 | 789 | "--database", |
| 790 | 790 | database_url, |
| @@ -802,7 +802,7 @@ | ||
| 802 | 802 | [ |
| 803 | 803 | "status", |
| 804 | 804 | "--no-ci", |
| 805 | - "--repository", | |
| 805 | + "--project", | |
| 806 | 806 | str(repo_path), |
| 807 | 807 | "--database", |
| 808 | 808 | database_url, |
| @@ -837,7 +837,7 @@ | ||
| 837 | 837 | app, |
| 838 | 838 | [ |
| 839 | 839 | "up", |
| 840 | - "--repository", | |
| 840 | + "--project", | |
| 841 | 841 | str(repo_path), |
| 842 | 842 | "--database", |
| 843 | 843 | database_url, |
| @@ -857,7 +857,7 @@ | ||
| 857 | 857 | [ |
| 858 | 858 | "checkout", |
| 859 | 859 | "target", |
| 860 | - "--repository", | |
| 860 | + "--project", | |
| 861 | 861 | str(repo_path), |
| 862 | 862 | "--database", |
| 863 | 863 | database_url, |
| @@ -878,7 +878,7 @@ | ||
| 878 | 878 | assert table is None |
| 879 | 879 | |
| 880 | 880 | |
| 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): | |
| 882 | 882 | repo_path = tmp_path / "repo" |
| 883 | 883 | repo_path.mkdir() |
| 884 | 884 | _init_git_repo(repo_path) |
| @@ -904,7 +904,7 @@ | ||
| 904 | 904 | app, |
| 905 | 905 | [ |
| 906 | 906 | "up", |
| 907 | - "--repository", | |
| 907 | + "--project", | |
| 908 | 908 | str(migrations_path), |
| 909 | 909 | "--database", |
| 910 | 910 | database_url, |
| @@ -924,7 +924,7 @@ | ||
| 924 | 924 | [ |
| 925 | 925 | "checkout", |
| 926 | 926 | "target", |
| 927 | - "--repository", | |
| 927 | + "--project", | |
| 928 | 928 | str(migrations_path), |
| 929 | 929 | "--database", |
| 930 | 930 | database_url, |
| @@ -965,7 +965,7 @@ | ||
| 965 | 965 | app, |
| 966 | 966 | [ |
| 967 | 967 | "up", |
| 968 | - "--repository", | |
| 968 | + "--project", | |
| 969 | 969 | str(repo_path), |
| 970 | 970 | "--database", |
| 971 | 971 | database_url, |
| @@ -994,7 +994,7 @@ | ||
| 994 | 994 | [ |
| 995 | 995 | "checkout", |
| 996 | 996 | "target", |
| 997 | - "--repository", | |
| 997 | + "--project", | |
| 998 | 998 | str(repo_path), |
| 999 | 999 | "--database", |
| 1000 | 1000 | database_url, |
| @@ -1041,7 +1041,7 @@ | ||
| 1041 | 1041 | app, |
| 1042 | 1042 | [ |
| 1043 | 1043 | "up", |
| 1044 | - "--repository", | |
| 1044 | + "--project", | |
| 1045 | 1045 | str(repo_path), |
| 1046 | 1046 | "--database", |
| 1047 | 1047 | database_url, |
| @@ -1062,7 +1062,7 @@ | ||
| 1062 | 1062 | [ |
| 1063 | 1063 | "checkout", |
| 1064 | 1064 | "target", |
| 1065 | - "--repository", | |
| 1065 | + "--project", | |
| 1066 | 1066 | str(repo_path), |
| 1067 | 1067 | "--database", |
| 1068 | 1068 | database_url, |
| @@ -1103,7 +1103,7 @@ | ||
| 1103 | 1103 | app, |
| 1104 | 1104 | [ |
| 1105 | 1105 | "up", |
| 1106 | - "--repository", | |
| 1106 | + "--project", | |
| 1107 | 1107 | str(repo_path), |
| 1108 | 1108 | "--database", |
| 1109 | 1109 | database_url, |
| @@ -1126,7 +1126,7 @@ | ||
| 1126 | 1126 | [ |
| 1127 | 1127 | "checkout", |
| 1128 | 1128 | "target", |
| 1129 | - "--repository", | |
| 1129 | + "--project", | |
| 1130 | 1130 | str(repo_path), |
| 1131 | 1131 | "--database", |
| 1132 | 1132 | database_url, |
| @@ -1174,7 +1174,7 @@ | ||
| 1174 | 1174 | app, |
| 1175 | 1175 | [ |
| 1176 | 1176 | "up", |
| 1177 | - "--repository", | |
| 1177 | + "--project", | |
| 1178 | 1178 | str(repo_path), |
| 1179 | 1179 | "--database", |
| 1180 | 1180 | database_url, |
| @@ -1204,7 +1204,7 @@ | ||
| 1204 | 1204 | [ |
| 1205 | 1205 | "checkout", |
| 1206 | 1206 | "target", |
| 1207 | - "--repository", | |
| 1207 | + "--project", | |
| 1208 | 1208 | str(repo_path), |
| 1209 | 1209 | "--database", |
| 1210 | 1210 | database_url, |
| @@ -1261,7 +1261,7 @@ | ||
| 1261 | 1261 | app, |
| 1262 | 1262 | [ |
| 1263 | 1263 | "up", |
| 1264 | - "--repository", | |
| 1264 | + "--project", | |
| 1265 | 1265 | str(repo_path), |
| 1266 | 1266 | "--database", |
| 1267 | 1267 | database_url, |
| @@ -1288,7 +1288,7 @@ | ||
| 1288 | 1288 | [ |
| 1289 | 1289 | "checkout", |
| 1290 | 1290 | "target", |
| 1291 | - "--repository", | |
| 1291 | + "--project", | |
| 1292 | 1292 | str(repo_path), |
| 1293 | 1293 | "--database", |
| 1294 | 1294 | database_url, |
| @@ -1345,7 +1345,7 @@ | ||
| 1345 | 1345 | app, |
| 1346 | 1346 | [ |
| 1347 | 1347 | "up", |
| 1348 | - "--repository", | |
| 1348 | + "--project", | |
| 1349 | 1349 | str(repo_path), |
| 1350 | 1350 | "--database", |
| 1351 | 1351 | database_url, |
| @@ -1366,7 +1366,7 @@ | ||
| 1366 | 1366 | [ |
| 1367 | 1367 | "checkout", |
| 1368 | 1368 | "target", |
| 1369 | - "--repository", | |
| 1369 | + "--project", | |
| 1370 | 1370 | str(repo_path), |
| 1371 | 1371 | "--database", |
| 1372 | 1372 | database_url, |
| @@ -1422,7 +1422,7 @@ | ||
| 1422 | 1422 | [ |
| 1423 | 1423 | "checkout", |
| 1424 | 1424 | "target", |
| 1425 | - "--repository", | |
| 1425 | + "--project", | |
| 1426 | 1426 | str(repo_path), |
| 1427 | 1427 | "--database", |
| 1428 | 1428 | database_url, |
| @@ -1468,7 +1468,7 @@ | ||
| 1468 | 1468 | app, |
| 1469 | 1469 | [ |
| 1470 | 1470 | "up", |
| 1471 | - "--repository", | |
| 1471 | + "--project", | |
| 1472 | 1472 | str(repo_path), |
| 1473 | 1473 | "--database", |
| 1474 | 1474 | database_url, |
| @@ -1496,7 +1496,7 @@ | ||
| 1496 | 1496 | [ |
| 1497 | 1497 | "checkout", |
| 1498 | 1498 | "target", |
| 1499 | - "--repository", | |
| 1499 | + "--project", | |
| 1500 | 1500 | str(repo_path), |
| 1501 | 1501 | "--database", |
| 1502 | 1502 | database_url, |
| @@ -1540,7 +1540,7 @@ | ||
| 1540 | 1540 | app, |
| 1541 | 1541 | [ |
| 1542 | 1542 | "up", |
| 1543 | - "--repository", | |
| 1543 | + "--project", | |
| 1544 | 1544 | str(repo_path), |
| 1545 | 1545 | "--database", |
| 1546 | 1546 | database_url, |
| @@ -1568,7 +1568,7 @@ | ||
| 1568 | 1568 | [ |
| 1569 | 1569 | "checkout", |
| 1570 | 1570 | "target", |
| 1571 | - "--repository", | |
| 1571 | + "--project", | |
| 1572 | 1572 | str(repo_path), |
| 1573 | 1573 | "--database", |
| 1574 | 1574 | database_url, |
| @@ -1625,7 +1625,7 @@ | ||
| 1625 | 1625 | app, |
| 1626 | 1626 | [ |
| 1627 | 1627 | "up", |
| 1628 | - "--repository", | |
| 1628 | + "--project", | |
| 1629 | 1629 | str(repo_path), |
| 1630 | 1630 | "--database", |
| 1631 | 1631 | database_url, |
| @@ -1649,7 +1649,7 @@ | ||
| 1649 | 1649 | [ |
| 1650 | 1650 | "checkout", |
| 1651 | 1651 | "target", |
| 1652 | - "--repository", | |
| 1652 | + "--project", | |
| 1653 | 1653 | str(repo_path), |
| 1654 | 1654 | "--database", |
| 1655 | 1655 | database_url, |
| @@ -1701,7 +1701,7 @@ | ||
| 1701 | 1701 | app, |
| 1702 | 1702 | [ |
| 1703 | 1703 | "up", |
| 1704 | - "--repository", | |
| 1704 | + "--project", | |
| 1705 | 1705 | str(repo_path), |
| 1706 | 1706 | "--database", |
| 1707 | 1707 | database_url, |
| @@ -1725,7 +1725,7 @@ | ||
| 1725 | 1725 | [ |
| 1726 | 1726 | "checkout", |
| 1727 | 1727 | "target", |
| 1728 | - "--repository", | |
| 1728 | + "--project", | |
| 1729 | 1729 | str(repo_path), |
| 1730 | 1730 | "--database", |
| 1731 | 1731 | database_url, |
| @@ -1766,7 +1766,7 @@ | ||
| 1766 | 1766 | app, |
| 1767 | 1767 | [ |
| 1768 | 1768 | "up", |
| 1769 | - "--repository", | |
| 1769 | + "--project", | |
| 1770 | 1770 | str(repo_path), |
| 1771 | 1771 | "--database", |
| 1772 | 1772 | database_url, |
| @@ -1790,7 +1790,7 @@ | ||
| 1790 | 1790 | [ |
| 1791 | 1791 | "checkout", |
| 1792 | 1792 | "target", |
| 1793 | - "--repository", | |
| 1793 | + "--project", | |
| 1794 | 1794 | str(repo_path), |
| 1795 | 1795 | "--database", |
| 1796 | 1796 | database_url, |
| @@ -1835,7 +1835,7 @@ | ||
| 1835 | 1835 | app, |
| 1836 | 1836 | [ |
| 1837 | 1837 | "up", |
| 1838 | - "--repository", | |
| 1838 | + "--project", | |
| 1839 | 1839 | str(repo_path), |
| 1840 | 1840 | "--database", |
| 1841 | 1841 | database_url, |
| @@ -1855,7 +1855,7 @@ | ||
| 1855 | 1855 | [ |
| 1856 | 1856 | "checkout", |
| 1857 | 1857 | "target", |
| 1858 | - "--repository", | |
| 1858 | + "--project", | |
| 1859 | 1859 | str(repo_path), |
| 1860 | 1860 | "--database", |
| 1861 | 1861 | database_url, |
| @@ -1904,7 +1904,7 @@ | ||
| 1904 | 1904 | app, |
| 1905 | 1905 | [ |
| 1906 | 1906 | "up", |
| 1907 | - "--repository", | |
| 1907 | + "--project", | |
| 1908 | 1908 | str(repo_path), |
| 1909 | 1909 | "--database", |
| 1910 | 1910 | database_url, |
| @@ -1930,7 +1930,7 @@ | ||
| 1930 | 1930 | [ |
| 1931 | 1931 | "checkout", |
| 1932 | 1932 | "target", |
| 1933 | - "--repository", | |
| 1933 | + "--project", | |
| 1934 | 1934 | str(repo_path), |
| 1935 | 1935 | "--database", |
| 1936 | 1936 | database_url, |
| @@ -1976,7 +1976,7 @@ | ||
| 1976 | 1976 | app, |
| 1977 | 1977 | [ |
| 1978 | 1978 | "up", |
| 1979 | - "--repository", | |
| 1979 | + "--project", | |
| 1980 | 1980 | str(repo_path), |
| 1981 | 1981 | "--database", |
| 1982 | 1982 | database_url, |
| @@ -2006,7 +2006,7 @@ | ||
| 2006 | 2006 | [ |
| 2007 | 2007 | "checkout", |
| 2008 | 2008 | "target", |
| 2009 | - "--repository", | |
| 2009 | + "--project", | |
| 2010 | 2010 | str(repo_path), |
| 2011 | 2011 | "--database", |
| 2012 | 2012 | database_url, |
modified tests/test_errors.py +4 −4
| @@ -3,12 +3,12 @@ | ||
| 3 | 3 | import pytest |
| 4 | 4 | |
| 5 | 5 | from mitch.errors import DuplicateMigrationIdError, MissingMigrationError |
| 6 | -from mitch.repository import Repository | |
| 6 | +from mitch.project import Project | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | def test_duplicate_migration_ids_raise(): |
| 10 | 10 | with pytest.raises(DuplicateMigrationIdError) as exc_info: |
| 11 | - Repository(Path("tests/repository-with-duplicate-ids")) | |
| 11 | + Project(Path("tests/project-with-duplicate-ids")) | |
| 12 | 12 | |
| 13 | 13 | duplicates = exc_info.value.duplicates |
| 14 | 14 | assert "same-id" in duplicates |
| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | def test_missing_migration_error_message(): |
| 19 | - repo = Repository("tests/migrations") | |
| 19 | + project = Project("tests/migrations") | |
| 20 | 20 | |
| 21 | 21 | with pytest.raises(MissingMigrationError) as exc_info: |
| 22 | - repo.by_id("missing-id") | |
| 22 | + project.by_id("missing-id") | |
| 23 | 23 | |
| 24 | 24 | assert "missing-id" in str(exc_info.value) |
renamed tests/test_repository.py → tests/test_project.py +18 −18
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | from typer import Exit |
| 5 | 5 | |
| 6 | 6 | from mitch.errors import MissingMigrationError |
| 7 | -from mitch.repository import Repository | |
| 7 | +from mitch.project import Project | |
| 8 | 8 | from mitch.vcs import GitManager |
| 9 | 9 | |
| 10 | 10 | |
| @@ -24,10 +24,10 @@ | ||
| 24 | 24 | _run_git(path, "init") |
| 25 | 25 | |
| 26 | 26 | |
| 27 | -def test_load_repository(): | |
| 28 | - repo = Repository("tests/migrations") | |
| 27 | +def test_load_project(): | |
| 28 | + project = Project("tests/migrations") | |
| 29 | 29 | |
| 30 | - migration = repo.by_id("001-init") | |
| 30 | + migration = project.by_id("001-init") | |
| 31 | 31 | assert migration is not None |
| 32 | 32 | |
| 33 | 33 | assert migration.id == "001-init" |
| @@ -39,16 +39,16 @@ | ||
| 39 | 39 | assert migration.dependencies == set() |
| 40 | 40 | |
| 41 | 41 | |
| 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"])) | |
| 45 | 45 | assert migrations[0].id == "001-init" |
| 46 | 46 | assert migrations[1].id == "002-add-column" |
| 47 | 47 | |
| 48 | 48 | |
| 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"])) | |
| 52 | 52 | assert migrations[0].id == "002-add-column" |
| 53 | 53 | assert migrations[1].id == "001-init" |
| 54 | 54 | |
| @@ -63,18 +63,18 @@ | ||
| 63 | 63 | (tmp_path / "004-new.up.sql").write_text("SELECT 1;", encoding="utf-8") |
| 64 | 64 | (tmp_path / "004-new.config.toml").write_text("created_at = 2020-01-02\n", encoding="utf-8") |
| 65 | 65 | |
| 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"])) | |
| 68 | 68 | |
| 69 | 69 | assert [m.id for m in migrations] == ["003-old", "004-new", "001-init", "002-second"] |
| 70 | 70 | |
| 71 | 71 | |
| 72 | 72 | def test_by_paths_raises_if_any_path_is_missing(): |
| 73 | - repo = Repository("tests/migrations") | |
| 73 | + project = Project("tests/migrations") | |
| 74 | 74 | |
| 75 | 75 | with pytest.raises(MissingMigrationError): |
| 76 | 76 | list( |
| 77 | - repo.by_paths( | |
| 77 | + project.by_paths( | |
| 78 | 78 | [ |
| 79 | 79 | "tests/migrations/001-init.up.sql", |
| 80 | 80 | "tests/migrations/does-not-exist.up.sql", |
| @@ -92,15 +92,15 @@ | ||
| 92 | 92 | migrations_path.mkdir() |
| 93 | 93 | (migrations_path / "001-init.up.sql").write_text("SELECT 1;", encoding="utf-8") |
| 94 | 94 | |
| 95 | - repo = Repository(migrations_path) | |
| 95 | + project = Project(migrations_path) | |
| 96 | 96 | |
| 97 | - manager = repo.get_migration_manager() | |
| 97 | + manager = project.get_migration_manager() | |
| 98 | 98 | |
| 99 | 99 | assert isinstance(manager, GitManager) |
| 100 | 100 | |
| 101 | 101 | |
| 102 | 102 | def test_get_migration_manager_raises_when_no_repository_metadata(tmp_path): |
| 103 | - repo = Repository(tmp_path) | |
| 103 | + project = Project(tmp_path) | |
| 104 | 104 | |
| 105 | 105 | 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 @@ | ||
| 9 | 9 | |
| 10 | 10 | from mitch.helpers import batch_transactional_migrations |
| 11 | 11 | from mitch.migration import Migration |
| 12 | -from mitch.repository import Repository | |
| 12 | +from mitch.project import Project | |
| 13 | 13 | from mitch.runner import Runner |
| 14 | 14 | |
| 15 | 15 | |
| 16 | 16 | @pytest.fixture |
| 17 | -def repo(): | |
| 18 | - yield Repository(Path("tests/migrations")) | |
| 17 | +def project(): | |
| 18 | + yield Project(Path("tests/migrations")) | |
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | @pytest.fixture |
| 22 | -def cloned_repo(tmp_path): | |
| 22 | +def cloned_project(tmp_path): | |
| 23 | 23 | source = Path("tests/migrations") |
| 24 | 24 | dest = tmp_path / "migrations" |
| 25 | 25 | shutil.copytree(source, dest) |
| 26 | - yield Repository(dest) | |
| 26 | + yield Project(dest) | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | @pytest.fixture |
| @@ -40,8 +40,8 @@ | ||
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | |
| 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"])) | |
| 45 | 45 | |
| 46 | 46 | # Check that the migrations are marked as applied |
| 47 | 47 | for migration in due_migrations: |
| @@ -129,11 +129,11 @@ | ||
| 129 | 129 | assert statements == [] |
| 130 | 130 | |
| 131 | 131 | |
| 132 | -def test_setup_project_copies_migrations_isolated(cloned_repo): | |
| 132 | +def test_setup_project_copies_migrations_isolated(cloned_project): | |
| 133 | 133 | original_sql = Path("tests/migrations/001-init.up.sql").read_text(encoding="utf-8") |
| 134 | 134 | |
| 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") | |
| 137 | 137 | modified_sql = original_sql + "\n-- mutated during test\n" |
| 138 | 138 | migration.up_script.write_text(modified_sql, encoding="utf-8") |
| 139 | 139 | assert migration.up_script.read_text(encoding="utf-8") == modified_sql |
| @@ -142,8 +142,8 @@ | ||
| 142 | 142 | assert unchanged_sql == original_sql |
| 143 | 143 | |
| 144 | 144 | |
| 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") | |
| 147 | 147 | runner.apply_migration(migration) |
| 148 | 148 | |
| 149 | 149 | modified_sql = ( |
| @@ -156,8 +156,8 @@ | ||
| 156 | 156 | runner.apply_migration(migration) |
| 157 | 157 | |
| 158 | 158 | |
| 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") | |
| 161 | 161 | runner.apply_migration(migration) |
| 162 | 162 | |
| 163 | 163 | original_sql = migration.up_script.read_text(encoding="utf-8") |
| @@ -219,8 +219,8 @@ | ||
| 219 | 219 | raise RuntimeError("boom") |
| 220 | 220 | |
| 221 | 221 | |
| 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") | |
| 224 | 224 | runner.apply_migration(migration) |
| 225 | 225 | |
| 226 | 226 | connection.execute( |