mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
poll database migration #181
This commit is contained in:
parent
d43e381b3e
commit
36fb3259b9
2 changed files with 90 additions and 0 deletions
|
@ -1369,6 +1369,28 @@ class NotificationSubscription(db.Model):
|
|||
created_at = db.Column(db.DateTime, default=utcnow) # Perhaps very old subscriptions can be automatically deleted
|
||||
|
||||
|
||||
class Poll(db.Model):
|
||||
post_id = db.Column(db.Integer, db.ForeignKey('post.id'), primary_key=True)
|
||||
end_poll = db.Column(db.DateTime)
|
||||
local_only = db.Column(db.Boolean)
|
||||
latest_vote = db.Column(db.DateTime)
|
||||
|
||||
|
||||
class PollChoice(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
post_id = db.Column(db.Integer, db.ForeignKey('post.id'), index=True)
|
||||
choice_text = db.Column(db.String(200))
|
||||
sort_order = db.Column(db.Integer)
|
||||
num_votes = db.Column(db.Integer, default=0)
|
||||
|
||||
|
||||
class PollChoiceVote(db.Model):
|
||||
choice_id = db.Column(db.Integer, db.ForeignKey('poll_choice.id'), primary_key=True)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
|
||||
post_id = db.Column(db.Integer, db.ForeignKey('post.id'), index=True)
|
||||
created_at = db.Column(db.DateTime, default=utcnow)
|
||||
|
||||
|
||||
class IpBan(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
ip_address = db.Column(db.String(50), index=True)
|
||||
|
|
68
migrations/versions/92bdb39f6c72_polls.py
Normal file
68
migrations/versions/92bdb39f6c72_polls.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
"""polls
|
||||
|
||||
Revision ID: 92bdb39f6c72
|
||||
Revises: 9752fb47d7a6
|
||||
Create Date: 2024-05-16 20:42:05.491951
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '92bdb39f6c72'
|
||||
down_revision = '9752fb47d7a6'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('poll',
|
||||
sa.Column('post_id', sa.Integer(), nullable=False),
|
||||
sa.Column('end_poll', sa.DateTime(), nullable=True),
|
||||
sa.Column('local_only', sa.Boolean(), nullable=True),
|
||||
sa.Column('latest_vote', sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['post_id'], ['post.id'], ),
|
||||
sa.PrimaryKeyConstraint('post_id')
|
||||
)
|
||||
op.create_table('poll_choice',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('post_id', sa.Integer(), nullable=True),
|
||||
sa.Column('choice_text', sa.String(length=200), nullable=True),
|
||||
sa.Column('sort_order', sa.Integer(), nullable=True),
|
||||
sa.Column('num_votes', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['post_id'], ['post.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
with op.batch_alter_table('poll_choice', schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f('ix_poll_choice_post_id'), ['post_id'], unique=False)
|
||||
|
||||
op.create_table('poll_choice_vote',
|
||||
sa.Column('choice_id', sa.Integer(), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.Column('post_id', sa.Integer(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['choice_id'], ['poll_choice.id'], ),
|
||||
sa.ForeignKeyConstraint(['post_id'], ['post.id'], ),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
|
||||
sa.PrimaryKeyConstraint('choice_id', 'user_id')
|
||||
)
|
||||
with op.batch_alter_table('poll_choice_vote', schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f('ix_poll_choice_vote_post_id'), ['post_id'], unique=False)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('poll_choice_vote', schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f('ix_poll_choice_vote_post_id'))
|
||||
|
||||
op.drop_table('poll_choice_vote')
|
||||
with op.batch_alter_table('poll_choice', schema=None) as batch_op:
|
||||
batch_op.drop_index(batch_op.f('ix_poll_choice_post_id'))
|
||||
|
||||
op.drop_table('poll_choice')
|
||||
op.drop_table('poll')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in a new issue