From 104282da30c7b9030a17b86ed362095a0fb86146 Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Wed, 13 Nov 2024 16:04:59 -0800 Subject: [PATCH] Add integration models --- ...c9a051a0a6_add_team_integrations_models.py | 41 +++++++++++++++++++ backend-flask/models/team.py | 3 ++ backend-flask/models/team_integration.py | 32 +++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 backend-flask/migrations/versions/1fc9a051a0a6_add_team_integrations_models.py create mode 100644 backend-flask/models/team_integration.py diff --git a/backend-flask/migrations/versions/1fc9a051a0a6_add_team_integrations_models.py b/backend-flask/migrations/versions/1fc9a051a0a6_add_team_integrations_models.py new file mode 100644 index 0000000..53c289a --- /dev/null +++ b/backend-flask/migrations/versions/1fc9a051a0a6_add_team_integrations_models.py @@ -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 ### diff --git a/backend-flask/models/team.py b/backend-flask/models/team.py index 537a9b9..a77a221 100644 --- a/backend-flask/models/team.py +++ b/backend-flask/models/team.py @@ -6,6 +6,7 @@ from sqlalchemy.types import TIMESTAMP, Integer, SmallInteger, String import app_db import spec + class Team(app_db.BaseModel): __tablename__ = "teams" @@ -17,6 +18,7 @@ class Team(app_db.BaseModel): players: Mapped[list["PlayerTeam"]] = 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()) @@ -30,4 +32,5 @@ class TeamSchema(spec.BaseModel): from models.player_team import PlayerTeam +from models.team_integration import TeamIntegration from models.team_invite import TeamInvite diff --git a/backend-flask/models/team_integration.py b/backend-flask/models/team_integration.py new file mode 100644 index 0000000..b48d0c2 --- /dev/null +++ b/backend-flask/models/team_integration.py @@ -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