Add timestamps to workspace
This commit is contained in:
parent
c723c9b326
commit
01778ada05
30
alembic/versions/a2b499a1dd62_workspace_timestamps.py
Normal file
30
alembic/versions/a2b499a1dd62_workspace_timestamps.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""workspace timestamps
|
||||
|
||||
Revision ID: a2b499a1dd62
|
||||
Revises: f549c7cee17c
|
||||
Create Date: 2018-08-17 10:43:13.165829
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'a2b499a1dd62'
|
||||
down_revision = 'f549c7cee17c'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('workspaces', sa.Column('time_created', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False))
|
||||
op.add_column('workspaces', sa.Column('time_updated', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('workspaces', 'time_updated')
|
||||
op.drop_column('workspaces', 'time_created')
|
||||
# ### end Alembic commands ###
|
7
atst/models/mixins.py
Normal file
7
atst/models/mixins.py
Normal file
@ -0,0 +1,7 @@
|
||||
from sqlalchemy import Column, func, TIMESTAMP
|
||||
|
||||
|
||||
class TimestampsMixin(object):
|
||||
time_created = Column(TIMESTAMP(timezone=True), nullable=False, server_default=func.now())
|
||||
time_updated = Column(TIMESTAMP(timezone=True), nullable=False, server_default=func.now(), onupdate=func.current_timestamp())
|
||||
|
@ -3,9 +3,10 @@ from sqlalchemy.orm import relationship
|
||||
|
||||
from atst.models import Base
|
||||
from atst.models.types import Id
|
||||
from atst.models.mixins import TimestampsMixin
|
||||
|
||||
|
||||
class Workspace(Base):
|
||||
class Workspace(Base, TimestampsMixin):
|
||||
__tablename__ = "workspaces"
|
||||
|
||||
id = Id()
|
||||
|
Loading…
x
Reference in New Issue
Block a user