Add created_at field to tasks
This commit is contained in:
parent
1013169093
commit
e05a024a79
34
alembic/versions/ac2bd309d20c_add_created_at_to_tasks.py
Normal file
34
alembic/versions/ac2bd309d20c_add_created_at_to_tasks.py
Normal file
@ -0,0 +1,34 @@
|
||||
"""add created_at to tasks
|
||||
|
||||
Revision ID: ac2bd309d20c
|
||||
Revises: 40867bd0dcc8
|
||||
Create Date: 2020-05-20 12:36:53.685254
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'ac2bd309d20c'
|
||||
down_revision = '40867bd0dcc8'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# Requires batching for non-constant default under SQLite.
|
||||
with op.batch_alter_table('tasks', recreate='always') as batch:
|
||||
batch.add_column(
|
||||
sa.Column(
|
||||
'created_at',
|
||||
sa.DateTime,
|
||||
server_default=sa.func.current_timestamp(),
|
||||
nullable=False
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table('tasks') as tasks:
|
||||
tasks.drop_column('created_at')
|
@ -22,8 +22,8 @@ def rm(session: sa.orm.Session, index: int):
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
def ls(session: sa.orm.Session):
|
||||
for i in session.query(Task):
|
||||
print(i.id, i.title)
|
||||
for i in session.query(Task).order_by(Task.created_at):
|
||||
print(i.id, i.created_at, i.title)
|
||||
|
||||
|
||||
###############################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user