-
Notifications
You must be signed in to change notification settings - Fork 31
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 index and function to check group3_inpn (#433)
* feat(db): add vm and function to check group3_inpn * refactor(db): replace vm by index in taxref Updated sql function not to use vm but to select in taxref instead
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
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,49 @@ | ||
"""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 INDEX i_taxref_group3_inpn ON taxonomie.taxref 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 EXISTS (SELECT 1 FROM taxonomie.taxref WHERE group3_inpn = mygroup ) OR mygroup IS NULL THEN | ||
RETURN true; | ||
ELSE | ||
RETURN false; | ||
END IF; | ||
END; | ||
$function$; | ||
""" | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.execute("DROP INDEX taxonomie.i_taxref_group3_inpn") | ||
op.execute("DROP FUNCTION taxonomie.check_is_group3inpn") |