diff --git a/mci_database/db/migrations/versions/f1f3df877341_.py b/mci_database/db/migrations/versions/f1f3df877341_.py new file mode 100644 index 0000000..9ae67dc --- /dev/null +++ b/mci_database/db/migrations/versions/f1f3df877341_.py @@ -0,0 +1,25 @@ +"""Add county field to Address. + +Revision ID: f1f3df877341 +Revises: 08dad05889a9 +Create Date: 2020-11-09 09:52:20.889107 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'f1f3df877341' +down_revision = '08dad05889a9' +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column('address', sa.Column( + 'county', sa.String(length=125), nullable=True)) + + +def downgrade(): + op.drop_column('address', 'county') diff --git a/mci_database/db/models/models.py b/mci_database/db/models/models.py index dbf7a4f..7dc637d 100644 --- a/mci_database/db/models/models.py +++ b/mci_database/db/models/models.py @@ -21,6 +21,8 @@ class Address(db.Model): postal_code (str): The postal code of the location. + county (str): The US county associated with the location. + country (str): The two digit country code where the location exists. """ @@ -29,13 +31,15 @@ class Address(db.Model): city = db.Column(db.String(100)) state = db.Column(db.String(20)) postal_code = db.Column(db.String(20)) + county = db.Column(db.String(125)) country = db.Column(db.String(2)) - def __init__(self, address=None, city=None, state=None, postal_code=None, country=None): + def __init__(self, address=None, city=None, state=None, postal_code=None, county=None, country=None): self.address = address self.city = city self.state = state self.postal_code = postal_code + self.county = county self.country = country @@ -219,8 +223,8 @@ def as_dict(self): Represent the Individual as a dict that uses empty strings for None values. ''' dict_repr = {column.name: getattr(self, column.name) - for column in self.__table__.columns} - + for column in self.__table__.columns} + for k, v in dict_repr.items(): if v is None: dict_repr[k] = "" @@ -229,6 +233,7 @@ def as_dict(self): return dict_repr + class IndividualDisposition(db.Model): individual_id = db.Column(db.String(40), db.ForeignKey( Individual.mci_id, ondelete='CASCADE'), nullable=False, primary_key=True) @@ -249,7 +254,7 @@ class IndividualPIIRemoval(db.Model): removal_timestamp = db.Column( db.DateTime, server_default=db.func.now(), nullable=False) comment = db.Column(db.String(500)) - + class Referral(db.Model): """An individual's referral.