From 9185a562672912e7752824864827b0cb93b5fbc3 Mon Sep 17 00:00:00 2001 From: Alan Roberts Date: Sat, 28 Sep 2024 09:27:03 -0400 Subject: [PATCH] adding intercted_at column to read_posts table --- app/models.py | 1 + ...6_adding_created_at_to_read_posts_table.py | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 migrations/versions/238d7c60d676_adding_created_at_to_read_posts_table.py diff --git a/app/models.py b/app/models.py index ace9b8c9..31e1fbde 100644 --- a/app/models.py +++ b/app/models.py @@ -617,6 +617,7 @@ user_role = db.Table('user_role', read_posts = db.Table('read_posts', db.Column('user_id', db.Integer, db.ForeignKey('user.id'), index=True), db.Column('read_post_id', db.Integer, db.ForeignKey('post.id'), index=True), + db.Column('interacted_at', db.DateTime, index=True, default=utcnow) # this is when the content is interacte with ) class User(UserMixin, db.Model): diff --git a/migrations/versions/238d7c60d676_adding_created_at_to_read_posts_table.py b/migrations/versions/238d7c60d676_adding_created_at_to_read_posts_table.py new file mode 100644 index 00000000..261dd72f --- /dev/null +++ b/migrations/versions/238d7c60d676_adding_created_at_to_read_posts_table.py @@ -0,0 +1,34 @@ +"""adding created_at to read_posts table + +Revision ID: 238d7c60d676 +Revises: 6e0b98e1fdc6 +Create Date: 2024-09-28 09:26:22.000646 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '238d7c60d676' +down_revision = '6e0b98e1fdc6' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('read_posts', schema=None) as batch_op: + batch_op.add_column(sa.Column('interacted_at', sa.DateTime(), nullable=True)) + batch_op.create_index(batch_op.f('ix_read_posts_interacted_at'), ['interacted_at'], unique=False) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('read_posts', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_read_posts_interacted_at')) + batch_op.drop_column('interacted_at') + + # ### end Alembic commands ###