mirror of
https://github.com/GSA/notifications-api.git
synced 2026-04-20 01:09:56 -04:00
Unique constrain and db.relationship
This commit is contained in:
@@ -179,6 +179,26 @@ class ServicePermissionTypes(db.Model):
|
||||
name = db.Column(db.String(255), primary_key=True)
|
||||
|
||||
|
||||
class AnnualBilling(db.Model):
|
||||
__tablename__ = "annual_billing"
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, unique=False)
|
||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), unique=False, index=True, nullable=False)
|
||||
financial_year_start = db.Column(db.Integer, nullable=False, default=True, unique=False)
|
||||
free_sms_fragment_limit = db.Column(db.Integer, nullable=False, index=False, unique=False)
|
||||
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
||||
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
'id': str(self.id),
|
||||
'service_id': str(self.service_id),
|
||||
'free_sms_fragment_limit': str(self.free_sms_fragment_limit),
|
||||
'financial_year_start': str(self.financial_year_start),
|
||||
'created_at': self.created_at.strftime(DATETIME_FORMAT),
|
||||
'updated_at': self.updated_at.strftime(DATETIME_FORMAT) if self.updated_at else None
|
||||
}
|
||||
|
||||
|
||||
class Service(db.Model, Versioned):
|
||||
__tablename__ = 'services'
|
||||
|
||||
@@ -213,6 +233,7 @@ class Service(db.Model, Versioned):
|
||||
organisation_id = db.Column(UUID(as_uuid=True), db.ForeignKey('organisation.id'), index=True, nullable=True)
|
||||
free_sms_fragment_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=True)
|
||||
organisation = db.relationship('Organisation')
|
||||
annual_billing = db.relationship('AnnualBilling')
|
||||
dvla_organisation_id = db.Column(
|
||||
db.String,
|
||||
db.ForeignKey('dvla_organisation.id'),
|
||||
@@ -1462,23 +1483,3 @@ class NotificationEmailReplyTo(db.Model):
|
||||
nullable=False,
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
|
||||
class AnnualBilling(db.Model):
|
||||
__tablename__ = "annual_billing"
|
||||
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
service_id = db.Column(UUID(as_uuid=True), db.ForeignKey('services.id'), unique=False, index=True, nullable=False)
|
||||
financial_year_start = db.Column(db.Integer, nullable=False, default=True)
|
||||
free_sms_fragment_limit = db.Column(db.Integer, nullable=False, index=False, unique=False)
|
||||
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
|
||||
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
'id': str(self.id),
|
||||
'service_id': str(self.service_id),
|
||||
'free_sms_fragment_limit': str(self.free_sms_fragment_limit),
|
||||
'financial_year_start': str(self.financial_year_start),
|
||||
'created_at': self.created_at.strftime(DATETIME_FORMAT),
|
||||
'updated_at': self.updated_at.strftime(DATETIME_FORMAT) if self.updated_at else None
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Revision ID: 0126_add_annual_billing
|
||||
Revises: 0125_add_organisation_type
|
||||
Create Date: 2017-10-18 11:42:54.261575
|
||||
Create Date: 2017-10-19 11:38:32.849573
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
@@ -19,11 +19,15 @@ def upgrade():
|
||||
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('financial_year_start', sa.Integer(), nullable=False),
|
||||
sa.Column('free_sms_fragment_limit', sa.Integer(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'))
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_annual_billing_service_id'), 'annual_billing', ['service_id'], unique=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_index(op.f('ix_annual_billing_service_id'), table_name='annual_billing')
|
||||
op.drop_table('annual_billing')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user