Skip to content

Commit

Permalink
[suite] Modify downgrade for the migration
Browse files Browse the repository at this point in the history
[suite] Migration to inherit permissions for modules and objects

fix: Change 'id_permission' to 'id_filter'
fix: Manage order in which operations are done
Signed-off-by: VincentCauchois <vincent.cauchois@mnhn.fr>
  • Loading branch information
VincentCauchois committed Apr 28, 2023
1 parent 3ba0943 commit ad1917c
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,13 @@ def downgrade():
Restore the permissions and filters from backup
"""

# First delete permissions, to be able to restore filters
op.execute(
"""
DELETE FROM gn_permissions.cor_role_action_filter_module_object;
"""
)

"""
Restore filters from backup table
Expand All @@ -544,21 +551,15 @@ def downgrade():
op.execute(
"""
INSERT INTO gn_permissions.t_filters
(id_permission, label_filter, value_filter, description_filter, id_filter_type)
SELECT id_permission, label_filter, value_filter, description_filter, id_filter_type
(id_filter, label_filter, value_filter, description_filter, id_filter_type)
SELECT id_filter, label_filter, value_filter, description_filter, id_filter_type
FROM gn_permissions.backup_t_filters
"""
)
op.drop_table(schema="gn_permissions", table_name="backup_t_filters")

"""
Restore permissions from backup table
"""
op.execute(
"""
DELETE FROM gn_permissions.cor_role_action_filter_module_object;
"""
)
op.execute(
"""
INSERT INTO gn_permissions.cor_role_action_filter_module_object
Expand All @@ -567,6 +568,13 @@ def downgrade():
FROM gn_permissions.backup_cor_role_action_filter_module_object;
"""
)

"""
Drop backup tables
drop 'backup_t_filters' after 'backup_cor_role_action_filter_module_object' because of
'fk_backup_cor_r_a_f_m_o_id_filter' referencing 'backup_t_filters'
"""
op.drop_table(
schema="gn_permissions", table_name="backup_cor_role_action_filter_module_object"
)

0 comments on commit ad1917c

Please sign in to comment.