-
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 tenant_id to opportunity association tables
- Loading branch information
shri
committed
Aug 13, 2024
1 parent
cee6ed9
commit e078a3b
Showing
2 changed files
with
89 additions
and
7 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/app/db/migrations/versions/2024-08-13_add_tenant_id_to_opportunity__46acf6e88bda.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,81 @@ | ||
# type: ignore | ||
"""Add tenant_id to opportunity association tables | ||
Revision ID: 46acf6e88bda | ||
Revises: 992fa69e02cb | ||
Create Date: 2024-08-13 09:43:48.474750+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 = '46acf6e88bda' | ||
down_revision = '992fa69e02cb' | ||
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_job_post_relation', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('tenant_id', sa.GUID(length=16), nullable=False)) | ||
batch_op.create_foreign_key(batch_op.f('fk_opportunity_job_post_relation_tenant_id_tenant'), 'tenant', ['tenant_id'], ['id'], ondelete='CASCADE') | ||
|
||
with op.batch_alter_table('opportunity_person_relation', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('tenant_id', sa.GUID(length=16), nullable=False)) | ||
batch_op.create_foreign_key(batch_op.f('fk_opportunity_person_relation_tenant_id_tenant'), 'tenant', ['tenant_id'], ['id'], ondelete='CASCADE') | ||
|
||
# ### 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_person_relation', schema=None) as batch_op: | ||
batch_op.drop_constraint(batch_op.f('fk_opportunity_person_relation_tenant_id_tenant'), type_='foreignkey') | ||
batch_op.drop_column('tenant_id') | ||
|
||
with op.batch_alter_table('opportunity_job_post_relation', schema=None) as batch_op: | ||
batch_op.drop_constraint(batch_op.f('fk_opportunity_job_post_relation_tenant_id_tenant'), type_='foreignkey') | ||
batch_op.drop_column('tenant_id') | ||
|
||
# ### 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