refactor(migrations): Consolidate migrations

Consolidate multiple migration files into a single migration file to
help the database prepare for production.
master
John Montagu, the 4th Earl of Sandvich 2024-12-10 16:45:06 -08:00
parent caaee983f2
commit 64b2d129eb
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
30 changed files with 176 additions and 1159 deletions

View File

@ -1,32 +0,0 @@
"""Add column players_teams_availability.availability
Revision ID: 062a154a0797
Revises: 4fb63c11ee8c
Create Date: 2024-10-30 23:54:22.877218
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '062a154a0797'
down_revision = '4fb63c11ee8c'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.add_column(sa.Column('availability', sa.Integer(), nullable=False, default=2))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.drop_column('availability')
# ### end Alembic commands ###

View File

@ -1,36 +0,0 @@
"""Add PlayerEvent models
Revision ID: 131efbdd7af4
Revises: 1fc9a051a0a6
Create Date: 2024-11-19 10:16:34.289124
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '131efbdd7af4'
down_revision = '1fc9a051a0a6'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('team_discord_integrations', schema=None) as batch_op:
batch_op.alter_column('webhook_url',
existing_type=sa.VARCHAR(length=255),
nullable=True)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('team_discord_integrations', schema=None) as batch_op:
batch_op.alter_column('webhook_url',
existing_type=sa.VARCHAR(length=255),
nullable=False)
# ### end Alembic commands ###

View File

