Always but always but ALWAYS, use server_default=func.now() when setting up a datetime field we autopopulate.
This commit is contained in:
parent
6bff33b9f5
commit
e67a1554ea
|
@ -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):
|
||||
|
|
|
@ -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 ###
|
|
@ -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 ###
|
Loading…
Reference in New Issue