forked from PnX-SI/TaxHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db): add vm and function to check group3_inpn
- Loading branch information
Maxime Vergez
committed
Sep 4, 2023
1 parent
7929f8e
commit 76b8d86
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
apptax/migrations/versions/33e20a7682b4_check_group3_inpn_vm_function.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""check_group3_inpn_vm_and_function | ||
Revision ID: 33e20a7682b4 | ||
Revises: 32c5ed42bdbd | ||
Create Date: 2023-09-04 08:23:34.336383 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "33e20a7682b4" | ||
down_revision = "32c5ed42bdbd" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.execute( | ||
""" | ||
CREATE MATERIALIZED VIEW taxonomie.vm_group3_inpn | ||
TABLESPACE pg_default | ||
AS SELECT DISTINCT tx.group3_inpn | ||
FROM taxonomie.taxref tx | ||
WHERE tx.group3_inpn notnull | ||
WITH DATA; | ||
CREATE UNIQUE INDEX i_unique_group3_inpn ON taxonomie.vm_group3_inpn USING btree (group3_inpn); | ||
""" | ||
) | ||
|
||
op.execute( | ||
""" | ||
CREATE OR REPLACE FUNCTION taxonomie.check_is_group3inpn(mygroup text) | ||
RETURNS boolean | ||
LANGUAGE plpgsql | ||
IMMUTABLE | ||
AS $function$ | ||
--fonction permettant de vérifier si un texte proposé correspond à un group3_inpn dans la table taxref | ||
BEGIN | ||
IF mygroup IN(SELECT group3_inpn FROM taxonomie.vm_group3_inpn) OR mygroup IS NULL THEN | ||
RETURN true; | ||
ELSE | ||
RETURN false; | ||
END IF; | ||
END; | ||
$function$; | ||
""" | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.execute("DROP MATERIALIZED VIEW taxonomie.vm_group3_inpn") | ||
op.execute("DROP FUNCTION taxonomie.check_is_group3inpn") |