-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- db and model evolution to make site cross module - some fixes on GN2CommonModule forms
- Loading branch information
1 parent
3adc7b4
commit 6928098
Showing
12 changed files
with
566 additions
and
46 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
2 changes: 1 addition & 1 deletion
2
backend/geonature/migrations/versions/5a2c9c65129f_add_sensitivity_filter_export_synthese.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
67 changes: 67 additions & 0 deletions
67
...onature/migrations/versions/6734d8f7eb2a_monitoring_add_id_digitizer_to_t_observations.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,67 @@ | ||
"""[monitoring] add id_digitizer to t_observations | ||
Revision ID: 6734d8f7eb2a | ||
Revises: 9b88459c1298 | ||
Create Date: 2024-01-16 15:50:30.308266 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "6734d8f7eb2a" | ||
down_revision = "9b88459c1298" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
monitorings_schema = "gn_monitoring" | ||
table = "t_observations" | ||
column = "id_digitiser" | ||
|
||
foreign_schema = "utilisateurs" | ||
table_foreign = "t_roles" | ||
foreign_key = "id_role" | ||
|
||
|
||
def upgrade(): | ||
op.add_column( | ||
table, | ||
sa.Column( | ||
column, | ||
sa.Integer(), | ||
sa.ForeignKey( | ||
f"{foreign_schema}.{table_foreign}.{foreign_key}", | ||
name=f"fk_{table}_{column}", | ||
onupdate="CASCADE", | ||
), | ||
), | ||
schema=monitorings_schema, | ||
) | ||
op.execute( | ||
""" | ||
UPDATE gn_monitoring.t_observations o SET id_digitiser = tbv.id_digitiser | ||
FROM gn_monitoring.t_base_visits AS tbv | ||
WHERE tbv.id_base_visit = o.id_base_visit; | ||
""" | ||
) | ||
# Set not null constraint | ||
op.alter_column( | ||
table_name=table, | ||
column_name=column, | ||
existing_type=sa.Integer(), | ||
nullable=False, | ||
schema=monitorings_schema, | ||
) | ||
|
||
|
||
def downgrade(): | ||
statement = sa.text( | ||
f""" | ||
ALTER TABLE {monitorings_schema}.{table} DROP CONSTRAINT fk_{table}_{column}; | ||
""" | ||
) | ||
op.execute(statement) | ||
op.drop_column(table, column, schema=monitorings_schema) |
38 changes: 38 additions & 0 deletions
38
...ture/migrations/versions/8309591841f3_monitoring_add_observers_txt_column_t_base_visit.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,38 @@ | ||
"""[monitoring] add_observers_txt_column_t_base_visit | ||
Revision ID: 8309591841f3 | ||
Revises: 5a2c9c65129f | ||
Create Date: 2023-10-06 11:07:43.532623 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "8309591841f3" | ||
down_revision = "ebbe0f7ed866" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
monitorings_schema = "gn_monitoring" | ||
table = "t_base_visits" | ||
column = "observers_txt" | ||
|
||
|
||
def upgrade(): | ||
op.add_column( | ||
table, | ||
sa.Column( | ||
column, | ||
sa.Text(), | ||
nullable=True, | ||
), | ||
schema=monitorings_schema, | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column(table, column, schema=monitorings_schema) |
55 changes: 55 additions & 0 deletions
55
backend/geonature/migrations/versions/9b88459c1298_monitoring_create_t_observations.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 @@ | ||
"""[monitoring] create t_observations | ||
Revision ID: 9b88459c1298 | ||
Revises: a54bafb13ce8 | ||
Create Date: 2024-01-16 15:41:13.331912 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "9b88459c1298" | ||
down_revision = "a54bafb13ce8" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.execute( | ||
""" | ||
CREATE TABLE IF NOT EXISTS gn_monitoring.t_observations ( | ||
id_observation SERIAL NOT NULL, | ||
id_base_visit INTEGER NOT NULL, | ||
cd_nom INTEGER NOT NULL, | ||
comments TEXT, | ||
uuid_observation UUID DEFAULT uuid_generate_v4() NOT NULL, | ||
CONSTRAINT pk_t_observations PRIMARY KEY (id_observation), | ||
CONSTRAINT fk_t_observations_id_base_visit FOREIGN KEY (id_base_visit) | ||
REFERENCES gn_monitoring.t_base_visits (id_base_visit) MATCH SIMPLE | ||
ON UPDATE CASCADE ON DELETE CASCADE | ||
); | ||
""" | ||
) | ||
op.execute( | ||
""" | ||
INSERT INTO gn_commons.bib_tables_location(table_desc, schema_name, table_name, pk_field, uuid_field_name) | ||
VALUES | ||
('Table centralisant les observations réalisées lors d''une visite sur un site', 'gn_monitoring', 't_observations', 'id_observation', 'uuid_observation') | ||
ON CONFLICT(schema_name, table_name) DO NOTHING; | ||
""" | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.execute( | ||
""" | ||
DELETE FROM gn_commons.bib_tables_location | ||
WHERE schema_name = 'gn_monitoring' AND table_name = 't_observations'; | ||
""" | ||
) | ||
op.drop_table("t_observations", schema="gn_monitoring") |
Oops, something went wrong.