Storing more info about an organisation

Currently we have
- a thing in the database called an ‘organisation’ which we don’t use
- the idea of an organisation which we derive from the user’s email
  address and is used to set the default branding for their service and
  determine whether they’ve signed the MOU

We should make these two things into one thing, by storing everything
we know about an organisation against that organisation in the database.
This will be much less laborious than storing it in a YAML file that
needs a deploy every time it’s updated.

An organisation can now have:
- domains which we can use to automatically associate services with it
  (eg anyone whose email address ends in `dwp.gsi.gov.uk` gets services
  they create associated to the DWP organisation)
- default letter branding for any new services
- default email branding for any new services
This commit is contained in:
Chris Hill-Scott
2019-02-19 11:47:30 +00:00
parent 46abcfd96d
commit d7e03e00d3
5 changed files with 221 additions and 13 deletions

View File

@@ -0,0 +1,57 @@
"""
Revision ID: 0278_add_more_stuff_to_orgs
Revises: 0277_consent_to_research_null
Create Date: 2019-02-26 10:15:22.430340
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0278_add_more_stuff_to_orgs'
down_revision = '0277_consent_to_research_null'
def upgrade():
op.create_table(
'domain',
sa.Column('domain', sa.String(length=255), nullable=False),
sa.Column('organisation_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.ForeignKeyConstraint(['organisation_id'], ['organisation.id'], ),
sa.PrimaryKeyConstraint('domain')
)
op.create_index(op.f('ix_domain_domain'), 'domain', ['domain'], unique=True)
op.add_column('organisation', sa.Column('email_branding_id', postgresql.UUID(as_uuid=True), nullable=True))
op.create_foreign_key('fk_organisation_email_branding_id', 'organisation', 'email_branding', ['email_branding_id'], ['id'])
op.add_column('organisation', sa.Column('letter_branding_id', postgresql.UUID(as_uuid=True), nullable=True))
op.create_foreign_key('fk_organisation_letter_branding_id', 'organisation', 'letter_branding', ['letter_branding_id'], ['id'])
op.add_column('organisation', sa.Column('agreement_signed', sa.Boolean(), nullable=True))
op.add_column('organisation', sa.Column('agreement_signed_at', sa.DateTime(), nullable=True))
op.add_column('organisation', sa.Column('agreement_signed_by_id', postgresql.UUID(as_uuid=True), nullable=True))
op.add_column('organisation', sa.Column('agreement_signed_version', sa.Float(), nullable=True))
op.add_column('organisation', sa.Column('crown', sa.Boolean(), nullable=True))
op.add_column('organisation', sa.Column('organisation_type', sa.String(length=255), nullable=True))
op.create_foreign_key('fk_organisation_agreement_user_id', 'organisation', 'users', ['agreement_signed_by_id'], ['id'])
def downgrade():
op.drop_constraint('fk_organisation_agreement_user_id', 'organisation', type_='foreignkey')
op.drop_column('organisation', 'organisation_type')
op.drop_column('organisation', 'crown')
op.drop_column('organisation', 'agreement_signed_version')
op.drop_column('organisation', 'agreement_signed_by_id')
op.drop_column('organisation', 'agreement_signed_at')
op.drop_column('organisation', 'agreement_signed')
op.drop_column('organisation', 'email_branding_id')
op.drop_constraint('fk_organisation_email_branding_id', 'organisation', type_='foreignkey')
op.drop_column('organisation', 'letter_branding_id')
op.drop_constraint('fk_organisation_letter_branding_id', 'organisation', type_='foreignkey')
op.drop_index(op.f('ix_domain_domain'), table_name='domain')
op.drop_table('domain')