Migrate all orgs and services onto new organisation types

Remove all mentions of generic 'nhs' organisation type.
This commit is contained in:
Pea Tyczynska
2019-07-19 14:51:06 +01:00
parent da61bb3b06
commit 5b256fa64e
5 changed files with 122 additions and 7 deletions

View File

@@ -309,7 +309,7 @@ def dao_create_service(
if organisation.letter_branding and not service.letter_branding: if organisation.letter_branding and not service.letter_branding:
service.letter_branding = organisation.letter_branding service.letter_branding = organisation.letter_branding
elif service.organisation_type == 'nhs' or email_address_is_nhs(user.email_address): elif service.organisation_type in ['nhs_central', 'nhs_local'] or email_address_is_nhs(user.email_address):
service.email_branding = dao_get_email_branding_by_name('NHS') service.email_branding = dao_get_email_branding_by_name('NHS')
service.letter_branding = dao_get_letter_branding_by_name('NHS') service.letter_branding = dao_get_letter_branding_by_name('NHS')

View File

@@ -325,12 +325,11 @@ class Domain(db.Model):
ORGANISATION_TYPES = [ ORGANISATION_TYPES = [
"central", "local", "nhs_central", "nhs", "central", "local", "nhs_central", "nhs_local", "emergency_service", "school_or_college", "other",
"nhs_local", "emergency_service", "school_or_college", "other",
] ]
CROWN_ORGANISATION_TYPES = ["nhs_central"] CROWN_ORGANISATION_TYPES = ["nhs_central"]
NON_CROWN_ORGANISATION_TYPES = ["local", "nhs_local", "emergency_service", "school_or_college", "nhs"] NON_CROWN_ORGANISATION_TYPES = ["local", "nhs_local", "emergency_service", "school_or_college"]
class OrganisationTypes(db.Model): class OrganisationTypes(db.Model):

View File

@@ -0,0 +1,116 @@
"""
Revision ID: 0300_migrate_org_types
Revises: 0299_org_types_table
Create Date: 2019-07-19 11:13:41.286472
"""
from alembic import op
revision = '0300_migrate_org_types'
down_revision = '0299_org_types_table'
def upgrade():
op.execute("""
UPDATE
organisation
SET
organisation_type = 'nhs_local'
FROM
organisation_to_service, annual_billing
WHERE
organisation.organisation_type = 'nhs'
AND
annual_billing.service_id = organisation_to_service.service_id
AND
organisation_to_service.organisation_id = organisation.id
AND
annual_billing.free_sms_fragment_limit = 25000
""")
op.execute("""
UPDATE
services
SET
organisation_type = 'nhs_local'
FROM
annual_billing
WHERE
services.organisation_type = 'nhs'
AND
annual_billing.service_id = services.id
AND
annual_billing.free_sms_fragment_limit = 25000
""")
op.execute("""
UPDATE
organisation
SET
organisation_type = 'nhs_central'
FROM
organisation_to_service, annual_billing
WHERE
organisation.organisation_type = 'nhs'
AND
annual_billing.service_id = organisation_to_service.service_id
AND
organisation_to_service.organisation_id = organisation.id
AND
annual_billing.free_sms_fragment_limit = 250000
""")
op.execute("""
UPDATE
services
SET
organisation_type = 'nhs_central'
FROM
annual_billing
WHERE
services.organisation_type = 'nhs'
AND
annual_billing.service_id = services.id
AND
annual_billing.free_sms_fragment_limit = 250000
""")
def downgrade():
op.execute("""
UPDATE
organisation
SET
organisation_type = 'nhs'
WHERE
organisation_type = 'nhs_central'
""")
op.execute("""
UPDATE
services
SET
organisation_type = 'nhs'
WHERE
organisation_type = 'nhs_central'
""")
op.execute("""
UPDATE
organisation
SET
organisation_type = 'nhs'
WHERE
organisation_type = 'nhs_local'
""")
op.execute("""
UPDATE
services
SET
organisation_type = 'nhs'
WHERE
organisation_type = 'nhs_local'
""")

View File

@@ -110,8 +110,8 @@ def test_create_service(notify_db_session):
@pytest.mark.parametrize('email_address, organisation_type', ( @pytest.mark.parametrize('email_address, organisation_type', (
("test@example.gov.uk", 'nhs'), ("test@example.gov.uk", 'nhs_central'),
("test@nhs.net", 'nhs'), ("test@nhs.net", 'nhs_local'),
("test@nhs.net", 'local'), ("test@nhs.net", 'local'),
("test@nhs.net", 'central'), ("test@nhs.net", 'central'),
("test@nhs.uk", 'central'), ("test@nhs.uk", 'central'),

View File

@@ -204,7 +204,7 @@ def test_post_create_organisation_existing_name_raises_400(admin_request, sample
'name': 'Service name', 'name': 'Service name',
'crown': False, 'crown': False,
'organisation_type': 'foo', 'organisation_type': 'foo',
}, 'organisation_type foo is not one of [central, local, nhs_central, nhs, nhs_local, emergency_service, school_or_college, other]'), # noqa }, 'organisation_type foo is not one of [central, local, nhs_central, nhs_local, emergency_service, school_or_college, other]'), # noqa
)) ))
def test_post_create_organisation_with_missing_data_gives_validation_error( def test_post_create_organisation_with_missing_data_gives_validation_error(
admin_request, admin_request,