fixing model and migration
This commit is contained in:
parent
bae5a1d2b1
commit
b3d77ba212
|
@ -21,6 +21,7 @@ revision = '21afd375a654'
|
||||||
down_revision = '6a2a939d5668'
|
down_revision = '6a2a939d5668'
|
||||||
branch_labels = None
|
branch_labels = None
|
||||||
depends_on = None
|
depends_on = None
|
||||||
|
comment_update = 'The last time Devicehub recorded a change for this thing.\n'
|
||||||
|
|
||||||
|
|
||||||
def get_inv():
|
def get_inv():
|
||||||
|
@ -29,10 +30,16 @@ def get_inv():
|
||||||
raise ValueError("Inventory value is not specified")
|
raise ValueError("Inventory value is not specified")
|
||||||
return INV
|
return INV
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
op.create_table('session',
|
op.create_table('session',
|
||||||
sa.Column('updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='The last time Devicehub recorded a change for \n this thing.\n '),
|
sa.Column('updated', sa.TIMESTAMP(timezone=True),
|
||||||
sa.Column('created', sa.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='When Devicehub created this.'),
|
server_default=sa.text('CURRENT_TIMESTAMP'),
|
||||||
|
nullable=False,
|
||||||
|
comment=comment_update),
|
||||||
|
sa.Column('created', sa.TIMESTAMP(timezone=True),
|
||||||
|
server_default=sa.text('CURRENT_TIMESTAMP'),
|
||||||
|
nullable=False, comment='When Devicehub created this.'),
|
||||||
sa.Column('id', sa.BigInteger(), nullable=False),
|
sa.Column('id', sa.BigInteger(), nullable=False),
|
||||||
sa.Column('expired', sa.BigInteger(), nullable=True),
|
sa.Column('expired', sa.BigInteger(), nullable=True),
|
||||||
sa.Column('token', postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column('token', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
@ -45,9 +52,11 @@ def upgrade():
|
||||||
)
|
)
|
||||||
op.create_index(op.f('ix_session_created'), 'session', ['created'], unique=False, schema='common')
|
op.create_index(op.f('ix_session_created'), 'session', ['created'], unique=False, schema='common')
|
||||||
op.create_index(op.f('ix_session_updated'), 'session', ['updated'], unique=False, schema='common')
|
op.create_index(op.f('ix_session_updated'), 'session', ['updated'], unique=False, schema='common')
|
||||||
|
op.create_index(op.f('ix_session_token'), 'session', ['token'], unique=True, schema='common')
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.drop_table('trade', schema=f'{get_inv()}')
|
op.drop_table('trade', schema=f'{get_inv()}')
|
||||||
op.drop_index(op.f('ix_session_created'), table_name='session', schema='common')
|
op.drop_index(op.f('ix_session_created'), table_name='session', schema='common')
|
||||||
op.drop_index(op.f('ix_session_updated'), table_name='session', schema='common')
|
op.drop_index(op.f('ix_session_updated'), table_name='session', schema='common')
|
||||||
|
op.drop_index(op.f('ix_session_token'), table_name='session', schema='common')
|
||||||
|
|
|
@ -67,3 +67,9 @@ class Session(Thing):
|
||||||
token = Column(UUID(as_uuid=True), default=uuid4, unique=True, nullable=False)
|
token = Column(UUID(as_uuid=True), default=uuid4, unique=True, nullable=False)
|
||||||
type = Column(IntEnum(SessionType), default=SessionType.Internal, nullable=False)
|
type = Column(IntEnum(SessionType), default=SessionType.Internal, nullable=False)
|
||||||
user_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey(User.id))
|
user_id = db.Column(db.UUID(as_uuid=True), db.ForeignKey(User.id))
|
||||||
|
user = db.relationship(User,
|
||||||
|
backref=db.backref('sessions', lazy=True, collection_class=set),
|
||||||
|
collection_class=set)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return '{0.token}'.format(self)
|
||||||
|
|
Reference in New Issue