Skip to content

Commit

Permalink
db downgrade does not work with data (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelclems authored and amandine-sahl committed Jul 29, 2024
1 parent 7321655 commit e776909
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ def downgrade():
op.drop_table("t_visit_complements", schema=monitorings_schema)

# Remove all GNM related objects

op.execute(
"""
DELETE FROM
gn_permissions.t_permissions p
USING gn_permissions.t_objects o
WHERE
p.id_object = o.id_object
AND o.code_object like 'GNM_%'
;
"""
)

op.execute(
"""
DELETE FROM
gn_permissions.t_permissions_available p
USING gn_permissions.t_objects o
WHERE
p.id_object = o.id_object
AND o.code_object like 'GNM_%'
;
"""
)

statement = sa.delete(TObjects).where(TObjects.code_object.like("GNM_%"))
op.execute(statement)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,12 @@ def downgrade():
"""
)
op.execute(statement)

statement = sa.text(
f"""
DELETE FROM gn_monitoring.t_site_complements WHERE id_module IS NULL;
"""
)
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
Expand Up @@ -124,6 +124,18 @@ def downgrade():
"""
)

op.execute(
"""
DELETE FROM
gn_permissions.t_permissions p
USING gn_permissions.t_objects o
WHERE
p.id_object = o.id_object
AND o.code_object = 'TYPES_SITES'
;
"""
)

op.execute(
"""
DELETE FROM
Expand Down

0 comments on commit e776909

Please sign in to comment.