Skip to content

Commit

Permalink
Make opportunity notes nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
shrir committed Nov 14, 2024
1 parent b4993b5 commit f57341c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# type: ignore
"""Make opportunity notes nullable
Revision ID: 6ced0484784f
Revises: 1183d2e97141
Create Date: 2024-11-14 08:37:44.453376+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

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 = '6ced0484784f'
down_revision = '1183d2e97141'
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! ###
with op.batch_alter_table('opportunity', schema=None) as batch_op:
batch_op.alter_column('notes',
existing_type=sa.TEXT(),
nullable=True)

# ### end Alembic commands ###

def schema_downgrades() -> None:
"""schema downgrade migrations go here."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('opportunity', schema=None) as batch_op:
batch_op.alter_column('notes',
existing_type=sa.TEXT(),
nullable=False)

# ### 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!"""
2 changes: 1 addition & 1 deletion src/app/db/models/opportunity.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Opportunity(UUIDAuditBase, SlugKey):
stage: Mapped[OpportunityStage] = mapped_column(
OpportunityStageType, nullable=False, default="identified", index=True
)
notes: Mapped[str] = mapped_column(Text, nullable=False, default="")
notes: Mapped[str] = mapped_column(Text, nullable=True)
context: Mapped[OpportunityContext | None] = mapped_column(OpportunityContextType, nullable=True, default={})
tenant_id: Mapped[UUID] = mapped_column(ForeignKey("tenant.id"), nullable=False, index=True)
owner_id: Mapped[UUID] = mapped_column(ForeignKey("user_account.id"), nullable=True, default=None, index=True)
Expand Down
2 changes: 1 addition & 1 deletion src/app/domain/opportunities/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Opportunity(CamelizedBaseStruct):
created_at: datetime
updated_at: datetime
stage: OpportunityStage
notes: str
notes: str | None = None
context: OpportunityContext | None = None
owner: User | None = None
company: Company | None = None
Expand Down

0 comments on commit f57341c

Please sign in to comment.