Skip to content

Remove emergency alerts data#4516

Merged
klssmith merged 1 commit into
mainfrom
ks-remove-emergency-alerts-data
Jul 17, 2025
Merged

Remove emergency alerts data#4516
klssmith merged 1 commit into
mainfrom
ks-remove-emergency-alerts-data

Conversation

@klssmith

@klssmith klssmith commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

This is a data migration (so no downgrade) that deletes broadcast services and all associated data - this includes obvious things like broadcast events and templates, but also everything connected to those services.

Although some of these theoretically shouldn't exist for broadcast services (eg returned_letters), we attempt to delete them out of an abundance of caution.

This work is based off an older PR, which was tested against a copy of the staging database. That PR was reverted because it was taking too long to delete from the notification_history table due to the foreign key constraints - since then, indexes have been added to notification_history to make deleting from the table faster.

Differences between this PR and the original are:

  • the service_inbound_api table no longer exists, so has been removed from the migration
  • this adds the api_keys_history, service_callback_api_history, ft_billing and ft_notification_status tables to the list we delete from
  • this deletes from the notifications and notification_history tables first - these have various foreign key constraints on other tables which would cause issues if the data from those other tables is deleted first.

This is a data migration (so no downgrade) that deletes broadcast
services and all associated data - this includes obvious things like
broadcast events and templates, but also everything connected to those
services.

Although some of these theoretically shouldn't exist for broadcast
services (eg returned_letters), we attempt to delete them out of an
abundance of caution.

This work is based off an older PR, which was tested against a copy of the
staging database. That PR was reverted because it was taking too long to
delete from the `notification_history` table due to the foreign key
constraints - since then, indexes have been added to
notification_history to make deleting from the table faster.

Differences between this PR and the original are:
* the `service_inbound_api` table no longer exists, so has been removed
  from the migration
* this adds the `api_keys_history`, `service_callback_api_history`,
  `ft_billing` and `ft_notification_status` tables to the list we delete
  from
* this deletes from the `notifications` and `notification_history` tables
  first - these have various foreign key constraints on other tables
  which would cause issues if the data from those other tables is deleted
  first.
@klssmith

klssmith commented Jul 9, 2025

Copy link
Copy Markdown
Contributor Author

Squawk is giving this error

...
    res = results.fetchall()
          ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'fetchall' 

I have tested this locally and confirmed that results is a sqlalchemy.engine.cursor.LegacyCursorResult, and that calling its fetchall method returns a list. The same code has also been run on production before (the first time this was deployed) without issues, so this error seems to be specific to how the migrations are being tested with Squawk

@klssmith klssmith merged commit d75cafd into main Jul 17, 2025
4 of 5 checks passed
@klssmith klssmith deleted the ks-remove-emergency-alerts-data branch July 17, 2025 09:30
@klssmith klssmith mentioned this pull request Jul 30, 2025
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants