Add unique constraints on some of our tables
I just missed thinking about this originally
This commit is contained in:
parent
9eef6c9754
commit
63a22e27e0
|
@ -0,0 +1,28 @@
|
||||||
|
"""add unique constraints
|
||||||
|
|
||||||
|
Revision ID: 4990a9f1ada3
|
||||||
|
Revises: 688af5ecd407
|
||||||
|
Create Date: 2016-05-18 15:40:33.511871
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '4990a9f1ada3'
|
||||||
|
down_revision = '688af5ecd407'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.create_unique_constraint('uq_credit_card_id', 'credit_card', ['card_id'])
|
||||||
|
op.create_unique_constraint('uq_ofxsource_fid', 'ofxsource', ['fid'])
|
||||||
|
op.create_unique_constraint('uq_user_username', 'users', ['username'])
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_constraint('uq_user_username', 'users', type_='unique')
|
||||||
|
op.drop_constraint('uq_ofxsource_fid', 'ofxsource', type_='unique')
|
||||||
|
op.drop_constraint('uq_credit_card_id', 'credit_card', type_='unique')
|
|
@ -1,6 +1,6 @@
|
||||||
import chryso.constants
|
import chryso.constants
|
||||||
from sqlalchemy import (Column, Date, DateTime, Float, ForeignKey, Integer,
|
from sqlalchemy import (Column, Date, DateTime, Float, ForeignKey, Integer,
|
||||||
MetaData, String, Table, func)
|
MetaData, String, Table, UniqueConstraint, func)
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
|
|
||||||
metadata = MetaData(naming_convention=chryso.constants.CONVENTION)
|
metadata = MetaData(naming_convention=chryso.constants.CONVENTION)
|
||||||
|
@ -14,6 +14,7 @@ User = Table('users', metadata,
|
||||||
Column('created_at', DateTime, nullable=False, server_default=func.now()),
|
Column('created_at', DateTime, nullable=False, server_default=func.now()),
|
||||||
Column('updated_at', DateTime, nullable=False, server_default=func.now(), onupdate=func.now()),
|
Column('updated_at', DateTime, nullable=False, server_default=func.now(), onupdate=func.now()),
|
||||||
Column('deleted_at', DateTime, nullable=True),
|
Column('deleted_at', DateTime, nullable=True),
|
||||||
|
UniqueConstraint('username', name='uq_user_username'),
|
||||||
)
|
)
|
||||||
|
|
||||||
CreditCard = Table('credit_card', metadata,
|
CreditCard = Table('credit_card', metadata,
|
||||||
|
@ -30,15 +31,17 @@ CreditCard = Table('credit_card', metadata,
|
||||||
Column('created', DateTime(), nullable=False, server_default=func.now()),
|
Column('created', DateTime(), nullable=False, server_default=func.now()),
|
||||||
Column('updated', DateTime(), nullable=False, server_default=func.now(), onupdate=func.now()),
|
Column('updated', DateTime(), nullable=False, server_default=func.now(), onupdate=func.now()),
|
||||||
Column('deleted', DateTime(), nullable=True),
|
Column('deleted', DateTime(), nullable=True),
|
||||||
|
UniqueConstraint('card_id', name='uq_credit_card_id'),
|
||||||
)
|
)
|
||||||
|
|
||||||
OFXSource = Table('ofxsource', metadata,
|
OFXSource = Table('ofxsource', metadata,
|
||||||
Column('uuid', UUID(as_uuid=True), primary_key=True),
|
Column('uuid', UUID(as_uuid=True), primary_key=True),
|
||||||
Column('name', String(255), nullable=False), # The name of the institution such as 'America First Credit Union'
|
Column('name', String(255), nullable=False), # The name of the institution such as 'America First Credit Union'
|
||||||
Column('fid', String(255), nullable=False), # The FID of the institution, such as 54324
|
Column('fid', String(255), nullable=False), # The FID of the institution, such as 54324
|
||||||
Column('bankid', String(255), nullable=False), # The bank ID of the institution such as 324377516
|
Column('bankid', String(255), nullable=False), # The bank ID of the institution such as 324377516. This may be a routing number
|
||||||
Column('created', DateTime(), nullable=False, server_default=func.now()),
|
Column('created', DateTime(), nullable=False, server_default=func.now()),
|
||||||
Column('updated', DateTime(), nullable=False, server_default=func.now(), onupdate=func.now()),
|
Column('updated', DateTime(), nullable=False, server_default=func.now(), onupdate=func.now()),
|
||||||
|
UniqueConstraint('fid', name='uq_ofxsource_fid'),
|
||||||
)
|
)
|
||||||
|
|
||||||
OFXAccount = Table('ofxaccount', metadata,
|
OFXAccount = Table('ofxaccount', metadata,
|
||||||
|
|
Loading…
Reference in New Issue