| @@ -158,21 +158,6 @@ |
| 158 | 158 | def restore_changes(self) -> None: |
| 159 | 159 | # Restore local changes after checkout and migration re-application. |
| 160 | 160 | self._run("stash", "pop", "--index") |
| 161 | | - |
| 162 | | - |
| 163 | | -def _migration_up_path(path: Path) -> Path | None: |
| 164 | | - if path.name.endswith(".up.sql"): |
| 165 | | - return path |
| 166 | | - if path.name.endswith(".config.toml"): |
| 167 | | - stem = path.name.removesuffix(".config.toml") |
| 168 | | - return path.with_name(f"{stem}.up.sql") |
| 169 | | - return None |
| 170 | | - |
| 171 | | - |
| 172 | | -def _resolve_repo_path(path: Path, repo_root: Path) -> Path: |
| 173 | | - if path.is_absolute(): |
| 174 | | - return path.resolve() |
| 175 | | - return (repo_root / path).resolve() |
| 176 | 161 | |
| 177 | 162 | |
| 178 | 163 | @contextmanager |
| @@ -257,41 +242,37 @@ |
| 257 | 242 | for entry in git_manager.changes(branch): |
| 258 | 243 | match entry: |
| 259 | 244 | case Deleted(path) if path.suffix == '.sql': |
| 260 | | - up_deleted.add(repo.by_path(_resolve_repo_path(path, repo_root))) |
| 245 | + up_deleted.add(repo.by_path(path)) |
| 261 | 246 | case Deleted(path) if path.suffix == '.toml': |
| 262 | | - config_deleted.add(repo.by_path(_resolve_repo_path(path, repo_root))) |
| 247 | + config_deleted.add(repo.by_path(path)) |
| 263 | 248 | case Modified(path) if path.suffix == '.sql': |
| 264 | | - up_modified.add(repo.by_path(_resolve_repo_path(path, repo_root))) |
| 249 | + up_modified.add(repo.by_path(path)) |
| 265 | 250 | case Modified(path) if path.suffix == '.toml': |
| 266 | | - config_modified.add(repo.by_path(_resolve_repo_path(path, repo_root))) |
| 251 | + config_modified.add(repo.by_path(path)) |
| 267 | 252 | case Renamed(old_path, new_path) if old_path.suffix == '.sql' and new_path.suffix == '.sql': |
| 268 | | - old_abs = _resolve_repo_path(old_path, repo_root) |
| 269 | | - new_abs = _resolve_repo_path(new_path, repo_root) |
| 270 | | - up_deleted.add(repo.by_path(old_abs)) |
| 271 | | - moved_paths[old_abs] = new_abs |
| 272 | | - redeploy_by_path.add(new_abs) |
| 253 | + up_deleted.add(repo.by_path(old_path)) |
| 254 | + moved_paths[repo.path / old_path] = repo.path / new_path |
| 255 | + redeploy_by_path.add(repo.path / new_path) |
| 273 | 256 | case Renamed(old_path, new_path) if old_path.suffix == '.toml' and new_path.suffix == '.toml': |
| 274 | | - old_abs = _resolve_repo_path(old_path, repo_root) |
| 275 | | - new_abs = _resolve_repo_path(new_path, repo_root) |
| 276 | | - config_deleted.add(repo.by_path(old_abs)) |
| 277 | | - moved_paths[old_abs] = new_abs |
| 257 | + config_deleted.add(repo.by_path(old_path)) |
| 258 | + moved_paths[repo.path / old_path] = repo.path / new_path |
| 278 | 259 | # Redeploys should not be triggered here, but by the up script path above. |
| 279 | 260 | # FIXME: Added migrations should only be applied if requested. |
| 280 | 261 | # For now, we assume all adds are intended to be applied, basically matching the behavior of `mitch up` on new files. |
| 281 | 262 | # But maybe, we should be closer to a `mitch pick` and only apply what the user explicitly wanted to add. |
| 282 | 263 | case Add(path) if path.suffix == '.sql': |
| 283 | | - new_paths.add(_resolve_repo_path(path, repo_root)) |
| 264 | + new_paths.add(repo.path / path) |
| 284 | 265 | case Add(path) if path.suffix == '.toml': |
| 285 | 266 | try: |
| 286 | 267 | # Maybe, we already have a migration with an up script, but no config yet. |
| 287 | 268 | # If so, we want to make sure to reapply that migration after checkout since the new config may introduce new dependencies or change IDs. |
| 288 | | - config_added.add(repo.by_path(_resolve_repo_path(path.with_suffix('').with_suffix('.up.sql'), repo_root))) |
| 269 | + config_added.add(repo.by_path(path.with_suffix('').with_suffix('.up.sql'))) |
| 289 | 270 | except MissingMigrationError: |
| 290 | 271 | pass |
| 291 | 272 | case Copied(_, new_path) if new_path.suffix == '.sql': |
| 292 | 273 | # Copies are treated as additions on the target branch, |
| 293 | 274 | # but we don't need to track them here since they don't cause reverts on the source branch. |
| 294 | | - new_paths.add(_resolve_repo_path(new_path, repo_root)) |
| 275 | + new_paths.add(repo.path / new_path) |
| 295 | 276 | |
| 296 | 277 | # Revert migrations on the current branch before switching branches. |
| 297 | 278 | with connection_for(database_url) as connection: |
| @@ -305,8 +286,7 @@ |
| 305 | 286 | |
| 306 | 287 | for migration in reverted: |
| 307 | 288 | if not migration in up_deleted: |
| 308 | | - old_path = _resolve_repo_path(migration.up_script, repo_root) |
| 309 | | - redeploy_by_path.add(moved_paths.get(old_path, old_path)) |
| 289 | + redeploy_by_path.add(moved_paths.get(migration.up_script, migration.up_script)) |
| 310 | 290 | |
| 311 | 291 | |
| 312 | 292 | # For dirty worktrees, stash only after DB reverts so reverts reflect current local files. |