Skip to content

Commit

Permalink
db changes and text fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
keul committed Jul 17, 2024
1 parent 2a88c3e commit c68e16c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 14 deletions.
33 changes: 33 additions & 0 deletions alembic/versions/18ba95eb351a_messages_by_site_header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""messages by SITE header.
Revision ID: 18ba95eb351a
Revises: 63827287c182
Create Date: 2024-07-15 17:08:21.290858
"""

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "18ba95eb351a"
down_revision = "63827287c182"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.drop_column("messages", "portal")
op.add_column(
"messages",
sa.Column("site", sa.String, index=True),
)


def downgrade() -> None:
op.drop_column("messages", "site")
op.add_column(
"messages",
sa.Column("portal", sa.String, index=True),
)
2 changes: 1 addition & 1 deletion cads_catalogue/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Message(BaseModel):
message_id = sa.Column(sa.Integer, primary_key=True)
message_uid = sa.Column(sa.String, index=True, unique=True, nullable=False)
date = sa.Column(sa.DateTime, nullable=False)
portal = sa.Column(sa.String, index=True)
site = sa.Column(sa.String, index=True)
summary = sa.Column(sa.String, nullable=True)
url = sa.Column(sa.String)
severity = sa.Column(
Expand Down
4 changes: 2 additions & 2 deletions cads_catalogue/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ def load_portal_messages(
List of found messages parsed.
"""
loaded_messages: List[dict[str, Any]] = []
portal = os.path.basename(portal_folder)
site = os.path.basename(portal_folder)
for current_root, dirs, files in os.walk(portal_folder):
for current_file in files:
file_path = os.path.join(current_root, current_file)
if os.path.splitext(current_file)[1].lower() == ".md":
msg_uid = os.path.relpath(file_path, root_msg_folder)
try:
msg_record = md2message_record(
file_path, msg_uid, is_global=True, portal=portal
file_path, msg_uid, is_global=True, site=site
)
except: # noqa
logger.exception("error loading message %r" % file_path)
Expand Down
22 changes: 11 additions & 11 deletions tests/test_10_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_load_messages() -> None:
"entries": [],
"is_global": True,
"live": True,
"message_uid": "portals/c3s/2023/Jan/2021-01-example-of-info-active.md",
"portal": "c3s",
"message_uid": "portals/cds/2023/Jan/2021-01-example-of-info-active.md",
"site": "cds",
"severity": "info",
"summary": "a summary of the message",
},
Expand Down Expand Up @@ -78,8 +78,8 @@ def test_load_messages() -> None:
"entries": [],
"is_global": True,
"live": False,
"message_uid": "portals/c3s/2023/Jan/2023-01-example-of-archived-critical.md",
"portal": "c3s",
"message_uid": "portals/cds/2023/Jan/2023-01-example-of-archived-critical.md",
"site": "cds",
"severity": "critical",
"summary": "A **brief description** of the message",
},
Expand All @@ -91,8 +91,8 @@ def test_load_messages() -> None:
"entries": [],
"is_global": True,
"live": True,
"message_uid": "portals/c3s/2023/Jan/2023-01-example-warning-active.md",
"portal": "c3s",
"message_uid": "portals/cds/2023/Jan/2023-01-example-warning-active.md",
"site": "cds",
"severity": "warning",
"summary": "A **brief description** of the message",
},
Expand All @@ -106,7 +106,7 @@ def test_load_messages() -> None:
"is_global": True,
"live": True,
"message_uid": "portals/ads/2023/02/2021-02-example-of-info-active.md",
"portal": "ads",
"site": "ads",
"severity": "info",
"summary": "a summary of the message",
},
Expand All @@ -119,7 +119,7 @@ def test_load_messages() -> None:
"is_global": True,
"live": False,
"message_uid": "portals/ads/2023/02/2023-02-example-of-archived-critical.md",
"portal": "ads",
"site": "ads",
"severity": "critical",
"summary": "A **brief description** of the message",
},
Expand All @@ -132,7 +132,7 @@ def test_load_messages() -> None:
"is_global": True,
"live": True,
"message_uid": "portals/ads/2023/02/2023-02-example-warning-active.md",
"portal": "ads",
"site": "ads",
"severity": "warning",
"summary": "A **brief description** of the message",
},
Expand Down Expand Up @@ -163,8 +163,8 @@ def test_message_sync(session_obj: sa.orm.sessionmaker) -> None:
"entries": [],
"is_global": True,
"live": False,
"message_uid": "portals/c3s/2023/Jan/2023-01-example-of-archived-critical.md",
"portal": "portal2",
"message_uid": "portals/cds/2023/Jan/2023-01-example-of-archived-critical.md",
"site": "site2",
"severity": "success",
"summary": "A **brief description** of the message",
}
Expand Down

0 comments on commit c68e16c

Please sign in to comment.