-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add icp table and use the criteria when scaing for leads
- Loading branch information
Showing
9 changed files
with
308 additions
and
72 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
src/app/db/migrations/versions/2024-09-11_add_icp_table_110d329b0992.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,94 @@ | ||
# type: ignore | ||
"""Add icp table | ||
Revision ID: 110d329b0992 | ||
Revises: 50dc3def711b | ||
Create Date: 2024-09-11 15:57:47.240984+00:00 | ||
""" | ||
from __future__ import annotations | ||
|
||
import warnings | ||
from typing import TYPE_CHECKING | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from advanced_alchemy.types import EncryptedString, EncryptedText, GUID, ORA_JSONB, DateTimeUTC | ||
from sqlalchemy import Text # noqa: F401 | ||
|
||
from app.db.models.custom_types import CompanyCriteriaType, ToolCriteriaType, PersonCriteriaType | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Sequence | ||
|
||
__all__ = ["downgrade", "upgrade", "schema_upgrades", "schema_downgrades", "data_upgrades", "data_downgrades"] | ||
|
||
sa.GUID = GUID | ||
sa.DateTimeUTC = DateTimeUTC | ||
sa.ORA_JSONB = ORA_JSONB | ||
sa.EncryptedString = EncryptedString | ||
sa.EncryptedText = EncryptedText | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "110d329b0992" | ||
down_revision = "50dc3def711b" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
with warnings.catch_warnings(): | ||
warnings.filterwarnings("ignore", category=UserWarning) | ||
with op.get_context().autocommit_block(): | ||
schema_upgrades() | ||
data_upgrades() | ||
|
||
|
||
def downgrade() -> None: | ||
with warnings.catch_warnings(): | ||
warnings.filterwarnings("ignore", category=UserWarning) | ||
with op.get_context().autocommit_block(): | ||
data_downgrades() | ||
schema_downgrades() | ||
|
||
|
||
def schema_upgrades() -> None: | ||
"""schema upgrade migrations go here.""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"icp", | ||
sa.Column("id", sa.GUID(length=16), nullable=False), | ||
sa.Column("company", CompanyCriteriaType(), nullable=True), | ||
sa.Column("tool", ToolCriteriaType(), nullable=True), | ||
sa.Column("person", PersonCriteriaType(), nullable=True), | ||
sa.Column("tenant_id", sa.GUID(length=16), nullable=False), | ||
sa.Column("sa_orm_sentinel", sa.Integer(), nullable=True), | ||
sa.Column("created_at", sa.DateTimeUTC(timezone=True), nullable=False), | ||
sa.Column("updated_at", sa.DateTimeUTC(timezone=True), nullable=False), | ||
sa.ForeignKeyConstraint(["tenant_id"], ["tenant.id"], name=op.f("fk_icp_tenant_id_tenant")), | ||
sa.PrimaryKeyConstraint("id", name=op.f("pk_icp")), | ||
) | ||
with op.batch_alter_table("icp", schema=None) as batch_op: | ||
batch_op.create_index(batch_op.f("ix_icp_person"), ["person"], unique=False) | ||
batch_op.create_index(batch_op.f("ix_icp_tenant_id"), ["tenant_id"], unique=False) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def schema_downgrades() -> None: | ||
"""schema downgrade migrations go here.""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("icp", schema=None) as batch_op: | ||
batch_op.drop_index(batch_op.f("ix_icp_tenant_id")) | ||
batch_op.drop_index(batch_op.f("ix_icp_person")) | ||
|
||
op.drop_table("icp") | ||
# ### end Alembic commands ### | ||
|
||
|
||
def data_upgrades() -> None: | ||
"""Add any optional data upgrade migrations here!""" | ||
|
||
|
||
def data_downgrades() -> None: | ||
"""Add any optional data downgrade migrations here!""" |
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,21 @@ | ||
from __future__ import annotations | ||
|
||
from uuid import UUID | ||
|
||
from advanced_alchemy.base import UUIDAuditBase | ||
from sqlalchemy import String, ForeignKey | ||
from sqlalchemy.dialects.postgresql import JSONB | ||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from app.lib.schema import CompanyCriteria, ToolCriteria, PersonCriteria | ||
from .custom_types import CompanyCriteriaType, ToolCriteriaType, PersonCriteriaType | ||
|
||
|
||
class ICP(UUIDAuditBase): | ||
"""ICP criteria.""" | ||
|
||
__tablename__ = "icp" | ||
company: Mapped[CompanyCriteria] = mapped_column(CompanyCriteriaType, nullable=True) | ||
tool: Mapped[ToolCriteria] = mapped_column(ToolCriteriaType, nullable=True) | ||
person: Mapped[PersonCriteria] = mapped_column(PersonCriteriaType, nullable=True, default="identified", index=True) | ||
tenant_id: Mapped[UUID] = mapped_column(ForeignKey("tenant.id"), nullable=False, index=True) |
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 @@ | ||
"""ICP Controllers.""" |
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.