Commit Graph

702 Commits

Author SHA1 Message Date
Rebecca Law
0849070eca Add created_at and updated_at columns to ft_processing_time 2021-02-26 07:49:49 +00:00
Rebecca Law
21edf7bfdd Persist the processing time statistics to the database.
The performance platform is going away soon. The only stat that we do not have in our database is the processing time. Let me clarify the only statistic we don't have in our database that we can query efficiently is the processing time. Any queries on notification_history are too inefficient to use on a web page.
Processing time = the total number of normal/team emails and text messages plus the number of messages that have gone from created to sending within 10 seconds per whole day. We can then easily calculate the percentage of messages that were marked as sending under 10 seconds.
2021-02-26 07:49:49 +00:00
David McDonald
ce2f550387 Backfill services_broadcast_settings table
At the moment, we currently have broadcast services that have the
'broadcast' service permission in the DB but don't have a corresponding
row in the service_broadcast_settings table. It's important to give them
a row in this table because this will control which broadcast channel
their messages will go out on. All broadcast services will be expected
to have this row so we can then remove hardcoded defaults from our code
that currently set what channel a message should go out on.

Whilst, when this gets deployed, we will have released
https://github.com/alphagov/notifications-admin/pull/3794, which means
that when a service setting is changed via that form, they will get the
corresponding row in the service_broadcast_settings form, we don't want
to ask every developer to go and fill in this form for every service on
their local dev environment and also do the same to every service we
have in preview, staging and production. Therefore a migration is the
best way to backfill the data.

Note, I made the decision that a service that is in trial mode will be
given the 'severe' channel. This is because this is what most trial mode
services should have. Only the MNOs would ever really have a trial mode
service on the test channel. And given they are in trial mode, it is not
too risky to give them the 'severe' channel.

For services that are live though, although there are no services in
production that have the broadcast permission and are live, it is not
worth taking that risk and accidently setting that service to send an
alert out on the 'severe' channel. We play it say by choosing 'test'.
2021-02-23 17:15:05 +00:00
Pea Tyczynska
b05ddd4978 Don't donwgrade if the environment is production
Because we are nervous about deleting data on prod, since it can
block the db.
2021-02-23 15:13:53 +00:00
Pea Tyczynska
88233543c3 Add email template for daily letter volumes 2021-02-23 15:13:18 +00:00
Rebecca Law
77b76ea0a4 Rename variable, it's a better name now. 2021-02-17 13:15:29 +00:00
Rebecca Law
e77534fb17 Send text message that are to an international number from a number rather than "Notify"
Update `send_user_2fa_code` to send from number when recipient is international
Update `update_user_attribute` to send from number when recipient is international
2021-02-17 12:14:47 +00:00
David McDonald
35ffb048e5 Bump the migration revision ID by 1
Concourse had passed the tests before someone elses migration had beaten
me to getting merged. So I merged and got an error.

This should fix it
2021-02-10 17:40:56 +00:00
David McDonald
5f58f6c698 Merge pull request #3128 from alphagov/move-provider-restriction
Move provider restriction into broadcast service settings table
2021-02-10 17:32:11 +00:00
Pea Tyczynska
6e1c5a70c0 Make stubbed column on broadcast_message non-nullable
But first set any null values there to False.
2021-02-09 16:33:11 +00:00
David McDonald
b2213dad19 Move provider restriction into broadcast settings
This means we will have a much easier way of knowing what the settings
are for a broadcast service.

Note, we can just move data directly into the newer table as there is
nothing on the API or admin app that is putting data in the
`service_broadcast_provider_restriction` table, this was being done
manually for the few services that needed it.
2021-02-09 15:40:32 +00:00
Pea Tyczynska
bbc8cffb5b No need to alter the columns in services, they are already the right type 2021-02-08 10:45:28 +00:00
Pea Tyczynska
02bc87c096 Add billing details and notes for organisation table 2021-02-05 14:44:42 +00:00
David McDonald
91f5be835a Add DB table for service broadcast settings
This will allow us to store details of which channel a service should be
sending to.

See the comment about how all broadcast services can have a row in the
table but may not at the moment. This has been done for speed as it's
the quickest way to let us set up different services to send to
different channels for some needed testing with the mobile handset
providers in the coming week.
2021-02-01 14:10:37 +00:00
Katie Smith
d7387869c4 Add February 2021 letter rates
All rates are changing, so we add an end date for the current rates and
insert new rates for every post_class, sheet count and crown status.
2021-01-28 14:35:21 +00:00
Pea Tyczynska
a93a35de8d Add 'stubbed' column to broadcast_message table
This is a boolean column. It will be set to True for broadcasts
created from training broadcast accounts.

This will help us debug, for example by excluding all the stubbed
broadcasts when we have some trouble with real broadcasts.
2021-01-27 10:20:43 +00:00
Pea Tyczynska
b3abdfb401 Rename billing contact email and name fields to plural
So:

'billing_contact_email_address' becomes 'billing_contact_email_addresses'
AND
'billing_contact_name' becomes 'billing_contact_names'

