diff --git a/alembic/versions/ac2bd309d20c_add_created_at_to_tasks.py b/alembic/versions/ac2bd309d20c_add_created_at_to_tasks.py new file mode 100644 index 0000000..d107291 --- /dev/null +++ b/alembic/versions/ac2bd309d20c_add_created_at_to_tasks.py @@ -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') diff --git a/src/pyelephant.py b/src/pyelephant.py index 74965cf..e0ab8f7 100755 --- a/src/pyelephant.py +++ b/src/pyelephant.py @@ -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) ###############################################################################