Skip to content

Commit

Permalink
Add indexes, unique constraints
Browse files Browse the repository at this point in the history
- Fix typos
- Update sqlalchemy model
  • Loading branch information
whabanks committed Jun 12, 2024
1 parent da56d60 commit e7346fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
6 changes: 3 additions & 3 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,11 @@ def get_users_with_permission(self):
PRECOMPILED_TEMPLATE_NAME = "Pre-compiled PDF"

class TemplateCategories(BaseModel):
__tablename__ = "template_category"
__tablename__ = "template_categories"

id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name_en = db.Column(db.String(255), nullable=False)
name_fr = db.Column(db.String(255), nullable=False)
name_en = db.Column(db.String(255), unique=True, nullable=False)
name_fr = db.Column(db.String(255), unique=True, nullable=False)
description_en = db.Column(db.String(200), nullable=True)
description_fr = db.Column(db.String(200), nullable=True)
sms_process_type = db.Column(db.String(200), nullable=False)
Expand Down
39 changes: 30 additions & 9 deletions migrations/versions/0454_add_template_category.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Revision ID: 0454_add_template_category
Revision ID: 0454_add_template_categories
Revises: 0453_add_callback_failure_email
Create Date: 2024-06-11 13:32:00
"""
Expand All @@ -11,35 +11,54 @@
from alembic import op
from sqlalchemy.dialects import postgresql

revision = "0454_add_template_categories"
down_revision = "0452_set_pgaudit_config"


def upgrade():
op.create_table(
"template_categories",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True, nullable=False),
sa.Column("name_en", sa.String(length=255), nullable=False),
sa.Column("name_fr", sa.String(length=255), nullable=False),
sa.Column("description_en", sa.String(length=255), nullable=True),
sa.Column("description_fr", sa.String(length=255), nullable=True),
sa.Column("sms_process_type", sa.String(length=255), nullable=False),
sa.Column("email_process_type", sa.String(length=255), nullable=False),
sa.Column("hidden", sa.Boolean(), nullable=False),
sa.UniqueConstraint("name_en"),
sa.UniqueConstraint("name_fr")
)

op.add_column(
"templates",
sa.Colum("template_category_id", postgresql.UUID(as_uuid=True), nullable=True)
sa.Column("template_category_id", postgresql.UUID(as_uuid=True), nullable=True)
)
op.create_index(
op.f("ix_template_category_id"),
"templates",
["template_category_id"],
unique=False,
)
op.create_index(
op.f("ix_template_category_id", "templates", ["template_category_id"], unique=False)
op.f("ix_template_categories_name_en"),
"template_categories",
["name_en"],
unique=False,
)
op.create_index(
op.f("ix_template_categories_name_fr"),
"template_categories",
["name_fr"],
unique=False,
)
op.create_foreign_key(
"fk_template_template_categories",
"template",
"template_category",
"templates",
"template_categories",
["template_category_id"],
["id"]
)
op.get_bind()

# Insert the generic Low priority (bulk) category
# op.execute("""
Expand All @@ -49,7 +68,9 @@ def upgrade():
# )

def downgrade():
op.drop_constraint("fk_template_template_category", "templates", type_="foreignkey")
op.drop_constraint("fk_template_template_categories", "templates", type_="foreignkey")
op.drop_index(op.f("ix_template_category_id"), table_name="templates")
op.drop_index(op.f("ix_template_categories_name_en"), table_name="template_categories")
op.drop_index(op.f("ix_template_categories_name_fr"), table_name="template_categories")
op.drop_column("templates", "template_category_id")
op.drop_table("template_category_id")
op.drop_table("template_categories")

0 comments on commit e7346fd

Please sign in to comment.