~muirrum/comortas

0a34d68581db4e82f92186c48499b3b581359ce5 — Cara Salter 3 years ago 965fea2
Add match scores model and migration
2 files changed, 58 insertions(+), 6 deletions(-)

M fllscoring/models.py
A migrations/versions/bed7e505df9b_add_match_scores.py
M fllscoring/models.py => fllscoring/models.py +5 -6
@@ 1,4 1,6 @@
from sqlalchemy import ForeignKey
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.mutable import MutableDict

from fllscoring import db



@@ 32,11 34,8 @@ class Team(db.Model):
    def __str__(self):
        return f"{self.team_number} - {self.team_name}"

class Match(db.Model):
class MatchScore(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    tournament = db.Column(db.Integer, ForeignKey("tournaments.id"))

class MatchTeams(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    match_id = db.Column(db.Integer, ForeignKey("match.id"))
    team_id = db.Column(db.Integer, ForeignKey("team.id"))
\ No newline at end of file
    team = db.Column(db.Integer, ForeignKey("team.id"))
    score = db.Column(MutableDict().as_mutable(JSONB))
\ No newline at end of file

A migrations/versions/bed7e505df9b_add_match_scores.py => migrations/versions/bed7e505df9b_add_match_scores.py +53 -0
@@ 0,0 1,53 @@
"""Add match scores

Revision ID: bed7e505df9b
Revises: 2cb04c80d294
Create Date: 2021-04-24 09:50:54.918706

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'bed7e505df9b'
down_revision = '2cb04c80d294'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('match_score',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('tournament', sa.Integer(), nullable=True),
    sa.Column('team', sa.Integer(), nullable=True),
    sa.Column('score', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.ForeignKeyConstraint(['team'], ['team.id'], ),
    sa.ForeignKeyConstraint(['tournament'], ['tournaments.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.drop_table('match_teams')
    op.drop_table('match')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('match',
    sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('match_id_seq'::regclass)"), autoincrement=True, nullable=False),
    sa.Column('tournament', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['tournament'], ['tournaments.id'], name='match_tournament_fkey'),
    sa.PrimaryKeyConstraint('id', name='match_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_table('match_teams',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('match_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('team_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['match_id'], ['match.id'], name='match_teams_match_id_fkey'),
    sa.ForeignKeyConstraint(['team_id'], ['team.id'], name='match_teams_team_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='match_teams_pkey')
    )
    op.drop_table('match_score')
    # ### end Alembic commands ###