-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SUIVI-EOLIEN] Séparation des groupes de sites et sites (db + api), style page d'accueil #204
Changes from 22 commits
6d55b19
466a6e9
a625733
697823d
e717216
8b09df2
1d58043
4b0139a
aa379ee
6a135d4
ecc02a4
15edb4b
a38eda5
83aa91a
dbcf9a0
a122e9b
b0d968e
e549193
ec1bf2a
a4c7f29
2834de1
0e15017
668f14f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""remove_id_module_from_sites_complements | ||
|
||
Revision ID: 6673266fb79c | ||
Revises: a54bafb13ce8 | ||
Create Date: 2022-12-13 16:00:00.512562 | ||
|
||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
from gn_module_monitoring import MODULE_CODE | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "6673266fb79c" | ||
down_revision = "a54bafb13ce8" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
monitorings_schema = "gn_monitoring" | ||
|
||
|
||
def upgrade(): | ||
op.drop_column("t_site_complements", "id_module", schema=monitorings_schema) | ||
|
||
|
||
def downgrade(): | ||
op.add_column( | ||
"t_site_complements", | ||
sa.Column( | ||
"id_module", | ||
sa.Integer(), | ||
sa.ForeignKey( | ||
f"gn_commons.t_modules.id_module", | ||
name="fk_t_site_complements_id_module", | ||
ondelete="CASCADE", | ||
onupdate="CASCADE", | ||
), | ||
nullable=True, | ||
), | ||
schema=monitorings_schema, | ||
) | ||
# Cannot use orm here because need the model to be "downgraded" as well | ||
# Need to set nullable True above for existing rows | ||
# FIXME: find a better way because need to assign a module... | ||
statement = sa.text( | ||
f""" | ||
update {monitorings_schema}.t_site_complements | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Si j'ai bien compris id_module de t_site_compléments sera peuplé avec la valeur 'MONITORINGS' ce qui n'est pas un vrai retour en arrière There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oui ce n'est pas idéal mais je ne sais pas si c'est possible de faire le downgrade à l'identique ici car on désolidarise les sites des modules |
||
set id_module = (select id_module | ||
from gn_commons.t_modules tm | ||
where module_code = :module_code); | ||
""" | ||
).bindparams(module_code=MODULE_CODE) | ||
op.execute(statement) | ||
op.alter_column("t_site_complements", "id_module", nullable=False, schema=monitorings_schema) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""create_cor_module_type | ||
|
||
Revision ID: a54bafb13ce8 | ||
Revises: ce54ba49ce5c | ||
Create Date: 2022-12-06 16:18:24.512562 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "a54bafb13ce8" | ||
down_revision = "ce54ba49ce5c" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
monitorings_schema = "gn_monitoring" | ||
referent_schema = "gn_commons" | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
"cor_module_type", | ||
sa.Column( | ||
"id_type_site", | ||
sa.Integer(), | ||
sa.ForeignKey( | ||
f"{monitorings_schema}.bib_type_site.id_nomenclature", | ||
name="fk_cor_module_type_id_nomenclature", | ||
ondelete="CASCADE", | ||
onupdate="CASCADE", | ||
), | ||
nullable=False, | ||
), | ||
sa.Column( | ||
"id_module", | ||
sa.Integer(), | ||
sa.ForeignKey( | ||
f"{referent_schema}.t_modules.id_module", | ||
name="fk_cor_module_type_id_module", | ||
ondelete="CASCADE", | ||
onupdate="CASCADE", | ||
), | ||
nullable=False, | ||
), | ||
sa.PrimaryKeyConstraint("id_type_site", "id_module", name="pk_cor_module_type"), | ||
schema=monitorings_schema, | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table("cor_module_type", schema=monitorings_schema) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""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" | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
"bib_type_site", | ||
sa.Column( | ||
"id_nomenclature", | ||
mvergez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
) | ||
|
||
# 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(): | ||
op.drop_table("bib_type_site", schema=monitorings_schema) |
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""remove_id_module_from_sites_groups | ||
|
||
Revision ID: f24adb481f54 | ||
Revises: 6673266fb79c | ||
Create Date: 2022-12-13 16:00:00.512562 | ||
|
||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
from gn_module_monitoring import MODULE_CODE | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "f24adb481f54" | ||
down_revision = "6673266fb79c" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
monitorings_schema = "gn_monitoring" | ||
|
||
|
||
def upgrade(): | ||
op.drop_column("t_sites_groups", "id_module", schema=monitorings_schema) | ||
|
||
|
||
def downgrade(): | ||
op.add_column( | ||
"t_sites_groups", | ||
sa.Column( | ||
"id_module", | ||
sa.Integer(), | ||
sa.ForeignKey( | ||
f"gn_commons.t_modules.id_module", | ||
name="fk_t_sites_groups_id_module", | ||
ondelete="CASCADE", | ||
onupdate="CASCADE", | ||
), | ||
nullable=True, | ||
), | ||
schema=monitorings_schema, | ||
) | ||
# Cannot use orm here because need the model to be "downgraded" as well | ||
# Need to set nullable True above for existing rows | ||
# FIXME: find a better way because need to assign a module... | ||
statement = sa.text( | ||
f""" | ||
update {monitorings_schema}.t_sites_groups | ||
set id_module = (select id_module | ||
from gn_commons.t_modules tm | ||
where module_code = :module_code); | ||
""" | ||
).bindparams(module_code=MODULE_CODE) | ||
op.execute(statement) | ||
op.alter_column("t_sites_groups", "id_module", nullable=False, schema=monitorings_schema) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dans mon souvenir on avait pas dit qu'on évitait les delete cascades?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Voilà ce qu'on a décidé :
Donc CASCADE seulement sur
cor_module_type
sur id_type_site etid_module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalement, après vérification, tout était déjà bon. J'attends ton retour