Skip to content

Instantly share code, notes, and snippets.

/-

Created April 8, 2014 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/10081234 to your computer and use it in GitHub Desktop.
Save anonymous/10081234 to your computer and use it in GitHub Desktop.
from sqlalchemy import Column, Index, Sequence, func
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.types import Integer, String
from st.orm.models.base import Base
from st.orm.models.mixins import RefBankCustomerMixin
class User(Base, RefBankCustomerMixin):
__tablename__ = 'st_user'
id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
username = Column('username', String(20), unique=True, index=True)
password = Column('password', String(60))
@declared_attr
def __table_args__(cls):
return (
# TODO: alembic should use this index to create a unique constraint on
# LOWER(username), but as of Alembic 0.6.4 & SQLAlchemy 0.9.4 this is broken
Index("ix_user_username_lower", func.lower(cls.username), unique=True),
)
"""
@nolint
empty message
Revision ID: 91c51d09f50
Revises: 3fe255b43218
Create Date: 2014-04-07 18:33:06.755461
"""
# revision identifiers, used by Alembic.
revision = '91c51d09f50'
down_revision = '3fe255b43218'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table('st_user',
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.Column('deleted_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(length=20), nullable=True),
sa.Column('password', sa.String(length=60), nullable=True),
sa.Column('bank_customer_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['bank_customer_id'], ['bank_customer.id'], initially='IMMEDIATE', deferrable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_st_user_username'), 'st_user', ['username'], unique=True)
op.create_index('ix_user_username_lower', 'st_user', ['lower'], unique=True)
def downgrade():
op.drop_index('ix_user_username_lower', table_name='st_user')
op.drop_index(op.f('ix_st_user_username'), table_name='st_user')
op.drop_table('st_user')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment