Added constraints to services.postage: not nullable and can only containt "first" or "second"

This commit is contained in:
Rebecca Law
2018-09-18 17:41:25 +01:00
parent 29a666302e
commit 5f73dfdbe9
4 changed files with 48 additions and 13 deletions

View File

@@ -167,7 +167,6 @@ def dao_create_service(service, user, service_id=None, service_permissions=None)
service.active = True
service.research_mode = False
service.crown = service.organisation_type == 'central'
service.postage = 'second'
for permission in service_permissions:
service_permission = ServicePermission(service_id=service.id, permission=permission)
@@ -181,7 +180,6 @@ def dao_create_service(service, user, service_id=None, service_permissions=None)
@transactional
@version_class(Service)
def dao_update_service(service):
service.postage = service.postage or 'second'
db.session.add(service)

View File

@@ -353,7 +353,9 @@ class Service(db.Model, Versioned):
crown = db.Column(db.Boolean, index=False, nullable=False, default=True)
rate_limit = db.Column(db.Integer, index=False, nullable=False, default=3000)
contact_link = db.Column(db.String(255), nullable=True, unique=False)
postage = db.Column(db.String(255), index=False, nullable=True)
postage = db.Column(db.String(255), index=False, nullable=False, default='second')
CheckConstraint("'postage' in ('first', 'second')")
organisation = db.relationship(
'Organisation',