mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-05-19 00:38:21 +00:00
416a6caf2d
Previously, triggers lived only in a particular migration file. With this change, code for the triggers resides in the model, and their lifecycle is managed through normal Django migrations.
23 lines
509 B
Python
23 lines
509 B
Python
""" Database utilities """
|
|
|
|
from typing import cast
|
|
import sqlparse # type: ignore
|
|
|
|
|
|
def format_trigger(sql: str) -> str:
|
|
"""format SQL trigger before storing
|
|
|
|
we remove whitespace and use consistent casing so as to avoid migrations
|
|
due to formatting changes.
|
|
"""
|
|
return cast(
|
|
str,
|
|
sqlparse.format(
|
|
sql,
|
|
strip_comments=True,
|
|
strip_whitespace=True,
|
|
keyword_case="upper",
|
|
identifier_case="lower",
|
|
),
|
|
)
|