-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/retry
- Loading branch information
Showing
8 changed files
with
296 additions
and
4 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
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
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,46 @@ | ||
from sqlalchemy import Column, ForeignKey, Integer, Numeric | ||
from sqlalchemy.ext.associationproxy import association_proxy | ||
from sqlalchemy.orm import relationship | ||
from typing import List, Optional | ||
|
||
from dispatch.database.core import Base | ||
from dispatch.case_cost_type.models import CaseCostTypeRead | ||
from dispatch.models import DispatchBase, Pagination, PrimaryKey, ProjectMixin, TimeStampMixin | ||
from dispatch.project.models import ProjectRead | ||
|
||
|
||
# SQLAlchemy Model | ||
class CaseCost(Base, TimeStampMixin, ProjectMixin): | ||
# columns | ||
id = Column(Integer, primary_key=True) | ||
amount = Column(Numeric(precision=10, scale=2), nullable=True) | ||
|
||
# relationships | ||
case_cost_type = relationship("CaseCostType", backref="case_cost") | ||
case_cost_type_id = Column(Integer, ForeignKey("case_cost_type.id")) | ||
case_id = Column(Integer, ForeignKey("case.id", ondelete="CASCADE")) | ||
search_vector = association_proxy("case_cost_type", "search_vector") | ||
|
||
|
||
# Pydantic Models | ||
class CaseCostBase(DispatchBase): | ||
amount: float = 0 | ||
|
||
|
||
class CaseCostCreate(CaseCostBase): | ||
case_cost_type: CaseCostTypeRead | ||
project: ProjectRead | ||
|
||
|
||
class CaseCostUpdate(CaseCostBase): | ||
id: Optional[PrimaryKey] = None | ||
case_cost_type: CaseCostTypeRead | ||
|
||
|
||
class CaseCostRead(CaseCostBase): | ||
id: PrimaryKey | ||
case_cost_type: CaseCostTypeRead | ||
|
||
|
||
class CaseCostPagination(Pagination): | ||
items: List[CaseCostRead] = [] |
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 datetime import datetime | ||
from typing import List, Optional | ||
from pydantic import Field | ||
|
||
from sqlalchemy import Column, Integer, String, Boolean | ||
from sqlalchemy.event import listen | ||
|
||
from sqlalchemy_utils import TSVectorType, JSONType | ||
|
||
from dispatch.database.core import Base, ensure_unique_default_per_project | ||
from dispatch.models import ( | ||
DispatchBase, | ||
NameStr, | ||
ProjectMixin, | ||
TimeStampMixin, | ||
Pagination, | ||
PrimaryKey, | ||
) | ||
from dispatch.project.models import ProjectRead | ||
|
||
|
||
# SQLAlchemy Model | ||
class CaseCostType(Base, TimeStampMixin, ProjectMixin): | ||
# columns | ||
id = Column(Integer, primary_key=True) | ||
name = Column(String) | ||
description = Column(String) | ||
category = Column(String) | ||
details = Column(JSONType, nullable=True) | ||
default = Column(Boolean, default=False) | ||
editable = Column(Boolean, default=True) | ||
|
||
# full text search capabilities | ||
search_vector = Column( | ||
TSVectorType("name", "description", weights={"name": "A", "description": "B"}) | ||
) | ||
|
||
|
||
listen(CaseCostType.default, "set", ensure_unique_default_per_project) | ||
|
||
|
||
# Pydantic Models | ||
class CaseCostTypeBase(DispatchBase): | ||
name: NameStr | ||
description: Optional[str] = Field(None, nullable=True) | ||
category: Optional[str] = Field(None, nullable=True) | ||
details: Optional[dict] = {} | ||
created_at: Optional[datetime] | ||
default: Optional[bool] | ||
editable: Optional[bool] | ||
|
||
|
||
class CaseCostTypeCreate(CaseCostTypeBase): | ||
project: ProjectRead | ||
|
||
|
||
class CaseCostTypeUpdate(CaseCostTypeBase): | ||
id: PrimaryKey = None | ||
|
||
|
||
class CaseCostTypeRead(CaseCostTypeBase): | ||
id: PrimaryKey | ||
|
||
|
||
class CaseCostTypePagination(Pagination): | ||
items: List[CaseCostTypeRead] = [] |
80 changes: 80 additions & 0 deletions
80
src/dispatch/database/revisions/tenant/versions/2024-06-28_15a8d3228123.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,80 @@ | ||
"""empty message | ||
Revision ID: 15a8d3228123 | ||
Revises: 4286dcce0a2d | ||
Create Date: 2024-06-28 11:19:27.227089 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlalchemy_utils | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "15a8d3228123" | ||
down_revision = "4286dcce0a2d" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"case_cost_type", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("name", sa.String(), nullable=True), | ||
sa.Column("description", sa.String(), nullable=True), | ||
sa.Column("category", sa.String(), nullable=True), | ||
sa.Column("details", sqlalchemy_utils.types.json.JSONType(), nullable=True), | ||
sa.Column("default", sa.Boolean(), nullable=True), | ||
sa.Column("editable", sa.Boolean(), nullable=True), | ||
sa.Column("search_vector", sqlalchemy_utils.types.ts_vector.TSVectorType(), nullable=True), | ||
sa.Column("project_id", sa.Integer(), nullable=True), | ||
sa.Column("updated_at", sa.DateTime(), nullable=True), | ||
sa.Column("created_at", sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint(["project_id"], ["project.id"], ondelete="CASCADE"), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.create_index( | ||
"case_cost_type_search_vector_idx", | ||
"case_cost_type", | ||
["search_vector"], | ||
unique=False, | ||
postgresql_using="gin", | ||
) | ||
op.create_table( | ||
"case_cost", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("amount", sa.Numeric(precision=10, scale=2), nullable=True), | ||
sa.Column("case_cost_type_id", sa.Integer(), nullable=True), | ||
sa.Column("case_id", sa.Integer(), nullable=True), | ||
sa.Column("project_id", sa.Integer(), nullable=True), | ||
sa.Column("updated_at", sa.DateTime(), nullable=True), | ||
sa.Column("created_at", sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["case_cost_type_id"], | ||
["case_cost_type.id"], | ||
), | ||
sa.ForeignKeyConstraint(["case_id"], ["case.id"], ondelete="CASCADE"), | ||
sa.ForeignKeyConstraint(["project_id"], ["project.id"], ondelete="CASCADE"), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.add_column("case_type", sa.Column("cost_model_id", sa.Integer(), nullable=True)) | ||
op.create_foreign_key(None, "case_type", "cost_model", ["cost_model_id"], ["id"]) | ||
op.add_column("participant_activity", sa.Column("case_id", sa.Integer(), nullable=True)) | ||
op.create_foreign_key(None, "participant_activity", "case", ["case_id"], ["id"]) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_constraint(None, "participant_activity", type_="foreignkey") | ||
op.drop_column("participant_activity", "case_id") | ||
op.drop_constraint(None, "case_type", type_="foreignkey") | ||
op.drop_column("case_type", "cost_model_id") | ||
op.drop_table("case_cost") | ||
op.drop_index( | ||
"case_cost_type_search_vector_idx", table_name="case_cost_type", postgresql_using="gin" | ||
) | ||
op.drop_table("case_cost_type") | ||
# ### end Alembic commands ### |
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
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
Oops, something went wrong.