Add Event and PlayerEvent models
parent
436359594b
commit
22040f47a0
|
@ -0,0 +1,36 @@
|
|||
"""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 ###
|
|
@ -0,0 +1,23 @@
|
|||
from datetime import datetime
|
||||
from sqlalchemy.orm import mapped_column, relationship
|
||||
from sqlalchemy.orm.attributes import Mapped
|
||||
from sqlalchemy.types import TIMESTAMP, Integer, String, Text
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy_utc import UtcDateTime
|
||||
import app_db
|
||||
|
||||
|
||||
class Event(app_db.BaseModel):
|
||||
__tablename__ = "events"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, autoincrement=True, primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
description: Mapped[str] = mapped_column(Text, nullable=True)
|
||||
start_time: Mapped[datetime] = mapped_column(UtcDateTime, nullable=False)
|
||||
team_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(TIMESTAMP, server_default=func.now())
|
||||
|
||||
team: Mapped["Team"] = relationship("Team", back_populates="events")
|
||||
|
||||
|
||||
from models.team import Team
|
|
@ -0,0 +1,18 @@
|
|||
from sqlalchemy.orm import mapped_column, relationship
|
||||
from sqlalchemy.orm.attributes import Mapped
|
||||
from sqlalchemy.orm.properties import ForeignKey
|
||||
import app_db
|
||||
|
||||
|
||||
class PlayerEvent(app_db.BaseModel):
|
||||
__tablename__ = "players_events"
|
||||
|
||||
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)
|
||||
|
||||
event: Mapped["Event"] = relationship("Event", back_populates="players")
|
||||
player: Mapped["Player"] = relationship("Player", back_populates="events")
|
||||
|
||||
|
||||
from models.event import Event
|
||||
from models.player import Player
|
Loading…
Reference in New Issue