Provides operations upon an Alembic script directory. This object is useful to get information as to current revisions, most notably being able to get at the "head" revision, for schemes that want to test if the current revision in the database is the most recent:: from ale
| 51 | |
| 52 | |
| 53 | class ScriptDirectory: |
| 54 | """Provides operations upon an Alembic script directory. |
| 55 | |
| 56 | This object is useful to get information as to current revisions, |
| 57 | most notably being able to get at the "head" revision, for schemes |
| 58 | that want to test if the current revision in the database is the most |
| 59 | recent:: |
| 60 | |
| 61 | from alembic.script import ScriptDirectory |
| 62 | from alembic.config import Config |
| 63 | config = Config() |
| 64 | config.set_main_option("script_location", "myapp:migrations") |
| 65 | script = ScriptDirectory.from_config(config) |
| 66 | |
| 67 | head_revision = script.get_current_head() |
| 68 | |
| 69 | |
| 70 | |
| 71 | """ |
| 72 | |
| 73 | def __init__( |
| 74 | self, |
| 75 | dir: Union[str, os.PathLike[str]], # noqa: A002 |
| 76 | file_template: str = _default_file_template, |
| 77 | truncate_slug_length: Optional[int] = 40, |
| 78 | version_locations: Optional[ |
| 79 | Sequence[Union[str, os.PathLike[str]]] |
| 80 | ] = None, |
| 81 | sourceless: bool = False, |
| 82 | output_encoding: str = "utf-8", |
| 83 | timezone: Optional[str] = None, |
| 84 | hooks: list[PostWriteHookConfig] = [], |
| 85 | recursive_version_locations: bool = False, |
| 86 | messaging_opts: MessagingOptions = cast( |
| 87 | "MessagingOptions", util.EMPTY_DICT |
| 88 | ), |
| 89 | ) -> None: |
| 90 | self.dir = _preserving_path_as_str(dir) |
| 91 | self.version_locations = [ |
| 92 | _preserving_path_as_str(p) for p in version_locations or () |
| 93 | ] |
| 94 | self.file_template = file_template |
| 95 | self.truncate_slug_length = truncate_slug_length or 40 |
| 96 | self.sourceless = sourceless |
| 97 | self.output_encoding = output_encoding |
| 98 | self.revision_map = revision.RevisionMap(self._load_revisions) |
| 99 | self.timezone = timezone |
| 100 | self.hooks = hooks |
| 101 | self.recursive_version_locations = recursive_version_locations |
| 102 | self.messaging_opts = messaging_opts |
| 103 | |
| 104 | if not os.access(dir, os.F_OK): |
| 105 | raise util.CommandError( |
| 106 | f"Path doesn't exist: {dir}. Please use " |
| 107 | "the 'init' command to create a new " |
| 108 | "scripts folder." |
| 109 | ) |
| 110 |
no outgoing calls
searching dependent graphs…