Add `Repository.by_path` to find migrations by path.
public
Add `Repository.by_path` to find migrations by path.
| Changeset | e83f6f6462e87b3e5075489644e84b30ff1eef3f |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | 793dd7b39a95 |
| Children | |
| Pushlog | by timo via ssh |
modified src/mitch/repository.py +10 −3
| @@ -32,9 +32,9 @@ | ||
| 32 | 32 | |
| 33 | 33 | migration = Migration( |
| 34 | 34 | id=config.get('id', stem), |
| 35 | - up_script=up_script, | |
| 36 | - down_script=down_script if down_script.exists() else None, | |
| 37 | - config_file=config_file if config_file.exists() else None, | |
| 35 | + up_script=up_script.resolve(), | |
| 36 | + down_script=down_script.resolve() if down_script.exists() else None, | |
| 37 | + config_file=config_file.resolve() if config_file.exists() else None, | |
| 38 | 38 | transactional=config.get('transactional', True), |
| 39 | 39 | idempotent=config.get('idempotent', False), |
| 40 | 40 | created_at=self._created_at_from_config(config.get('created_at'), config_file), |
| @@ -96,6 +96,13 @@ | ||
| 96 | 96 | yield migration |
| 97 | 97 | sorter.done(migration.id) |
| 98 | 98 | |
| 99 | + def by_path(self, migration_path: Path | str) -> Migration: | |
| 100 | + migration_path = Path(migration_path).resolve() | |
| 101 | + for migration in self.migrations: | |
| 102 | + if migration_path in (migration.up_script, migration.down_script, migration.config_file): | |
| 103 | + return migration | |
| 104 | + raise MissingMigrationError(f"No migration found for path: {migration_path}") | |
| 105 | + | |
| 99 | 106 | def by_id(self, migration_id: str) -> Migration: |
| 100 | 107 | try: |
| 101 | 108 | return self.migrations_by_id[migration_id] |