Add integration models
parent
325b3529fe
commit
104282da30
|
@ -0,0 +1,41 @@
|
||||||
|
"""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 ###
|
|
@ -6,6 +6,7 @@ from sqlalchemy.types import TIMESTAMP, Integer, SmallInteger, String
|
||||||
import app_db
|
import app_db
|
||||||
import spec
|
import spec
|
||||||
|
|
||||||
|
|
||||||
class Team(app_db.BaseModel):
|
class Team(app_db.BaseModel):
|
||||||
__tablename__ = "teams"
|
__tablename__ = "teams"
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ class Team(app_db.BaseModel):
|
||||||
|
|
||||||
players: Mapped[list["PlayerTeam"]] = relationship(back_populates="team")
|
players: Mapped[list["PlayerTeam"]] = relationship(back_populates="team")
|
||||||
invites: Mapped[list["TeamInvite"]] = relationship(back_populates="team")
|
invites: Mapped[list["TeamInvite"]] = relationship(back_populates="team")
|
||||||
|
integrations: Mapped[list["TeamIntegration"]] = relationship(back_populates="team")
|
||||||
|
|
||||||
created_at: Mapped[datetime] = mapped_column(TIMESTAMP, server_default=func.now())
|
created_at: Mapped[datetime] = mapped_column(TIMESTAMP, server_default=func.now())
|
||||||
|
|
||||||
|
@ -30,4 +32,5 @@ class TeamSchema(spec.BaseModel):
|
||||||
|
|
||||||
|
|
||||||
from models.player_team import PlayerTeam
|
from models.player_team import PlayerTeam
|
||||||
|
from models.team_integration import TeamIntegration
|
||||||
from models.team_invite import TeamInvite
|
from models.team_invite import TeamInvite
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
from sqlalchemy.orm import mapped_column, relationship
|
||||||
|
from sqlalchemy.orm.attributes import Mapped
|
||||||
|
from sqlalchemy.orm.properties import ForeignKey
|
||||||
|
from sqlalchemy.types import Integer, String
|
||||||
|
import app_db
|
||||||
|
|
||||||
|
|
||||||
|
class TeamIntegration(app_db.BaseModel):
|
||||||
|
__tablename__ = "team_integrations"
|
||||||
|
|
||||||
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
team_id: Mapped[int] = mapped_column(Integer, ForeignKey("teams.id"))
|
||||||
|
integration_type: Mapped[str]
|
||||||
|
|
||||||
|
team: Mapped["Team"] = relationship(back_populates="integrations")
|
||||||
|
|
||||||
|
__mapper_args__ = {
|
||||||
|
"polymorphic_identity": "team_integrations",
|
||||||
|
"polymorphic_on": "integration_type",
|
||||||
|
}
|
||||||
|
|
||||||
|
class TeamDiscordIntegration(TeamIntegration):
|
||||||
|
__tablename__ = "team_discord_integrations"
|
||||||
|
|
||||||
|
integration_id: Mapped[int] = mapped_column(ForeignKey("team_integrations.id"), primary_key=True)
|
||||||
|
webhook_url: Mapped[str] = mapped_column(String(255))
|
||||||
|
|
||||||
|
__mapper_args__ = {
|
||||||
|
"polymorphic_identity": "team_discord_integrations",
|
||||||
|
}
|
||||||
|
|
||||||
|
from models.team import Team
|
Loading…
Reference in New Issue