Created
June 21, 2021 18:39
-
-
Save kkirsche/975f6d5d05eb9a80ea743238162fedaa to your computer and use it in GitHub Desktop.
Generate Alembic Slug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
# https://github.com/sqlalchemy/alembic/blob/c97d5b3dd6fde31acb8e9e0c67d0ebc54fa0d809/alembic/script/base.py#L682 | |
_slug_re = re.compile(r"\w+") | |
truncate_slug_length = 40 | |
def generate_slug(message: str) -> str: | |
slug = "_".join(_slug_re.findall(message or "")).lower() | |
if len(slug) > truncate_slug_length: | |
slug = slug[: truncate_slug_length].rsplit("_", 1)[0] + "_" | |
return slug |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment