-
Notifications
You must be signed in to change notification settings - Fork 33
Remove emergency alerts data #4201
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0464_create_svc_join_requests | ||
| 0465_delete_broadcast_data |
This file contains hidden or 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,104 @@ | ||
| from alembic import op | ||
| from sqlalchemy.sql import text | ||
| import sqlalchemy as sa | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
| revision = "0465_delete_broadcast_data" | ||
| down_revision = "0464_create_svc_join_requests" | ||
|
|
||
|
|
||
| def upgrade(): | ||
| """ | ||
| Removes all existance of broadcast specific services and all their associated data: | ||
|
|
||
| deletes ALL data from the following tables: | ||
|
|
||
| * broadcast_event | ||
| * broadcast_message | ||
| * broadcast_provider_message | ||
| * broadcast_provider_message_number | ||
| * service_broadcast_provider_restriction | ||
| * service_broadcast_settings | ||
|
|
||
| deletes all data linked to a broadcast service from any table with a `service_id` (or a `template_id` for templates | ||
| belonging to a broadcast service). | ||
|
|
||
| this does not touch the following static type tables | ||
|
|
||
| * broadcast_channel_types | ||
| * broadcast_provider_message_status_type | ||
| * broadcast_provider_types | ||
| * broadcast_status_type | ||
|
|
||
| this does not touch the following sequence | ||
|
|
||
| * broadcast_provider_message_number_seq | ||
| """ | ||
|
|
||
| conn = op.get_bind() | ||
| results = conn.execute("SELECT service_id FROM service_broadcast_settings;") | ||
| res = results.fetchall() | ||
| broadcast_service_ids = tuple(x.service_id for x in res) | ||
|
|
||
| # these are broadly alphabetical, but with some lines reordered due to precedence (eg needing to delete | ||
| # user_folder_permissions before we can delete the template folders they reference) | ||
| delete_statements = [ | ||
| # step 1: delete the entire tables for the broadcast specific things | ||
| "DELETE FROM broadcast_provider_message_number;", | ||
| "DELETE FROM broadcast_provider_message;", | ||
| "DELETE FROM broadcast_event;", | ||
| "DELETE FROM broadcast_message;", | ||
| "DELETE FROM service_broadcast_settings;", | ||
| "DELETE FROM service_broadcast_provider_restriction;", | ||
| # all these tables have service_id, so need to be deleted before we can delete the service, | ||
| # (note this includes templates as well, which we need to delete), | ||
| ] | ||
|
|
||
| if broadcast_service_ids: | ||
| delete_statements += [ | ||
| "DELETE FROM annual_billing WHERE service_id in :service_ids;", | ||
| "DELETE FROM api_keys WHERE service_id in :service_ids;", | ||
| "DELETE FROM complaints WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_sms_senders WHERE service_id in :service_ids;", | ||
| "DELETE FROM inbound_numbers WHERE service_id in :service_ids;", | ||
| "DELETE FROM inbound_sms WHERE service_id in :service_ids;", | ||
| "DELETE FROM inbound_sms_history WHERE service_id in :service_ids;", | ||
| "DELETE FROM invited_users WHERE service_id in :service_ids;", | ||
| "DELETE FROM jobs WHERE service_id in :service_ids;", | ||
| "DELETE FROM notification_history WHERE service_id in :service_ids;", | ||
| "DELETE FROM notifications WHERE service_id in :service_ids;", | ||
| "DELETE FROM permissions WHERE service_id in :service_ids;", | ||
| "DELETE FROM returned_letters WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_callback_api WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_contact_list WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_data_retention WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_email_branding WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_email_reply_to WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_inbound_api WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_join_requests WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_letter_branding WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_permissions WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_whitelist WHERE service_id in :service_ids;", | ||
| "DELETE FROM user_folder_permissions WHERE service_id in :service_ids", | ||
| "DELETE FROM template_folder_map WHERE template_id in (SELECT id FROM templates WHERE service_id in :service_ids);", | ||
| "DELETE FROM template_redacted WHERE template_id in (SELECT id FROM templates WHERE service_id in :service_ids);", | ||
| "DELETE FROM template_folder WHERE service_id in :service_ids;", | ||
| "DELETE FROM templates WHERE service_id in :service_ids;", | ||
| "DELETE FROM templates_history WHERE service_id in :service_ids;", | ||
| "DELETE FROM service_letter_contacts WHERE service_id in :service_ids;", | ||
| "DELETE FROM unsubscribe_request WHERE service_id in :service_ids;", | ||
| "DELETE FROM unsubscribe_request_history WHERE service_id in :service_ids;", | ||
| "DELETE FROM unsubscribe_request_report WHERE service_id in :service_ids;", | ||
| "DELETE FROM user_to_service WHERE service_id in :service_ids;", | ||
| # now we can finally delete the services | ||
| "DELETE FROM services WHERE id in :service_ids;", | ||
| "DELETE FROM services_history WHERE id in :service_ids;", | ||
| ] | ||
|
|
||
| for delete_statement in delete_statements: | ||
| conn.execute(text(delete_statement), service_ids=broadcast_service_ids) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # undowngradeable! | ||
| pass | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.