From ef6321d4f614847d77bd90a82f4fabe5f867dbf1 Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Sun, 24 Nov 2024 17:17:12 -0800 Subject: [PATCH] Add player_team_role_id to player_event --- ...55_add_player_event_player_team_role_id.py | 34 +++++++++++++++ ...9af_rename_players_teams_roles_id_to_id.py | 42 +++++++++++++++++++ backend-flask/models/player_event.py | 3 ++ backend-flask/models/player_team_role.py | 2 +- 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 backend-flask/migrations/versions/2a33f577d655_add_player_event_player_team_role_id.py create mode 100644 backend-flask/migrations/versions/2b05ba5ba9af_rename_players_teams_roles_id_to_id.py diff --git a/backend-flask/migrations/versions/2a33f577d655_add_player_event_player_team_role_id.py b/backend-flask/migrations/versions/2a33f577d655_add_player_event_player_team_role_id.py new file mode 100644 index 0000000..0ab4023 --- /dev/null +++ b/backend-flask/migrations/versions/2a33f577d655_add_player_event_player_team_role_id.py @@ -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 ### diff --git a/backend-flask/migrations/versions/2b05ba5ba9af_rename_players_teams_roles_id_to_id.py b/backend-flask/migrations/versions/2b05ba5ba9af_rename_players_teams_roles_id_to_id.py new file mode 100644 index 0000000..67da94c --- /dev/null +++ b/backend-flask/migrations/versions/2b05ba5ba9af_rename_players_teams_roles_id_to_id.py @@ -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 ### diff --git a/backend-flask/models/player_event.py b/backend-flask/models/player_event.py index 6f7bc0a..db0d802 100644 --- a/backend-flask/models/player_event.py +++ b/backend-flask/models/player_event.py @@ -9,10 +9,13 @@ class PlayerEvent(app_db.BaseModel): 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_team_role_id: Mapped[int] = mapped_column(ForeignKey("players_teams_roles.id")) event: Mapped["Event"] = relationship("Event", back_populates="players") player: Mapped["Player"] = relationship("Player", back_populates="events") + role: Mapped["PlayerTeamRole"] = relationship("PlayerTeamRole") from models.event import Event from models.player import Player +from models.player_team_role import PlayerTeamRole diff --git a/backend-flask/models/player_team_role.py b/backend-flask/models/player_team_role.py index 3a095a2..b84f2d6 100644 --- a/backend-flask/models/player_team_role.py +++ b/backend-flask/models/player_team_role.py @@ -32,7 +32,7 @@ class PlayerTeamRole(app_db.BaseModel): Spy = 13 # surrogate key - player_team_role_id: Mapped[int] = mapped_column( + id: Mapped[int] = mapped_column( Integer, autoincrement=True, primary_key=True,