Commit Graph

697 Commits

Author SHA1 Message Date
Rebecca Law
12dd58d281 Script to drop the tables. 2017-11-30 16:51:26 +00:00
venusbb
5761d22822 Migration to create new database table service_callback_api 2017-11-28 15:25:15 +00:00
Rebecca Law
5450af661e Merge branch 'master' into add-reply-to-notifications 2017-11-27 10:40:02 +00:00
Leo Hemsted
d30a8b83c1 update readme and ensure makefile up to date 2017-11-23 17:04:58 +00:00
Rebecca Law
df2d3a95ae [WIP] 2017-11-23 14:55:49 +00:00
Rebecca Law
80db78e7a5 Fix merge conflict 2017-11-23 13:46:14 +00:00
Rebecca Law
a19cb66590 Merge branch 'master' into add-reply-to-notifications 2017-11-23 13:45:27 +00:00
Rebecca Law
1378c45ba1 Add a column to Notifications to store the reply_to_text.
This is text value of the sender_id, depending on the channel this will be a SMS sender, email reply to address or a letter contact block.
This is the first PR in a series to refactor how we send the "reply_to" the provider, eventually we can eliminate the notification_to_sms_sender and notification_to_email_to tables.
2017-11-22 14:46:14 +00:00
Alexey Bezhan
0be39cc9f9 Add a migration to add template service_letter_contact_id columns 2017-11-22 14:26:04 +00:00
Rebecca Law
c80bdbaffe Remove email_reply_to and letter_contact_block from Services 2017-11-21 11:06:07 +00:00
Alexey Bezhan
0a50993fc2 Validate notifcations.template_history foreign key constraints
Removes "NOT VALID" mark from the notifications -> template_history
foreign key constraint by validating existing records.

From postgres docs:

> This form validates a foreign key or check constraint that was
> previously created as NOT VALID, by scanning the table to ensure there
> are no rows for which the constraint is not satisfied. Nothing happens
> if the constraint is already marked valid.

> Validation can be a long process on larger tables. The value of
> separating validation from initial creation is that you can defer
> validation to less busy times, or can be used to give additional time
> to correct pre-existing errors while preventing new errors. Note also
> that validation on its own does not prevent normal write commands
> against the table while it runs.

> Validation acquires only a SHARE UPDATE EXCLUSIVE lock on the table
> being altered. If the constraint is a foreign key then a ROW SHARE
> lock is also required on the table referenced by the constraint.
2017-11-20 15:23:27 +00:00
Rebecca Law
93f19956b8 Remove notification_statistics and Service.sms_sender 2017-11-20 13:13:13 +00:00
Chris Hill-Scott
e8a94422e5 Make SMS prefix setting non-nullable
We have now:
- defaulted new services to start with this column set to `true`
- migrated all preexisting services[1] to have either `true` or `false` set
  for this column

There is no way for a service to switch back from `true`/`false` to
`null`.

This means that we can safely enforce a non-nullable constraint on this
column now.

1. There is a little gotcha: the GOV.UK Notify service still relies on
   the `sms_sender` column. It doesn’t have a row in the
   `service_sms_senders` table. This means the previous migration
   never changed this service’s value for `prefix_sms` from `null`. So
   this commit also changes its value to `False`, so that the rest of
   the migration, of the whole column, is possible.
2017-11-16 14:29:32 +00:00
venusbb
7ac0346961 change migration version 2017-11-16 13:44:55 +00:00
Venus Bailey
bb0c8090c5 Merge pull request #1389 from alphagov/vb-sms-allowance-data-migration
migrate data from service table to annual billing
2017-11-16 13:16:15 +00:00
Rebecca Law
9fa59c9407 Fix merge conflict 2017-11-15 12:42:49 +00:00
Rebecca Law
fd217e67f5 Merge branch 'master' into remove-initial-update-sms-sender 2017-11-15 12:33:38 +00:00
venusbb
e903257156 version change because of other commits 2017-11-15 11:25:27 +00:00
Alexey Bezhan
d2a220a418 Fix migration numbers after #1383 2017-11-15 11:03:55 +00:00
Rebecca Law
45bf7e1938 Fix db migration merge conflict
Update create_service_with_inbound_number
2017-11-15 11:00:56 +00:00
venusbb
fcfea6844d Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-sms-allowance-data-migration 2017-11-15 10:54:22 +00:00
Alexey Bezhan
bc54d34a22 Merge pull request #1384 from alphagov/notifications-template-history
Fix notifications template history relationship
2017-11-15 10:51:56 +00:00
Rebecca Law
e3f9dab884 Merge branch 'master' into remove-initial-update-sms-sender 2017-11-14 16:27:10 +00:00
venusbb
7c0c2a9a0f migrate data from service table to annual billing 2017-11-14 09:43:28 +00:00
Alexey Bezhan
9d4b8961cb Add a migration to replace notifications_template foreign key
Removes notifications.template_id foreign key and replaces it with
a composite foreign key constraint to TemplateHistory using the
existing notification columns for template ID and template version.

Foreign key constraint is created as NOT VALID to avoid locking the
notifications table while postgres verifies that existing records
don't break the constraint. From postgres docs:

> If the constraint is marked NOT VALID, the potentially-lengthy initial
> check to verify that all rows in the table satisfy the constraint is
> skipped. The constraint will still be enforced against subsequent
> inserts or updates (that is, they'll fail unless there is a matching
> row in the referenced table, in the case of foreign keys; and they'll
> fail unless the new row matches the specified check constraints). But
> the database will not assume that the constraint holds for all rows
> in the table, until it is validated by using the VALIDATE CONSTRAINT
> option.

