From f6ad3ed1873c40a60b125bcf70e014e392108801 Mon Sep 17 00:00:00 2001 From: Alex Do Date: Wed, 4 Mar 2026 10:09:34 +0000 Subject: [PATCH] fix(db): incorrect revision hash stamp + new tables --- .github/workflows/deploy.yml | 2 + data/elections.json | 49 ++++++++++++++++ .../b300460f8ead_add_election_models.py | 56 +++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 data/elections.json create mode 100644 migrations/versions/b300460f8ead_add_election_models.py diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ff93f89..5e7ad7a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -80,6 +80,8 @@ jobs: key: ${{ secrets.VM_SSH_KEY }} script: | cd ~/website/ + FLASK_APP=codesoc.py flask db current 2>/dev/null | grep -q '[0-9a-f]' || \ + FLASK_APP=codesoc.py flask db stamp head FLASK_APP=codesoc.py flask db upgrade - name: Reset database diff --git a/data/elections.json b/data/elections.json new file mode 100644 index 0000000..b26dc8d --- /dev/null +++ b/data/elections.json @@ -0,0 +1,49 @@ +{ + "categories": [ + { + "name": "Management", + "slug": "management", + "positions": [ + { "title": "President", "candidates": [] }, + { "title": "Vice-President", "candidates": [] }, + { "title": "Head of Infrastructure", "candidates": [] } + ] + }, + { + "name": "Finance Team", + "slug": "finance", + "positions": [ + { "title": "Treasurer", "candidates": [] }, + { "title": "Merchandise Manager", "candidates": [] } + ] + }, + { + "name": "Academic Team", + "slug": "academic", + "positions": [ + { "title": "Head of Mentoring", "candidates": [] }, + { "title": "Python Course Lead", "candidates": [] }, + { "title": "C++ Course Lead", "candidates": [] }, + { "title": "HPC Team Lead", "candidates": [] } + ] + }, + { + "name": "Creative Team", + "slug": "creative", + "positions": [ + { "title": "Social Media Lead", "candidates": [] }, + { "title": "Graphics Lead", "candidates": [] }, + { "title": "Video Production", "candidates": [] } + ] + }, + { + "name": "Community Team", + "slug": "community", + "positions": [ + { "title": "Social Secretary", "candidates": [] }, + { "title": "Sports Coordinator", "candidates": [] }, + { "title": "Diversity Director", "candidates": [] } + ] + } + ] +} diff --git a/migrations/versions/b300460f8ead_add_election_models.py b/migrations/versions/b300460f8ead_add_election_models.py new file mode 100644 index 0000000..78b1317 --- /dev/null +++ b/migrations/versions/b300460f8ead_add_election_models.py @@ -0,0 +1,56 @@ +"""Add election models + +Revision ID: b300460f8ead +Revises: 91e2ccd08922 +Create Date: 2026-03-04 09:47:35.646898 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'b300460f8ead' +down_revision = '91e2ccd08922' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('electionCandidates', + sa.Column('candidateID', sa.Integer(), nullable=False), + sa.Column('categorySlug', sa.String(length=64), nullable=True), + sa.Column('categoryName', sa.String(length=128), nullable=True), + sa.Column('positionTitle', sa.String(length=128), nullable=True), + sa.Column('name', sa.String(length=128), nullable=True), + sa.Column('manifestoLink', sa.String(length=512), nullable=True), + sa.PrimaryKeyConstraint('candidateID') + ) + op.create_table('electionSettings', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('isOpen', sa.Boolean(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('electionVotes', + sa.Column('voteID', sa.Integer(), nullable=False), + sa.Column('voterStudentID', sa.Integer(), nullable=False), + sa.Column('candidateID', sa.Integer(), nullable=False), + sa.Column('positionTitle', sa.String(length=128), nullable=True), + sa.Column('categorySlug', sa.String(length=64), nullable=True), + sa.Column('rank', sa.Integer(), nullable=True), + sa.Column('points', sa.Integer(), nullable=True), + sa.Column('submittedAt', sa.DateTime(), nullable=True), + sa.PrimaryKeyConstraint('voteID'), + sa.UniqueConstraint('voterStudentID', 'candidateID', name='uq_voter_candidate'), + sa.UniqueConstraint('voterStudentID', 'positionTitle', 'rank', name='uq_voter_position_rank') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('electionVotes') + op.drop_table('electionSettings') + op.drop_table('electionCandidates') + # ### end Alembic commands ###