MCPcopy
hub / github.com/sqlalchemy/alembic / generate_revision

Method generate_revision

alembic/script/base.py:622–772  ·  view source on GitHub ↗

Generate a new revision file. This runs the ``script.py.mako`` template, given template arguments, and creates a new file. :param revid: String revision id. Typically this comes from ``alembic.util.rev_id()``. :param message: the revision message, the one

(
        self,
        revid: str,
        message: Optional[str],
        head: Optional[_RevIdType] = None,
        splice: Optional[bool] = False,
        branch_labels: Optional[_RevIdType] = None,
        version_path: Union[str, os.PathLike[str], None] = None,
        file_template: Optional[str] = None,
        depends_on: Optional[_RevIdType] = None,
        **kw: Any,
    )

Source from the content-addressed store, hash-verified

620 return create_date
621
622 def generate_revision(
623 self,
624 revid: str,
625 message: Optional[str],
626 head: Optional[_RevIdType] = None,
627 splice: Optional[bool] = False,
628 branch_labels: Optional[_RevIdType] = None,
629 version_path: Union[str, os.PathLike[str], None] = None,
630 file_template: Optional[str] = None,
631 depends_on: Optional[_RevIdType] = None,
632 **kw: Any,
633 ) -> Optional[Script]:
634 """Generate a new revision file.
635
636 This runs the ``script.py.mako`` template, given
637 template arguments, and creates a new file.
638
639 :param revid: String revision id. Typically this
640 comes from ``alembic.util.rev_id()``.
641 :param message: the revision message, the one passed
642 by the -m argument to the ``revision`` command.
643 :param head: the head revision to generate against. Defaults
644 to the current "head" if no branches are present, else raises
645 an exception.
646 :param splice: if True, allow the "head" version to not be an
647 actual head; otherwise, the selected head must be a head
648 (e.g. endpoint) revision.
649
650 """
651 if head is None:
652 head = "head"
653
654 try:
655 Script.verify_rev_id(revid)
656 except revision.RevisionError as err:
657 raise util.CommandError(err.args[0]) from err
658
659 with self._catch_revision_errors(
660 multiple_heads=(
661 "Multiple heads are present; please specify the head "
662 "revision on which the new revision should be based, "
663 "or perform a merge."
664 )
665 ):
666 heads = cast(
667 Tuple[Optional["Revision"], ...],
668 self.revision_map.get_revisions(head),
669 )
670 for h in heads:
671 assert h != "base" # type: ignore[comparison-overlap]
672
673 if len(set(heads)) != len(heads):
674 raise util.CommandError("Duplicate head revisions specified")
675
676 create_date = self._generate_create_date()
677
678 if version_path is None:
679 if len(self._version_locations) > 1:

Callers 15

mergeFunction · 0.80
three_rev_fixtureFunction · 0.80
multi_heads_fixtureFunction · 0.80
_to_scriptMethod · 0.80
_test_001_revisionsMethod · 0.80
setUpMethod · 0.80
test_optionMethod · 0.80
test_lookup_legacyMethod · 0.80
test_needs_flagMethod · 0.80

Calls 11

_generate_create_dateMethod · 0.95
_ensure_directoryMethod · 0.95
_rev_pathMethod · 0.95
_generate_templateMethod · 0.95
not_noneFunction · 0.85
verify_rev_idMethod · 0.80
_from_pathMethod · 0.80
add_revisionMethod · 0.80
get_revisionsMethod · 0.45
get_revisionMethod · 0.45

Tested by 15

_test_001_revisionsMethod · 0.64
setUpMethod · 0.64
test_optionMethod · 0.64
test_lookup_legacyMethod · 0.64
test_needs_flagMethod · 0.64
non_recursive_fixtureMethod · 0.64
depends_on_fixtureMethod · 0.64
setup_classMethod · 0.64
setup_classMethod · 0.64