forked from PnX-SI/gn_module_monitoring
-
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): upgrade down_revision following rebase Since rebase with develop: changed the down_revision number * fix(db): fix bind params enabling downgrade Beforehand the downgrade was not possible... * refactor(db): removed cor_site_type_category * refactor(db): changed category into type in cor * refactor(db): create cor_type_site * fix(db): renamed column * refactor(api): update models to fit migrations * fix(db):change bib_categorie_site to bib_type_site Adding : cor_site_module cor_site_type revision alembic to create function and trigger in order to add bib_type_site but only with nomenclature 'TYPE_SITE' upgrade and downgrade works [Refs ticket]: #3 Reviewed-by: andriac * fix(api): updated models from migrations * fix(api): wip: fix admin following migrations * fix(api): update routes and tests To match migration changes * feat: flask admin bib_type_site Change bib_categories to bib_type_site into flask admin Adding filtering in list label_fr of type_site to secure the unique constraint Reviewed-by: andriac [Refs ticket]: #3 * fix(api): updated schema to match models * fix(api): module edition * style(api): uniformize type_site * style(api): change relationship name for type_site * feat(api): validator admin * fix(api): make unique BibTypeSite in admin * test(api): fix test when existing nomenclatures In database Co-authored-by: Andria Capai <[email protected]>
- Loading branch information
Showing
22 changed files
with
349 additions
and
240 deletions.
There are no files selected for viewing
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
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
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
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
60 changes: 0 additions & 60 deletions
60
backend/gn_module_monitoring/migrations/b53bafb13ce8_create_bib_categorie_site.py
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
backend/gn_module_monitoring/migrations/b53bafb13ce8_create_bib_type_site.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,71 @@ | ||
"""create_bib_type_site | ||
Revision ID: b53bafb13ce8 | ||
Revises: e78003460441 | ||
Create Date: 2022-12-06 16:18:24.512562 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "b53bafb13ce8" | ||
down_revision = "e78003460441" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
monitorings_schema = "gn_monitoring" | ||
nomenclature_schema = "ref_nomenclatures" | ||
|
||
TYPE_SITE = "TYPE_SITE" | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
"bib_type_site", | ||
sa.Column( | ||
"id_nomenclature", | ||
sa.Integer(), | ||
sa.ForeignKey( | ||
f"{nomenclature_schema}.t_nomenclatures.id_nomenclature", | ||
name="fk_t_nomenclatures_id_nomenclature", | ||
), | ||
nullable=False, | ||
unique=True, | ||
), | ||
sa.PrimaryKeyConstraint("id_nomenclature"), | ||
sa.Column("config", sa.JSON(), nullable=True), | ||
schema=monitorings_schema, | ||
) | ||
|
||
statement = sa.text( | ||
f""" | ||
CREATE OR REPLACE FUNCTION {monitorings_schema}.ck_bib_type_site_id_nomenclature() | ||
RETURNS trigger | ||
LANGUAGE plpgsql | ||
AS $function$ | ||
BEGIN | ||
perform {nomenclature_schema}.check_nomenclature_type_by_mnemonique(NEW.id_nomenclature, :mnemonique ); | ||
RETURN NEW; | ||
END; | ||
$function$ | ||
; | ||
DROP TRIGGER IF EXISTS ck_bib_type_site_id_nomenclature on gn_monitoring.bib_type_site; | ||
CREATE TRIGGER ck_bib_type_site_id_nomenclature BEFORE | ||
INSERT | ||
OR | ||
UPDATE ON {monitorings_schema}.bib_type_site FOR EACH ROW EXECUTE PROCEDURE {monitorings_schema}.ck_bib_type_site_id_nomenclature(); | ||
""" | ||
).bindparams(mnemonique=TYPE_SITE) | ||
op.execute(statement) | ||
|
||
|
||
def downgrade(): | ||
|
||
op.drop_table("bib_type_site", schema=monitorings_schema) | ||
statement = sa.text( | ||
f""" | ||
DROP FUNCTION IF EXISTS {monitorings_schema}.ck_bib_type_site_id_nomenclature; | ||
""" | ||
) | ||
op.execute(statement) |
51 changes: 51 additions & 0 deletions
51
backend/gn_module_monitoring/migrations/ce54ba49ce5c_create_cor_type_site.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,51 @@ | ||
"""create_cor_type_site | ||
Revision ID: ce54ba49ce5c | ||
Revises: b53bafb13ce8 | ||
Create Date: 2022-12-06 16:18:24.512562 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "ce54ba49ce5c" | ||
down_revision = "b53bafb13ce8" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
monitorings_schema = "gn_monitoring" | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
"cor_type_site", | ||
sa.Column( | ||
"id_type_site", | ||
sa.Integer(), | ||
sa.ForeignKey( | ||
f"{monitorings_schema}.bib_type_site.id_nomenclature", | ||
name="fk_cor_type_site_id_nomenclature", | ||
ondelete="CASCADE", | ||
onupdate="CASCADE", | ||
), | ||
nullable=False, | ||
), | ||
sa.Column( | ||
"id_base_site", | ||
sa.Integer(), | ||
sa.ForeignKey( | ||
f"{monitorings_schema}.t_base_sites.id_base_site", | ||
name="fk_cor_type_site_id_base_site", | ||
ondelete="CASCADE", | ||
onupdate="CASCADE", | ||
), | ||
nullable=False, | ||
), | ||
sa.PrimaryKeyConstraint("id_type_site", "id_base_site", name="pk_cor_type_site"), | ||
schema=monitorings_schema, | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table("cor_type_site", schema=monitorings_schema) |
47 changes: 0 additions & 47 deletions
47
backend/gn_module_monitoring/migrations/e64bafb13ce8_create_cor_site_type_category.py
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.