From 01778ada05c4dfe265730fb7f060350234dcaa0e Mon Sep 17 00:00:00 2001 From: richard-dds Date: Fri, 17 Aug 2018 11:02:59 -0400 Subject: [PATCH] Add timestamps to workspace --- .../a2b499a1dd62_workspace_timestamps.py | 30 +++++++++++++++++++ atst/models/mixins.py | 7 +++++ atst/models/workspace.py | 3 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 alembic/versions/a2b499a1dd62_workspace_timestamps.py create mode 100644 atst/models/mixins.py diff --git a/alembic/versions/a2b499a1dd62_workspace_timestamps.py b/alembic/versions/a2b499a1dd62_workspace_timestamps.py new file mode 100644 index 00000000..f7c3e05a --- /dev/null +++ b/alembic/versions/a2b499a1dd62_workspace_timestamps.py @@ -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 ### diff --git a/atst/models/mixins.py b/atst/models/mixins.py new file mode 100644 index 00000000..467ee172 --- /dev/null +++ b/atst/models/mixins.py @@ -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()) + diff --git a/atst/models/workspace.py b/atst/models/workspace.py index 03370c34..b0051093 100644 --- a/atst/models/workspace.py +++ b/atst/models/workspace.py @@ -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()