VALIDATE CONSTRAINT will be issued as a separate migration in a
follow-up PR.
2017-11-10 15:13:55 +00:00
Leo Hemsted
15bf888624 make user mobile num nullable if user has email_auth enabled 2017-11-09 19:07:44 +00:00
Richard Chapman
b78d989d4e Updates after review
- Modified the services_dao to return an int instead of a datetime to
make usage easier and removed the BST function on year as it is not
relevant for year
- Improved tests do there is less logic by ordering the result so there
is less reliance on the template id
- Renamed variable in stats_template_usage_by_month_dao.py to make it
consistent with the method
2017-11-09 14:13:42 +00:00
Rebecca Law
3713cc2353 Merge branch 'master' into remove-initial-update-sms-sender 2017-11-09 11:53:29 +00:00
Richard Chapman
98b762869d Renamed database migration file after merge
Updated the database migration file name after a rebase as there were
two 0134 files and this would break the upgrade / downgrade process.
2017-11-09 10:41:43 +00:00
Richard Chapman
ab43803453 Removed unwanted migration commands
There were some unwanted db migration commands which crept into the
migration file. removed these as they are being handled in other PRs.
2017-11-09 10:34:49 +00:00
Richard Chapman
26617a921e Added database migration file
Currently the 'See templates used by month' report is timing out for
some services due to the query time of the data from notification_history
This is a stats table which will hold the data and will be updated by a
scheduled celery task once a day. This data will be combined with the
'live' data from notifications tables (which will be considerably less)
to form the data of the new report.
2017-11-09 10:34:49 +00:00
Leo Hemsted
57b7a392b2 add email 2fa template 2017-11-07 16:47:20 +00:00
Rebecca Law
0054361044 Refactor the sms sender code to remove any unused methods.
Refactor tests/db/create_service() to behave more like the real world.
Created new create_service_with_inbound_number and create_service_with_defined_sms_sender() test/db methods.
2017-11-07 14:26:18 +00:00
Chris Hill-Scott
97db65bc9e Migrate prefix SMS setting to be true or false
We want services to have control over this setting, rather than deriving
it from the value of their sender. This commit does that derivation one
last time, and stores it in the column, where it can be changed as and
when needed.
2017-11-07 10:47:13 +00:00
Chris Hill-Scott
cccffdd2ac Add a column for a service to set SMS prefixing
In future changes, services will be able to control whether their text
messages will be prefixed with the name of their service.

This commit:
- adds a column to store the value of that setting
- makes the service model take notice of it, if it were to have a value
  set

It doesn’t:
- provide a way of setting the value of this column

Currently the column can have three values:
- `None` – ignore it (this is what all current services will start as)
  and continue to determine whether to prefix messages by looking at the
  sender
- `True` – always the service name to the start of text messages
- `False` – never add the service name to the start of text messages

In the future we’ll migrate all services to be either `True` or `False`,
the `None` will go away and all services will have direct control over
the setting.
2017-11-03 12:53:06 +00:00
Leo Hemsted
0ab89116ee use server_default in alembic to ensure zero-downtimeness
we can back-fill data, however, between alembic running and the api
updating to the new code, it'll still try and create new users without
adding the auth_type, because that won't be referenced in the model yet.

Instead of using a python-level default, a postgres-level
server_default will make postgres set every row to sms_auth if it's not
defined in the application.
2017-10-30 11:59:35 +00:00
Leo Hemsted
c39ec90727 add auth type table, currently contains sms_auth and email_auth 2017-10-30 11:11:37 +00:00
Ken Tsang
8a4c8802ef Add notification email reply_to script 2017-10-27 15:11:35 +01:00
Leo Hemsted
46f5896b3b add new email_auth service permission 2017-10-27 14:28:20 +01:00
Rebecca Law
b048b2c3bf DB update script for new table 2017-10-26 16:40:38 +01:00
Rebecca Law
d975f30888 Fix merge conflict 2017-10-19 14:39:53 +01:00
Rebecca Law
954a80649e Merge branch 'master' into add-update-multiple-sms-sender 2017-10-19 14:34:58 +01:00
venusbb
7e78e19500 Unique constrain and db.relationship 2017-10-19 12:00:01 +01:00
venusbb
b2fa7cdd83 create new table annual_billing 2017-10-18 15:35:51 +01:00
Rebecca Law
4ca6fbc724 Added dao methods needed to add or update multiple sms senders for a service.
Remove the unique constraint for service on the ServiceSmsSender model.
2017-10-18 13:13:23 +01:00
Rebecca Law
1a463cba1f Merge branch 'master' into add-update-multiple-sms-sender 2017-10-18 11:18:44 +01:00
Chris Hill-Scott
2a5e6c2d0c Store organisation type against each service
> So that we can default services to their appropriate text allowance,
> we need to find out what sector they're in. So let's start collecting
> that from teams as they create new services.

In order to work out what a team’s allowance should be, we need to know
what part of government they’re from. We’re going to do this logic in
the admin app and then `POST` the allowance to the API.

So all we need to do with the information that the users give us is
store it against the service, so we have a record. Doesn’t need any
logic doing as a result of it, doesn’t need foreign keying to the
organisations table, etc.
2017-10-18 10:49:31 +01:00
Rebecca Law
edba490c72 Remove unique constraint for ServiceSmsSenders.
This will allow a service to have multiple sms senders.
2017-10-17 16:53:13 +01:00
Venus Bailey
9b60d69931 Revert "Revert "[#151837054] Add new column free_sms_fragment_limit in the Services table"" 2017-10-16 16:24:34 +01:00
Venus Bailey
616a6f8ef8 Revert "[#151837054] Add new column free_sms_fragment_limit in the Services table" 2017-10-16 12:43:05 +01:00