Skip to content

Commit

Permalink
fix(db): add NOT VALID in constraint for bib_type_site (#36)
Browse files Browse the repository at this point in the history
Cannot use alembic to do this because need sqlalchemy >= 1.4.32
  • Loading branch information
mvergez authored Jan 17, 2023
1 parent 2834de1 commit 0e15017
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,26 @@ def upgrade():
schema=monitorings_schema,
)

op.create_check_constraint(
"ck_bib_type_site_id_nomenclature",
"bib_type_site",
f"{nomenclature_schema}.check_nomenclature_type_by_mnemonique(id_nomenclature,'TYPE_SITE')",
schema=monitorings_schema,
# FIXME: if sqlalchemy >= 1.4.32, it should work with postgresql_not_valid=True: cleaner
# op.create_check_constraint(
# "ck_bib_type_site_id_nomenclature",
# "bib_type_site",
# f"{nomenclature_schema}.check_nomenclature_type_by_mnemonique(id_nomenclature,'TYPE_SITE')",
# schema=monitorings_schema,
# postgresql_not_valid=True
# )
statement = sa.text(
f"""
ALTER TABLE {monitorings_schema}.bib_type_site
ADD
CONSTRAINT ck_bib_type_site_id_nomenclature CHECK (
{nomenclature_schema}.check_nomenclature_type_by_mnemonique(
id_nomenclature, 'TYPE_SITE' :: character varying
)
) NOT VALID
"""
)
op.execute(statement)


def downgrade():
Expand Down

0 comments on commit 0e15017

Please sign in to comment.