This is to signify that each of those fields can contain numerous
items
2021-01-25 17:53:27 +00:00
Pea Tyczynska
e703d1a172 Add billing details fields to Service model and db table
The fields are:
Purchase order number - string field
Billing contact name - text field to acommodate possible multiple
contacts
Billing contact email address - text field to acommodate possible
multiple contacts
Billing reference - string field

All these fields are nullable. Notify platform admins will be
able to check and edit those values in Service Settings
section in Notify interface.

This will help make billing tasks and reports simpler.

Similar fields will also be added to Organisation model and
db table.
2021-01-20 18:00:43 +00:00
Pea Tyczynska
22f2eb7bfe Add notes column to services table 2021-01-18 10:36:51 +00:00
Chris Hill-Scott
fe420448e1 Allow broadcast messages to be created with API key
When we have a public API there will be no human creating the broadcast
message. Instead it will be created by an API integration, authenticated
by a key (just like for emails or texts).

This updates the database to:
- add a new foreign key from BroadcastMessages to API keys
- add a `reference` column

It doesn’t change the model yet, because the model is used by previous
migrations, so would cause them to fail when run before the new columns
exist. We can make this change in later pull requests.
2021-01-15 12:52:24 +00:00
Chris Hill-Scott
8d86d70739 Rewrite previous migration in raw SQL
We shouldn’t import models into migrations because if the model changes
later down the line then the migration can’t be re-run at a later date
(for example to rebuild a database from scratch).

We don’t need to encode the content before storing it (we’ll always do
that before rendering/sending) so we don’t need to use
`BroadcastMessageTemplate`.

And given that no past broadcasts will have personalisation, we don’t
need to replace the personalisation in the template before rendering it.
So we can just copy the raw content from the templates table.
2021-01-15 12:52:24 +00:00
Leo Hemsted
54495b4e14 add content to old broadcast messages with no content
new broadcast messages will have content filled whether they have a
tempalte or not, but old ones won't so populate.

Stole the session constructor from 0044_jos_to_notification_hist.py
2021-01-13 10:09:16 +00:00
Leo Hemsted
91abe6d55f allow null content in migration
because existing rows won't have any content populated yet.
2021-01-11 15:56:11 +00:00
Leo Hemsted
2e929754ff add content to broadcast_message and make template fields nullable
we want to be able to create broadcast messages without templates. To
start with, these will come from the API, but in future we may want to
let people create via the admin interface without creating a template
too.

populate a non-nullable content field with the values supplied via the
template (or supplied directly if via api).
2021-01-08 18:58:17 +00:00
Pea Tyczynska
ac3f56f4ed Delete unneeded code form migration 2020-12-09 12:31:50 +00:00
Pea Tyczynska
2a04148ea1 Add sequential numbering for broadcast messages
We need that to send broadcast messages using proprietary IBAG
format that Vodafone currently uses.
2020-12-07 13:13:10 +00:00
Leo Hemsted
1a083134fa add service broadcast provider restriction table
some services only send to one provider. This is a platform admin
setting to allow us to test integrations and providers manually without
affecting other broadcasts from different services.

one-to-one - a service can either send to all as normal, or send to only
one provider.
2020-12-03 12:38:04 +00:00
Leo Hemsted
2e665de46d add broadcast provider message table to DB
we need to track the state of sending to different provider separately
(and trigger them off separately, refer to references separately, etc)
2020-11-19 15:50:37 +00:00
Chris Hill-Scott
88cd92b946 Revert "Remove the upload letters permission" 2020-10-23 15:14:37 +01:00
Chris Hill-Scott
182bfa7e10 Remove the upload letters permission
As of https://github.com/alphagov/notifications-admin/pull/3690 it’s no
longer referred to.
2020-10-20 11:46:11 +01:00
Leo Hemsted
aac6b16b3c add broadcast org
keep the ID the same as the existing prod broadcast org to keep things
simple.

Move all services with a broadcast permission across to this new
service. Note that we'll need to clear the service and organisation
cache after deploying this
2020-09-23 17:05:17 +01:00
David McDonald
6620590aad Add template for broadcast service invite 2020-09-15 16:47:41 +01:00
Pea Tyczynska
bceb5d8fde Purge broadcast data
To avoid problems after changing data type for areas column from
array to dictionary.
2020-09-07 15:54:30 +01:00
Rebecca Law
59200b241e Add international_letters service permission for all services. 2020-08-13 09:17:18 +01:00
Rebecca Law
180ed86a27 This migration will bring all environments in line with the prod.
There are a few indexes that we still need to drop from prod notification_history. Indexes on prod can take too long to run in a migration so we need to run them manually.
2020-07-30 07:46:51 +01:00
Leo Hemsted
36ae5fadf6 add broadcast_event table
It's clear that we need a way to track updates to a broadcast message.
It's also clear that we'll need some kind of audit log that captures
exactly what was sent out in a message.

This commit adds a new database table, `broadcast_event`, which maps 1:1
with CAP XML sent to the CBCs. We'll create one of these just before
sending out.

