Skip to content

Commit

Permalink
Added ialt text for email_branding table
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbahrai committed Apr 23, 2024
1 parent 522451e commit feb4be8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ class EmailBranding(BaseModel):
UUID(as_uuid=True), db.ForeignKey("organisation.id", ondelete="SET NULL"), index=True, nullable=True
)
organisation = db.relationship("Organisation", back_populates="email_branding", foreign_keys=[organisation_id])
alt_text_en = db.Column(db.String(), nullable=True)
alt_text_fr = db.Column(db.String(), nullable=True)

def serialize(self) -> dict:
serialized = {
Expand All @@ -290,6 +292,8 @@ def serialize(self) -> dict:
"text": self.text,
"brand_type": self.brand_type,
"organisation_id": str(self.organisation_id) if self.organisation_id else "",
"alt_text_en": self.alt_text_en,
"alt_text_fr": self.alt_text_fr,
}

return serialized
Expand Down
35 changes: 35 additions & 0 deletions migrations/versions/0446_add_alt_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Revision ID: 0446_add_alt_text.py
Revises: 0445_add_org_id_branding.py
Create Date: 2024-04-23
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy import text
from sqlalchemy.dialects import postgresql

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'postgresql' is not used.

revision = "0446_add_alt_text"
down_revision = "0445_add_org_id_branding"


def upgrade():
table_description = op.get_bind().execute(
text("SELECT * FROM information_schema.columns WHERE table_name = 'email_branding'")
)

# Check if the column exists
if "alt_text_en" not in [column["column_name"] for column in table_description]:
op.add_column(
"email_branding",
sa.Column("alt_text_en", sa.String(), nullable=True),
)
if "alt_text_fr" not in [column["column_name"] for column in table_description]:
op.add_column(
"email_branding",
sa.Column("alt_text_fr", sa.String(), nullable=True),
)


def downgrade():
op.drop_column("email_branding", "alt_text_fr")
op.drop_column("email_branding", "alt_text_en")

0 comments on commit feb4be8

Please sign in to comment.