Skip to content

Commit

Permalink
feat(db): add team and tessera models
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Moreno authored and photonbit committed Oct 21, 2021
1 parent 86c4206 commit 8578050
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
66 changes: 66 additions & 0 deletions giges/models/team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from sqlalchemy import CHAR, ForeignKey, String
from sqlalchemy.orm import relationship

from giges.db import db
from giges.models.mixins import UUIDMixin

team_tessera_association = db.Table(
"team_tessera_association",
db.Model.metadata,
db.Column(
"team_id", CHAR(36), ForeignKey("team.id", name="team_tessera_team_fk")
),
db.Column(
"tessera_id",
CHAR(36),
ForeignKey("tessera.id", name="team_tessera_tessera_fk"),
),
)

team_project_association = db.Table(
"team_project_association",
db.Model.metadata,
db.Column(
"team_id", CHAR(36), ForeignKey("team.id", name="team_project_team_fk")
),
db.Column(
"project_id",
CHAR(36),
ForeignKey("asana_project.id", name="team_project_project_fk"),
),
)


class Team(db.Model, UUIDMixin):

name = db.Column(
String, nullable=False, unique=True, index=True, doc="Name of the team"
)

tesseras = relationship(
"Tessera", secondary=team_tessera_association, back_populates="teams"
)
projects = relationship("Project", secondary=team_project_association)


class Tessera(db.Model, UUIDMixin):

name = db.Column(
String, nullable=False, index=True, doc="Name of the human"
)
asana_id = db.Column(
String, nullable=False, index=True, doc="Asana ID of the tessera"
)
github_handle = db.Column(
String,
nullable=False,
index=True,
doc="User name in Github of this human",
)
slack_id = db.Column(
String, nullable=False, index=True, doc="Slack ID of the tessera"
)

teams = relationship(
"Team", secondary=team_tessera_association, back_populates="tesseras"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""Team and Tessera models
Revision ID: 20c506662a93
Revises: 089ccde49d20
Create Date: 2021-10-06 13:50:48.166391
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "20c506662a93"
down_revision = "089ccde49d20"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"team",
sa.Column("id", sa.CHAR(length=36), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_team_name"), "team", ["name"], unique=True)
op.create_table(
"tessera",
sa.Column("id", sa.CHAR(length=36), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("asana_id", sa.String(), nullable=False),
sa.Column("github_handle", sa.String(), nullable=False),
sa.Column("slack_id", sa.String(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_tessera_asana_id"), "tessera", ["asana_id"], unique=False
)
op.create_index(
op.f("ix_tessera_github_handle"),
"tessera",
["github_handle"],
unique=False,
)
op.create_index(op.f("ix_tessera_name"), "tessera", ["name"], unique=False)
op.create_index(
op.f("ix_tessera_slack_id"), "tessera", ["slack_id"], unique=False
)
op.create_table(
"team_project_association",
sa.Column("team_id", sa.CHAR(length=36), nullable=True),
sa.Column("project_id", sa.CHAR(length=36), nullable=True),
sa.ForeignKeyConstraint(
["project_id"],
["asana_project.id"],
name="team_project_project_fk",
),
sa.ForeignKeyConstraint(
["team_id"], ["team.id"], name="team_project_team_fk"
),
)
op.create_table(
"team_tessera_association",
sa.Column("team_id", sa.CHAR(length=36), nullable=True),
sa.Column("tessera_id", sa.CHAR(length=36), nullable=True),
sa.ForeignKeyConstraint(
["team_id"], ["team.id"], name="team_tessera_team_fk"
),
sa.ForeignKeyConstraint(
["tessera_id"], ["tessera.id"], name="team_tessera_tessera_fk"
),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("team_tessera_association")
op.drop_table("team_project_association")
op.drop_index(op.f("ix_tessera_slack_id"), table_name="tessera")
op.drop_index(op.f("ix_tessera_name"), table_name="tessera")
op.drop_index(op.f("ix_tessera_github_handle"), table_name="tessera")
op.drop_index(op.f("ix_tessera_asana_id"), table_name="tessera")
op.drop_table("tessera")
op.drop_index(op.f("ix_team_name"), table_name="team")
op.drop_table("team")
# ### end Alembic commands ###

0 comments on commit 8578050

Please sign in to comment.