~muirrum/comortas

611d9a3bca03f20ad22203b3b5761e05528485a1 — Cara Salter 3 years ago 64fb2df
Update models
M fllscoring/models.py => fllscoring/models.py +26 -2
@@ 12,7 12,31 @@ class Users(db.Model,UserMixin):
    is_superadmin = db.Column(db.Boolean, default=False, nullable=False)

    def __repr__(self):
        return f"<User {self.username}"
        return f"<User {self.username} ({self.user_id})>"

    def get_id(self):
        return self.user_id
\ No newline at end of file
        return self.user_id

class Tournaments(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    owner_id = db.Column(db.Integer, ForeignKey("users.user_id"), nullable=False, index=True)
    tournament_name = db.Column(db.String, nullable=False)

class Team(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    tournament = db.Column(db.Integer, ForeignKey("tournaments.id"), nullable=False, index=True)
    team_number = db.Column(db.Integer, nullable=False, unique=True)
    team_name = db.Column(db.String, nullable=False, default="No Name")
    team_town = db.Column(db.String, nullable=False, default="No Town")

    def __str__(self):
        return f"{self.team_number} - {self.team_name}"

class Match(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

A migrations/versions/2cb04c80d294_scoring.py => migrations/versions/2cb04c80d294_scoring.py +42 -0
@@ 0,0 1,42 @@
"""scoring

Revision ID: 2cb04c80d294
Revises: 5b61d04de41e
Create Date: 2021-04-16 17:12:47.135233

"""
from alembic import op
import sqlalchemy as sa


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


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


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('match_teams')
    op.drop_table('match')
    # ### end Alembic commands ###

A migrations/versions/5b61d04de41e_teams.py => migrations/versions/5b61d04de41e_teams.py +39 -0
@@ 0,0 1,39 @@
"""teams

Revision ID: 5b61d04de41e
Revises: b7aa2e2835b4
Create Date: 2021-04-15 17:29:29.256646

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '5b61d04de41e'
down_revision = 'b7aa2e2835b4'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('team',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('tournament', sa.Integer(), nullable=False),
    sa.Column('team_number', sa.Integer(), nullable=False),
    sa.Column('team_name', sa.String(), nullable=False),
    sa.Column('team_town', sa.String(), nullable=False),
    sa.ForeignKeyConstraint(['tournament'], ['tournaments.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('team_number')
    )
    op.create_index(op.f('ix_team_tournament'), 'team', ['tournament'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_team_tournament'), table_name='team')
    op.drop_table('team')
    # ### end Alembic commands ###

A migrations/versions/b7aa2e2835b4_tournaments.py => migrations/versions/b7aa2e2835b4_tournaments.py +36 -0
@@ 0,0 1,36 @@
"""tournaments

Revision ID: b7aa2e2835b4
Revises: 8cba3105ef08
Create Date: 2021-04-15 17:24:05.327426

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'b7aa2e2835b4'
down_revision = '8cba3105ef08'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('tournaments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('owner_id', sa.Integer(), nullable=False),
    sa.Column('tournament_name', sa.String(), nullable=False),
    sa.ForeignKeyConstraint(['owner_id'], ['users.user_id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_tournaments_owner_id'), 'tournaments', ['owner_id'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_tournaments_owner_id'), table_name='tournaments')
    op.drop_table('tournaments')
    # ### end Alembic commands ###