The main driver for this was that cancel and update messages need to
contain a list of references of all previous messages that they're
amending. This is of format `{sender},{identifier},{sent_timestamp}`,
and the identifier itself needs to be unique for each message.
2020-07-28 12:10:18 +01:00
Katie Smith
7c12c6c8f0 Fix international letter rate start dates
These were not taking timezones into account before.
2020-07-15 10:23:54 +01:00
Katie Smith
5d47e1cf06 Migration to add international letter rates
New rows giving the prices of letters with a post_class of `europe` and
`rest-of-world` have been added to the `letter_rates` table. All rates
are currently the same for international letters.
2020-07-14 10:22:30 +01:00
Leo Hemsted
3486355354 remove any broadcast templates in downgrade step 2020-07-06 17:43:44 +01:00
Leo Hemsted
5f337f7914 add broadcast_message to database
new broadcast_message table. contains a whole bunch of timestamps, a
couple of user ids for who created and who approved, some
personalisation and a template id/version. areas is a jsonb field - it
is expected that this will be an array, for example `["england",
"wales"]`

intended valid state transitions are as follows, from an initial status
of draft

* draft -> pending-approval, rejected
* pending-approval -> broadcasting, rejected, (draft maybe)
* broadcasting -> completed, cancelled

rejected, completed, cancelled and technical-failure are terminating
states.

also copy across the enum switching code from migration 0060 (adding
letter type).
2020-07-06 16:37:35 +01:00
Leo Hemsted
63f6d8df6b broadcast service permission
it'll eventually be a template type too, so add the _TYPE suffix to the var name to make refactoring easier
2020-06-29 11:53:57 +01:00
Katie Smith
bdde035a0c Drop postage constraints
The constaints on notifications and notification_history have already
been dropped in production, but still exist in staging and in dev
environments.

The constraints on templates and templates_history exist in all
environments.
2020-06-19 15:36:10 +01:00
Katie Smith
0b28766442 Reverts the new postage constraints
Reverts https://github.com/alphagov/notifications-api/pull/2843 and https://github.com/alphagov/notifications-api/pull/2848
2020-05-20 18:31:25 +01:00
Rebecca Law
fa7d2c2c3f Adding a commit at the end of each migration file.
The assumption that a commit is issued in between migration files was false. This will force the db connection to commit, the alter table commands will complete and the alembic version updated.
2020-05-20 16:50:46 +01:00
Katie Smith
7fd52017d0 Update postage db constraints for international letters
The `notifications`, `notification_history`, `templates` and `templates_history`
tables all had a check constraint on the postage column which specified
that the postage had to be `first` or `second` if the notification or
template was a letter. We now have two more options for postage -
`europe` and `rest-of-world`.

It's not possible to alter a check constraint, so the constraints have
to be dropped then recreated. We are not recreating the constraint on
the `notification_history` table since values here are always copied
from the `notifications` table.

The constraints get added as `NOT VALID` at first - this stage will lock
the tables, so updating the `notification` table and `templates` and
`templates_history` are done in separate migrations so that we don't lock
all tables at the same time. In a third migration we then run
`VALIDATE CONSTRAINT` for all tables - this will lock a row at a time,
not the whole table.
2020-05-19 16:04:36 +01:00
Katie Smith
4fd74af3bd Revert "Update postage db constraints for international letters" 2020-04-08 10:53:51 +01:00
Katie Smith
186670e10e Update postage db constraints for international letters
The `notifications`, `notification_history`, `templates` and `templates_history`
tables all had a check constraint on the postage column which specified
that the postage had to be `first` or `second` if the notification or
template was a letter. We now have two more options for postage -
`europe` and `rest-of-world`.

It's not possible to alter a check constraint, so the constraints have
to be dropped then recreated. We are not recreating the constraint on
the `notification_history` table since values here are always copied
from the `notifications` table.

The constraints get added as `NOT VALID` at first - this stage will lock
the tables, so updating the `notification` table and `templates` and
`templates_history` are done in separate migrations so that we don't lock
all tables at the same time. In a third migration we then run
`VALIDATE CONSTRAINT` for all tables - this will lock a row at a time,
not the whole table.
2020-04-07 08:01:11 +01:00
Rebecca Law
5f8ea5d1f5 Remove duplicates 2020-03-31 15:17:27 +01:00
Rebecca Law
7489cda6f0 Optimise indexes
Dropping unnecessary indexes on Notification and Notication_History
Create new composite indexes that should give queries better performance
Drop and create new indexes.

We are not running this migration on production because we want to run each one at a time.
Run this on staging then start run some load tests
2020-03-31 14:12:55 +01:00
Chris Hill-Scott
5fe0fafadf Archive, don’t delete contact lists
So we keep a record of who first uploaded a list it’s better to archive
a list than completely delete it.

The list in the database doesn’t contain any recipient info so this
isn’t a change to what data we’re retaining.

This means updating the endpoints that get contact lists to exclude ones
that are archived.
2020-03-27 09:51:54 +00:00