Always but always but ALWAYS, use server_default=func.now() when setting up a datetime field we autopopulate.

This commit is contained in:
Dan 2022-01-12 12:33:59 -05:00
parent 6bff33b9f5
commit e67a1554ea
3 changed files with 57 additions and 1 deletions

View File

@ -31,7 +31,7 @@ class TaskLogModel(db.Model):
study_id = db.Column(db.Integer, db.ForeignKey(StudyModel.id), nullable=False)
workflow_id = db.Column(db.Integer, db.ForeignKey(WorkflowModel.id), nullable=False)
task = db.Column(db.String)
timestamp = db.Column(db.DateTime(timezone=True), default=func.now())
timestamp = db.Column(db.DateTime(timezone=True), server_default=func.now())
class TaskLogModelSchema(ma.Schema):

View File

@ -0,0 +1,28 @@
"""empty message
Revision ID: 1fb36d682c7f
Revises: e8cc6a9245f3
Create Date: 2022-01-12 12:28:48.577819
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1fb36d682c7f'
down_revision = 'e8cc6a9245f3'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('task_log', sa.Column('timestamp', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('task_log', 'timestamp')
# ### end Alembic commands ###

View File

@ -0,0 +1,28 @@
"""empty message
Revision ID: e8cc6a9245f3
Revises: efdc41cc7fbf
Create Date: 2022-01-12 12:28:25.257443
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = 'e8cc6a9245f3'
down_revision = 'efdc41cc7fbf'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('task_log', 'timestamp')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('task_log', sa.Column('timestamp', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True))
# ### end Alembic commands ###