Add player_team_role_id to player_event

master
John Montagu, the 4th Earl of Sandvich 2024-11-24 17:17:12 -08:00
parent 8bef735756
commit ef6321d4f6
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
4 changed files with 80 additions and 1 deletions

View File

@ -0,0 +1,34 @@
"""Add player_event.player_team_role_id
Revision ID: 2a33f577d655
Revises: 2b05ba5ba9af
Create Date: 2024-11-24 16:29:03.546231
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '2a33f577d655'
down_revision = '2b05ba5ba9af'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_events', schema=None) as batch_op:
batch_op.add_column(sa.Column('player_team_role_id', sa.Integer(), nullable=False))
batch_op.create_foreign_key('fk_players_events_player_team_role_id_players_teams_roles', 'players_teams_roles', ['player_team_role_id'], ['id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_events', schema=None) as batch_op:
batch_op.drop_constraint('fk_players_events_player_team_role_id_players_teams_roles', type_='foreignkey')
batch_op.drop_column('player_team_role_id')
# ### end Alembic commands ###

View File

@ -0,0 +1,42 @@
"""Rename players_teams_roles_id to id
Revision ID: 2b05ba5ba9af
Revises: 47f0722b02b0
Create Date: 2024-11-24 15:58:36.018191
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '2b05ba5ba9af'
down_revision = '47f0722b02b0'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('events', schema=None) as batch_op:
batch_op.create_unique_constraint('uq_events_team_id', ['team_id', 'name', 'start_time'])
with op.batch_alter_table('players_teams_roles', schema=None) as batch_op:
#batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
#batch_op.drop_column('player_team_role_id')
batch_op.alter_column('player_team_role_id', new_column_name='id')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams_roles', schema=None) as batch_op:
batch_op.alter_column('id', new_column_name='player_team_role_id')
#batch_op.add_column(sa.Column('player_team_role_id', sa.INTEGER(), nullable=False))
#batch_op.drop_column('id')
with op.batch_alter_table('events', schema=None) as batch_op:
batch_op.drop_constraint('uq_events_team_id', type_='unique')
# ### end Alembic commands ###

View File

@ -9,10 +9,13 @@ class PlayerEvent(app_db.BaseModel):
event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), primary_key=True) event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), primary_key=True)
player_id: Mapped[int] = mapped_column(ForeignKey("players.steam_id"), primary_key=True) player_id: Mapped[int] = mapped_column(ForeignKey("players.steam_id"), primary_key=True)
player_team_role_id: Mapped[int] = mapped_column(ForeignKey("players_teams_roles.id"))
event: Mapped["Event"] = relationship("Event", back_populates="players") event: Mapped["Event"] = relationship("Event", back_populates="players")
player: Mapped["Player"] = relationship("Player", back_populates="events") player: Mapped["Player"] = relationship("Player", back_populates="events")
role: Mapped["PlayerTeamRole"] = relationship("PlayerTeamRole")
from models.event import Event from models.event import Event
from models.player import Player from models.player import Player
from models.player_team_role import PlayerTeamRole

View File

@ -32,7 +32,7 @@ class PlayerTeamRole(app_db.BaseModel):
Spy = 13 Spy = 13
# surrogate key # surrogate key
player_team_role_id: Mapped[int] = mapped_column( id: Mapped[int] = mapped_column(
Integer, Integer,
autoincrement=True, autoincrement=True,
primary_key=True, primary_key=True,