mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
Update model
- adds email_from field to the service model - adds subject_line to the template model These are unique and not null fields, so there is a migration here for email_from to populate it.
This commit is contained in:
@@ -66,7 +66,7 @@ class Service(db.Model):
|
||||
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
old_id = db.Column(db.Integer, Sequence('services_id_seq'), nullable=False)
|
||||
name = db.Column(db.String(255), nullable=False)
|
||||
name = db.Column(db.String(255), nullable=False, unique=True)
|
||||
created_at = db.Column(
|
||||
db.DateTime,
|
||||
index=False,
|
||||
@@ -86,6 +86,7 @@ class Service(db.Model):
|
||||
secondary=user_to_service,
|
||||
backref=db.backref('user_to_service', lazy='dynamic'))
|
||||
restricted = db.Column(db.Boolean, index=False, unique=False, nullable=False)
|
||||
email_from = db.Column(db.Text, index=False, unique=True, nullable=False)
|
||||
|
||||
|
||||
class ApiKey(db.Model):
|
||||
@@ -127,6 +128,7 @@ class Template(db.Model):
|
||||
content = db.Column(db.Text, index=False, unique=False, nullable=False)
|
||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), index=True, unique=False, nullable=False)
|
||||
service = db.relationship('Service', backref=db.backref('templates', lazy='dynamic'))
|
||||
subject = db.Column(db.Text, index=False, unique=True, nullable=True)
|
||||
|
||||
|
||||
JOB_STATUS_TYPES = ['pending', 'in progress', 'finished']
|
||||
|
||||
26
migrations/versions/0015_add_subject_line.py
Normal file
26
migrations/versions/0015_add_subject_line.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0015_add_subject_line
|
||||
Revises: 0014_job_id_nullable
|
||||
Create Date: 2016-02-18 09:43:29.282804
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0015_add_subject_line'
|
||||
down_revision = '0014_job_id_nullable'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
pass
|
||||
op.add_column('templates', sa.Column('subject', sa.Text(), nullable=True))
|
||||
op.create_unique_constraint(None, 'templates', ['subject'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
pass
|
||||
op.drop_constraint(None, 'templates', type_='unique')
|
||||
op.drop_column('templates', 'subject')
|
||||
23
migrations/versions/0016_add_email_from.py
Normal file
23
migrations/versions/0016_add_email_from.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0016_add_email_from
|
||||
Revises: 0015_add_subject_line
|
||||
Create Date: 2016-02-18 11:25:37.915137
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0016_add_email_from'
|
||||
down_revision = '0015_add_subject_line'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column('services', sa.Column('email_from', sa.Text(), nullable=True))
|
||||
op.execute("UPDATE services SET email_from=name")
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('services', 'email_from')
|
||||
26
migrations/versions/0017_emailfrom_notnull.py
Normal file
26
migrations/versions/0017_emailfrom_notnull.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0017_emailfrom_notnull
|
||||
Revises: 0016_add_email_from
|
||||
Create Date: 2016-02-18 11:41:25.753694
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0017_emailfrom_notnull'
|
||||
down_revision = '0016_add_email_from'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.alter_column('services', 'email_from',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.alter_column('services', 'email_from',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=True)
|
||||
22
migrations/versions/0018_unique_emailfrom.py
Normal file
22
migrations/versions/0018_unique_emailfrom.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0018_unique_emailfrom
|
||||
Revises: 0017_emailfrom_notnull
|
||||
Create Date: 2016-02-18 11:42:18.246280
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0018_unique_emailfrom'
|
||||
down_revision = '0017_emailfrom_notnull'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_unique_constraint(None, 'services', ['email_from'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_constraint(None, 'services', type_='unique')
|
||||
22
migrations/versions/0019_unique_servicename.py
Normal file
22
migrations/versions/0019_unique_servicename.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0019_unique_servicename
|
||||
Revises: 0018_unique_emailfrom
|
||||
Create Date: 2016-02-18 11:45:29.102891
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0019_unique_servicename'
|
||||
down_revision = '0018_unique_emailfrom'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_unique_constraint(None, 'services', ['name'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_constraint(None, 'services', type_='unique')
|
||||
Reference in New Issue
Block a user