@ -1,41 +0,0 @@
"""Add team integrations models
Revision ID: 1fc9a051a0a6
Revises: 65714d7e78f8
Create Date: 2024-11-11 19:12:42.611838
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1fc9a051a0a6'
down_revision = '65714d7e78f8'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('team_integrations',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('integration_type', sa.String(), nullable=False),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('team_discord_integrations',
sa.Column('integration_id', sa.Integer(), nullable=False),
sa.Column('webhook_url', sa.String(length=255), nullable=False),
sa.ForeignKeyConstraint(['integration_id'], ['team_integrations.id'], ),
sa.PrimaryKeyConstraint('integration_id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('team_discord_integrations')
op.drop_table('team_integrations')
# ### end Alembic commands ###

View File

@ -1,33 +0,0 @@
"""empty message
Revision ID: 273f73c81783
Revises: ce676db8c655
Create Date: 2024-10-29 23:12:40.743611
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '273f73c81783'
down_revision = 'ce676db8c655'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('auth_session',
sa.Column('player_id', sa.BigInteger(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.ForeignKeyConstraint(['player_id'], ['players.steam_id'], ),
sa.PrimaryKeyConstraint('player_id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('auth_session')
# ### end Alembic commands ###

View File

@ -1,32 +0,0 @@
"""Add event.discord_message_id
Revision ID: 286ee26b9e5d
Revises: 392454b91293
Create Date: 2024-11-25 21:00:08.444434
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '286ee26b9e5d'
down_revision = '392454b91293'
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.add_column(sa.Column('discord_message_id', sa.BigInteger(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('events', schema=None) as batch_op:
batch_op.drop_column('discord_message_id')
# ### end Alembic commands ###

View File

@ -1,34 +0,0 @@
"""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

@ -1,42 +0,0 @@
"""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

@ -1,26 +0,0 @@
"""Make player role primary key
Revision ID: 2b2f3ae2ec7f
Revises: 958df14798d5
Create Date: 2024-10-31 19:07:02.960849
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '2b2f3ae2ec7f'
down_revision = '958df14798d5'
branch_labels = None
depends_on = None
def upgrade():
with op.batch_alter_table('players_teams_roles', schema=None) as batch_op:
batch_op.create_primary_key('pk_players_teams_roles', ['player_id', 'team_id', 'role'])
def downgrade():
with op.batch_alter_table('players_teams_roles', schema=None) as batch_op:
batch_op.drop_constraint('pk_players_teams_roles')

View File

@ -1,42 +0,0 @@
"""Change integrations to one-to-one
Revision ID: 392454b91293
Revises: f802d763a7b4
Create Date: 2024-11-25 18:36:15.293593
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '392454b91293'
down_revision = 'f802d763a7b4'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('team_discord_integrations',
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('webhook_url', sa.String(), nullable=False),
sa.Column('webhook_bot_name', sa.String(), nullable=False),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('team_id')
)
op.create_table('team_logs_tf_integrations',
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('logs_tf_api_key', sa.String(), nullable=True),
sa.Column('min_team_member_count', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('team_id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('team_logs_tf_integrations')
op.drop_table('team_discord_integrations')
# ### end Alembic commands ###

View File

@ -0,0 +1,176 @@
"""empty message
Revision ID: 3b18d4bfc6ac
Revises:
Create Date: 2024-12-10 16:43:29.354244
"""
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utc
# revision identifiers, used by Alembic.
revision = '3b18d4bfc6ac'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('matches',
sa.Column('logs_tf_id', sa.Integer(), nullable=False),
sa.Column('logs_tf_title', sa.String(length=255), nullable=False),
sa.Column('duration', sa.Integer(), nullable=False),
sa.Column('match_time', sa.TIMESTAMP(), nullable=False),
sa.Column('blue_score', sa.Integer(), nullable=False),
sa.Column('red_score', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.PrimaryKeyConstraint('logs_tf_id')
)
op.create_table('players',
sa.Column('steam_id', sa.BigInteger(), nullable=False),
sa.Column('username', sa.String(length=63), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.PrimaryKeyConstraint('steam_id')
)
op.create_table('teams',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('team_name', sa.String(length=63), nullable=False),
sa.Column('discord_webhook_url', sa.String(length=255), nullable=True),
sa.Column('tz_timezone', sa.String(length=31), nullable=False),
sa.Column('minute_offset', sa.SmallInteger(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('team_name')
)
op.create_table('auth_sessions',
sa.Column('key', sa.String(length=31), nullable=False),
sa.Column('player_id', sa.BigInteger(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.ForeignKeyConstraint(['player_id'], ['players.steam_id'], ),
sa.PrimaryKeyConstraint('key')
)
op.create_table('events',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('start_time', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.Column('discord_message_id', sa.BigInteger(), nullable=True),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('team_id', 'name', 'start_time')
)
op.create_table('players_matches',
sa.Column('player_id', sa.BigInteger(), nullable=False),
sa.Column('match_id', sa.Integer(), nullable=False),
sa.Column('kills', sa.Integer(), nullable=False),
sa.Column('deaths', sa.Integer(), nullable=False),
sa.Column('assists', sa.Integer(), nullable=False),
sa.Column('damage', sa.BigInteger(), nullable=False),
sa.Column('damage_taken', sa.BigInteger(), nullable=False),
sa.ForeignKeyConstraint(['match_id'], ['matches.logs_tf_id'], ),
sa.ForeignKeyConstraint(['player_id'], ['players.steam_id'], ),
sa.PrimaryKeyConstraint('player_id', 'match_id')
)
op.create_table('players_teams',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('player_id', sa.BigInteger(), nullable=False),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('team_role', sa.Enum('Player', 'CoachMentor', name='teamrole'), nullable=False),
sa.Column('playtime', sa.Integer(), nullable=False),
sa.Column('is_team_leader', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.ForeignKeyConstraint(['player_id'], ['players.steam_id'], ),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('team_discord_integrations',
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('webhook_url', sa.String(), nullable=False),
sa.Column('webhook_bot_name', sa.String(), nullable=False),
sa.Column('webhook_bot_profile_picture', sa.String(length=255), nullable=True),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('team_id')
)
op.create_table('team_invites',
sa.Column('key', sa.String(length=31), nullable=False),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('delete_on_use', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('key')
)
op.create_table('team_logs_tf_integrations',
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('logs_tf_api_key', sa.String(), nullable=True),
sa.Column('min_team_member_count', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('team_id')
)
op.create_table('teams_matches',
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('match_id', sa.Integer(), nullable=False),
sa.Column('team_color', sa.String(length=4), nullable=False),
sa.ForeignKeyConstraint(['match_id'], ['matches.logs_tf_id'], ),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('team_id', 'match_id')
)
op.create_table('players_teams_availability',
sa.Column('player_team_id', sa.Integer(), nullable=False),
sa.Column('start_time', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), nullable=False),
sa.Column('availability', sa.Integer(), nullable=False),
sa.Column('end_time', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['player_team_id'], ['players_teams.id'], ),
sa.PrimaryKeyConstraint('player_team_id', 'start_time')
)
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_players_teams_availability_end_time'), ['end_time'], unique=False)
batch_op.create_index(batch_op.f('ix_players_teams_availability_start_time'), ['start_time'], unique=False)
op.create_table('players_teams_roles',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('player_team_id', sa.Integer(), nullable=False),
sa.Column('role', sa.Enum('Unknown', 'Scout', 'PocketScout', 'FlankScout', 'Soldier', 'PocketSoldier', 'Roamer', 'Pyro', 'Demoman', 'HeavyWeapons', 'Engineer', 'Medic', 'Sniper', 'Spy', name='role'), nullable=False),
sa.Column('is_main', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['player_team_id'], ['players_teams.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('player_team_id', 'role')
)
op.create_table('players_events',
sa.Column('event_id', sa.Integer(), nullable=False),
sa.Column('player_id', sa.BigInteger(), nullable=False),
sa.Column('player_team_role_id', sa.Integer(), nullable=True),
sa.Column('has_confirmed', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['event_id'], ['events.id'], ),
sa.ForeignKeyConstraint(['player_id'], ['players.steam_id'], ),
sa.ForeignKeyConstraint(['player_team_role_id'], ['players_teams_roles.id'], ),
sa.PrimaryKeyConstraint('event_id', 'player_id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('players_events')
op.drop_table('players_teams_roles')
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_players_teams_availability_start_time'))
batch_op.drop_index(batch_op.f('ix_players_teams_availability_end_time'))
op.drop_table('players_teams_availability')
op.drop_table('teams_matches')
op.drop_table('team_logs_tf_integrations')
op.drop_table('team_invites')
op.drop_table('team_discord_integrations')
op.drop_table('players_teams')
op.drop_table('players_matches')
op.drop_table('events')
op.drop_table('auth_sessions')
op.drop_table('teams')
op.drop_table('players')
op.drop_table('matches')
# ### end Alembic commands ###

View File

@ -1,34 +0,0 @@
"""Add availability index
Revision ID: 47f0722b02b0
Revises: 7361c978e53d
Create Date: 2024-11-21 13:10:45.098947
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '47f0722b02b0'
down_revision = '7361c978e53d'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_players_teams_availability_end_time'), ['end_time'], unique=False)
batch_op.create_index(batch_op.f('ix_players_teams_availability_start_time'), ['start_time'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_players_teams_availability_start_time'))
batch_op.drop_index(batch_op.f('ix_players_teams_availability_end_time'))
# ### end Alembic commands ###

View File

@ -1,44 +0,0 @@
"""Rename table players_teams_availability
Revision ID: 4fb63c11ee8c
Revises: 8ea29cf493f5
Create Date: 2024-10-30 22:45:51.227298
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '4fb63c11ee8c'
down_revision = '8ea29cf493f5'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('players_teams_availability',
sa.Column('player_id', sa.Integer(), nullable=False),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('start_time', sa.TIMESTAMP(), nullable=False),
sa.Column('end_time', sa.TIMESTAMP(), nullable=False),
sa.ForeignKeyConstraint(['player_id', 'team_id'], ['players_teams.player_id', 'players_teams.team_id'], ),
sa.PrimaryKeyConstraint('player_id', 'team_id', 'start_time')
)
op.drop_table('player_team_availability')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('player_team_availability',
sa.Column('player_id', sa.INTEGER(), nullable=False),
sa.Column('team_id', sa.INTEGER(), nullable=False),
sa.Column('start_time', sa.TIMESTAMP(), nullable=False),
sa.Column('end_time', sa.TIMESTAMP(), nullable=False),
sa.ForeignKeyConstraint(['player_id', 'team_id'], ['players_teams.player_id', 'players_teams.team_id'], ),
sa.PrimaryKeyConstraint('player_id', 'team_id')
)
op.drop_table('players_teams_availability')
# ### end Alembic commands ###

View File

@ -1,46 +0,0 @@
"""Add Events
Revision ID: 5debac4cdf37
Revises: 131efbdd7af4
Create Date: 2024-11-20 15:17:00.205485
"""
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utc
# revision identifiers, used by Alembic.
revision = '5debac4cdf37'
down_revision = '131efbdd7af4'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('events',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('start_time', sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True), nullable=False),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('players_events',
sa.Column('event_id', sa.Integer(), nullable=False),
sa.Column('player_id', sa.BigInteger(), nullable=False),
sa.ForeignKeyConstraint(['event_id'], ['events.id'], ),
sa.ForeignKeyConstraint(['player_id'], ['players.steam_id'], ),
sa.PrimaryKeyConstraint('event_id', 'player_id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('players_events')
op.drop_table('events')
# ### end Alembic commands ###

View File

@ -1,64 +0,0 @@
"""Add surrogate key to player_team and others
Revision ID: 6296c347731b
Revises: 5debac4cdf37
Create Date: 2024-11-21 10:30:09.333087
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '6296c347731b'
down_revision = '5debac4cdf37'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams', schema=None) as batch_op:
batch_op.add_column(sa.Column('player_team_id', sa.Integer(), autoincrement=True, nullable=False))
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.add_column(sa.Column('player_team_id', sa.Integer(), nullable=False))
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'players_teams', ['player_team_id'], ['player_team_id'])
batch_op.drop_column('team_id')
batch_op.drop_column('player_id')
with op.batch_alter_table('players_teams_roles', schema=None) as batch_op:
batch_op.add_column(sa.Column('player_team_role_id', sa.Integer(), autoincrement=True, nullable=False))
batch_op.add_column(sa.Column('player_team_id', sa.Integer(), nullable=False))
batch_op.create_unique_constraint(None, ['player_team_id', 'role'])
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'players_teams', ['player_team_id'], ['player_team_id'])
batch_op.drop_column('team_id')
batch_op.drop_column('player_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.add_column(sa.Column('player_id', sa.INTEGER(), nullable=False))
batch_op.add_column(sa.Column('team_id', sa.INTEGER(), nullable=False))
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'players_teams', ['player_id', 'team_id'], ['player_id', 'team_id'])
batch_op.drop_constraint(None, type_='unique')
batch_op.drop_column('player_team_id')
batch_op.drop_column('player_team_role_id')
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.add_column(sa.Column('player_id', sa.INTEGER(), nullable=False))
batch_op.add_column(sa.Column('team_id', sa.INTEGER(), nullable=False))
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'players_teams', ['player_id', 'team_id'], ['player_id', 'team_id'])
batch_op.drop_column('player_team_id')
with op.batch_alter_table('players_teams', schema=None) as batch_op:
batch_op.drop_column('player_team_id')
# ### end Alembic commands ###

View File

@ -1,35 +0,0 @@
"""Add TeamInvite
Revision ID: 65714d7e78f8
Revises: f50a79c4ae22
Create Date: 2024-11-08 23:16:04.669526
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '65714d7e78f8'
down_revision = 'f50a79c4ae22'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('team_invites',
sa.Column('key', sa.String(length=31), nullable=False),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.Column('delete_on_use', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('key')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('team_invites')
# ### end Alembic commands ###

View File

@ -1,50 +0,0 @@
"""Change player_team surrogate key name
Revision ID: 6e9d70f835d7
Revises: 6296c347731b
Create Date: 2024-11-21 12:13:44.989797
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '6e9d70f835d7'
down_revision = '6296c347731b'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams', schema=None) as batch_op:
batch_op.add_column(sa.Column('id', sa.Integer(), autoincrement=True, nullable=False))
batch_op.drop_column('player_team_id')
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'players_teams', ['player_team_id'], ['id'])
with op.batch_alter_table('players_teams_roles', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'players_teams', ['player_team_id'], ['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.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'players_teams', ['player_team_id'], ['player_team_id'])
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.create_foreign_key(None, 'players_teams', ['player_team_id'], ['player_team_id'])
with op.batch_alter_table('players_teams', schema=None) as batch_op:
batch_op.add_column(sa.Column('player_team_id', sa.INTEGER(), nullable=False))
batch_op.drop_column('id')
# ### end Alembic commands ###

View File

@ -1,40 +0,0 @@
"""Fix integrity
Revision ID: 7361c978e53d
Revises: 6e9d70f835d7
Create Date: 2024-11-21 12:43:01.786598
"""
from alembic import op
import sqlalchemy as sa
import app_db
# revision identifiers, used by Alembic.
revision = '7361c978e53d'
down_revision = '6e9d70f835d7'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams_availability', schema=None, naming_convention=app_db.convention) as batch_op:
batch_op.create_foreign_key(batch_op.f("fk_players_teams_availability_player_team_id_players_teams"), 'players_teams', ['player_team_id'], ['id'])
with op.batch_alter_table('players_teams_roles', schema=None) as batch_op:
batch_op.create_foreign_key(batch_op.f("fk_players_teams_roles_player_team_id_players_teams"), 'players_teams', ['player_team_id'], ['id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams_roles', schema=None, naming_convention=app_db.convention) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
# ### end Alembic commands ###

View File

@ -1,56 +0,0 @@
"""Add the rest of the match tables
Revision ID: 7995474ef2cc
Revises: fda727438444
Create Date: 2024-12-09 16:17:25.518959
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7995474ef2cc'
down_revision = 'fda727438444'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('players_matches',
sa.Column('player_id', sa.BigInteger(), nullable=False),
sa.Column('match_id', sa.Integer(), nullable=False),
sa.Column('kills', sa.Integer(), nullable=False),
sa.Column('deaths', sa.Integer(), nullable=False),
sa.Column('assists', sa.Integer(), nullable=False),
sa.Column('damage', sa.BigInteger(), nullable=False),
sa.Column('damage_taken', sa.BigInteger(), nullable=False),
sa.ForeignKeyConstraint(['match_id'], ['matches.logs_tf_id'], ),
sa.ForeignKeyConstraint(['player_id'], ['players.steam_id'], ),
sa.PrimaryKeyConstraint('player_id', 'match_id')
)
op.create_table('teams_matches',
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('match_id', sa.Integer(), nullable=False),
sa.Column('team_color', sa.String(length=4), nullable=False),
sa.ForeignKeyConstraint(['match_id'], ['matches.logs_tf_id'], ),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('team_id', 'match_id')
)
with op.batch_alter_table('matches', schema=None) as batch_op:
batch_op.add_column(sa.Column('blue_score', sa.Integer(), nullable=False))
batch_op.add_column(sa.Column('red_score', sa.Integer(), nullable=False))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('matches', schema=None) as batch_op:
batch_op.drop_column('red_score')
batch_op.drop_column('blue_score')
op.drop_table('teams_matches')
op.drop_table('players_matches')
# ### end Alembic commands ###

View File

@ -1,35 +0,0 @@
"""Make PlayerTeamAvailability a db.Model
Revision ID: 8ea29cf493f5
Revises: b00632365b58
Create Date: 2024-10-30 22:21:13.718428
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '8ea29cf493f5'
down_revision = 'b00632365b58'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('player_team_availability',
sa.Column('player_id', sa.Integer(), nullable=False),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('start_time', sa.TIMESTAMP(), nullable=False),
sa.Column('end_time', sa.TIMESTAMP(), nullable=False),
sa.ForeignKeyConstraint(['player_id', 'team_id'], ['players_teams.player_id', 'players_teams.team_id'], ),
sa.PrimaryKeyConstraint('player_id', 'team_id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('player_team_availability')
# ### end Alembic commands ###

View File

@ -1,32 +0,0 @@
"""Add team.discord_webhook_url
Revision ID: 958df14798d5
Revises: 062a154a0797
Create Date: 2024-10-31 09:56:43.335627
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '958df14798d5'
down_revision = '062a154a0797'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('teams', schema=None) as batch_op:
batch_op.add_column(sa.Column('discord_webhook_url', sa.String(length=255), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('teams', schema=None) as batch_op:
batch_op.drop_column('discord_webhook_url')
# ### end Alembic commands ###

View File

@ -1,32 +0,0 @@
"""Add auth_session.key
Revision ID: a340b3da0f2a
Revises: 273f73c81783
Create Date: 2024-10-29 23:17:29.296293
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'a340b3da0f2a'
down_revision = '273f73c81783'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('auth_session', schema=None) as batch_op:
batch_op.add_column(sa.Column('key', sa.String(length=31), nullable=False))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('auth_session', schema=None) as batch_op:
batch_op.drop_column('key')
# ### end Alembic commands ###

View File

@ -1,42 +0,0 @@
"""empty message
Revision ID: b00632365b58
Revises: a340b3da0f2a
Create Date: 2024-10-29 23:27:37.306568
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'b00632365b58'
down_revision = 'a340b3da0f2a'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('auth_sessions',
sa.Column('key', sa.String(length=31), nullable=False),
sa.Column('player_id', sa.BigInteger(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.ForeignKeyConstraint(['player_id'], ['players.steam_id'], ),
sa.PrimaryKeyConstraint('key')
)
op.drop_table('auth_session')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('auth_session',
sa.Column('player_id', sa.BIGINT(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.Column('key', sa.VARCHAR(length=31), nullable=False),
sa.ForeignKeyConstraint(['player_id'], ['players.steam_id'], ),
sa.PrimaryKeyConstraint('player_id')
)
op.drop_table('auth_sessions')
# ### end Alembic commands ###

View File

@ -1,32 +0,0 @@
"""Add webhook profile picture
Revision ID: c242e3f99c64
Revises: 286ee26b9e5d
Create Date: 2024-11-27 10:40:39.027786
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'c242e3f99c64'
down_revision = '286ee26b9e5d'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('team_discord_integrations', schema=None) as batch_op:
batch_op.add_column(sa.Column('webhook_bot_profile_picture', sa.String(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('team_discord_integrations', schema=None) as batch_op:
batch_op.drop_column('webhook_bot_profile_picture')
# ### end Alembic commands ###

View File

@ -1,61 +0,0 @@
"""Initial migration
Revision ID: ce676db8c655
Revises:
Create Date: 2024-10-28 17:42:13.639729
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'ce676db8c655'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('players',
sa.Column('steam_id', sa.BigInteger(), nullable=False),
sa.Column('username', sa.String(length=63), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.PrimaryKeyConstraint('steam_id')
)
op.create_table('teams',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('team_name', sa.String(length=63), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('team_name')
)
op.create_table('players_teams',
sa.Column('player_id', sa.BigInteger(), nullable=False),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('team_role', sa.Enum('Player', 'CoachMentor', name='teamrole'), nullable=False),
sa.Column('playtime', sa.Interval(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.ForeignKeyConstraint(['player_id'], ['players.steam_id'], ),
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
sa.PrimaryKeyConstraint('player_id', 'team_id')
)
op.create_table('players_teams_roles',
sa.Column('player_id', sa.Integer(), nullable=False),
sa.Column('team_id', sa.Integer(), nullable=False),
sa.Column('role', sa.Enum('Unknown', 'Scout', 'PocketScout', 'FlankScout', 'Soldier', 'PocketSoldier', 'Roamer', 'Pyro', 'Demoman', 'HeavyWeapons', 'Engineer', 'Medic', 'Sniper', 'Spy', name='role'), nullable=False),
sa.Column('is_main', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['player_id', 'team_id'], ['players_teams.player_id', 'players_teams.team_id'], ),
sa.PrimaryKeyConstraint('player_id', 'team_id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('players_teams_roles')
op.drop_table('players_teams')
op.drop_table('teams')
op.drop_table('players')
# ### end Alembic commands ###

View File

@ -1,50 +0,0 @@
"""Change intervals to integers
Revision ID: d15570037f47
Revises: 7995474ef2cc
Create Date: 2024-12-09 20:16:18.385467
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd15570037f47'
down_revision = '7995474ef2cc'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('matches', schema=None) as batch_op:
batch_op.alter_column('duration',
existing_type=sa.DATETIME(),
type_=sa.Integer(),
existing_nullable=False)
with op.batch_alter_table('players_teams', schema=None) as batch_op:
batch_op.alter_column('playtime',
existing_type=sa.DATETIME(),
type_=sa.Integer(),
existing_nullable=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams', schema=None) as batch_op:
batch_op.alter_column('playtime',
existing_type=sa.Integer(),
type_=sa.DATETIME(),
existing_nullable=False)
with op.batch_alter_table('matches', schema=None) as batch_op:
batch_op.alter_column('duration',
existing_type=sa.Integer(),
type_=sa.DATETIME(),
existing_nullable=False)
# ### end Alembic commands ###

View File

@ -1,38 +0,0 @@
"""Add has_confirmed column
Revision ID: dcf5ffd0ec73
Revises: 2a33f577d655
Create Date: 2024-11-25 09:17:26.892047
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'dcf5ffd0ec73'
down_revision = '2a33f577d655'
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('has_confirmed', sa.Boolean(), nullable=False))
batch_op.alter_column('player_team_role_id',
existing_type=sa.INTEGER(),
nullable=True)
# ### 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.alter_column('player_team_role_id',
existing_type=sa.INTEGER(),
nullable=False)
batch_op.drop_column('has_confirmed')
# ### end Alembic commands ###

View File

@ -1,55 +0,0 @@
"""Add Team.tz_timezone
Revision ID: ea359b0e46d7
Revises: 2b2f3ae2ec7f
Create Date: 2024-11-03 16:53:37.904012
"""
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utc
# revision identifiers, used by Alembic.
revision = 'ea359b0e46d7'
down_revision = '2b2f3ae2ec7f'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.alter_column('start_time',
existing_type=sa.TIMESTAMP(),
type_=sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True),
existing_nullable=False)
batch_op.alter_column('end_time',
existing_type=sa.TIMESTAMP(),
type_=sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True),
existing_nullable=False)
with op.batch_alter_table('teams', schema=None) as batch_op:
batch_op.add_column(sa.Column('tz_timezone', sa.String(length=31), nullable=False, default='Etc/UTC', server_default='0'))
batch_op.add_column(sa.Column('minute_offset', sa.SmallInteger(), nullable=False, default=0, server_default='0'))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('teams', schema=None) as batch_op:
batch_op.drop_column('minute_offset')
batch_op.drop_column('tz_timezone')
with op.batch_alter_table('players_teams_availability', schema=None) as batch_op:
batch_op.alter_column('end_time',
existing_type=sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True),
type_=sa.TIMESTAMP(),
existing_nullable=False)
batch_op.alter_column('start_time',
existing_type=sqlalchemy_utc.sqltypes.UtcDateTime(timezone=True),
type_=sa.TIMESTAMP(),
existing_nullable=False)
# ### end Alembic commands ###

View File

@ -1,32 +0,0 @@
"""Add PlayerTeam.is_team_leader
Revision ID: f50a79c4ae22
Revises: ea359b0e46d7
Create Date: 2024-11-03 17:11:35.956743
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'f50a79c4ae22'
down_revision = 'ea359b0e46d7'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams', schema=None) as batch_op:
batch_op.add_column(sa.Column('is_team_leader', sa.Boolean(), nullable=False, server_default='0'))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('players_teams', schema=None) as batch_op:
batch_op.drop_column('is_team_leader')
# ### end Alembic commands ###

View File

@ -1,28 +0,0 @@
"""Drop integrations tables
Revision ID: f802d763a7b4
Revises: dcf5ffd0ec73
Create Date: 2024-11-25 18:34:08.136071
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'f802d763a7b4'
down_revision = 'dcf5ffd0ec73'
branch_labels = None
depends_on = None
def upgrade():
# drop integrations tables
op.drop_table("team_discord_integrations")
op.drop_table("team_logs_tf_integrations")
op.drop_table("team_integrations")
pass
def downgrade():
pass

View File

@ -1,35 +0,0 @@
"""Add match table
Revision ID: fda727438444
Revises: c242e3f99c64
Create Date: 2024-12-09 12:45:16.974122
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'fda727438444'
down_revision = 'c242e3f99c64'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('matches',
sa.Column('logs_tf_id', sa.Integer(), nullable=False),
sa.Column('logs_tf_title', sa.String(length=255), nullable=False),
sa.Column('duration', sa.Interval(), nullable=False),
sa.Column('match_time', sa.TIMESTAMP(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.PrimaryKeyConstraint('logs_tf_id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('matches')
# ### end Alembic commands ###