From d40d520d2cc76c3e397f8017815e1b10210035d3 Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Wed, 7 Feb 2018 14:14:02 +0000 Subject: [PATCH] Add Organisation model and migration Now that we have renamed the 'old' organisation model to email_branding, we can create a new organisation model. --- app/models.py | 9 +++++ migrations/versions/0163_add_new_org_model.py | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 migrations/versions/0163_add_new_org_model.py diff --git a/app/models.py b/app/models.py index 580626b4b..6dbc64cd5 100644 --- a/app/models.py +++ b/app/models.py @@ -303,6 +303,15 @@ class Service(db.Model, Versioned): return permission in [p.permission for p in self.permissions] +class Organisation(db.Model): + __tablename__ = "organisation" + id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, unique=False) + name = db.Column(db.String(255), nullable=False, unique=True, index=True) + active = db.Column(db.Boolean, nullable=False, default=True) + created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) + updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow) + + class AnnualBilling(db.Model): __tablename__ = "annual_billing" id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, unique=False) diff --git a/migrations/versions/0163_add_new_org_model.py b/migrations/versions/0163_add_new_org_model.py new file mode 100644 index 000000000..da2232011 --- /dev/null +++ b/migrations/versions/0163_add_new_org_model.py @@ -0,0 +1,34 @@ +""" + +Revision ID: 0163_add_new_org_model +Revises: 0162_remove_org +Create Date: 2018-02-07 14:03:00.804849 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +revision = '0163_add_new_org_model' +down_revision = '0162_remove_org' + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('organisation', + sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('active', sa.Boolean(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_organisation_name'), 'organisation', ['name'], unique=True) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_organisation_name'), table_name='organisation') + op.drop_table('organisation') + # ### end Alembic commands ###