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,
)
| 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: |