-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db): add team and tessera models
- Loading branch information
Showing
2 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
87 changes: 87 additions & 0 deletions
87
migrations/versions/202110061350_20c506662a93_team_and_tessera_models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ### |