From c68e16c0834df5c48b9da38e9b27f98ce3762db7 Mon Sep 17 00:00:00 2001 From: Luca Fabbri Date: Wed, 17 Jul 2024 17:03:21 +0200 Subject: [PATCH] db changes and text fixes --- .../18ba95eb351a_messages_by_site_header.py | 33 +++++++++++++++++++ cads_catalogue/database.py | 2 +- cads_catalogue/messages.py | 4 +-- .../Jan/2021-01-example-of-info-active.md | 0 .../2023-01-example-of-archived-critical.md | 0 .../Jan/2023-01-example-warning-active.md | 0 tests/test_10_messages.py | 22 ++++++------- 7 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 alembic/versions/18ba95eb351a_messages_by_site_header.py rename tests/data/cads-messages/portals/{c3s => cds}/2023/Jan/2021-01-example-of-info-active.md (100%) rename tests/data/cads-messages/portals/{c3s => cds}/2023/Jan/2023-01-example-of-archived-critical.md (100%) rename tests/data/cads-messages/portals/{c3s => cds}/2023/Jan/2023-01-example-warning-active.md (100%) diff --git a/alembic/versions/18ba95eb351a_messages_by_site_header.py b/alembic/versions/18ba95eb351a_messages_by_site_header.py new file mode 100644 index 0000000..853790e --- /dev/null +++ b/alembic/versions/18ba95eb351a_messages_by_site_header.py @@ -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), + ) diff --git a/cads_catalogue/database.py b/cads_catalogue/database.py index 2734fe4..fe98d4d 100644 --- a/cads_catalogue/database.py +++ b/cads_catalogue/database.py @@ -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( diff --git a/cads_catalogue/messages.py b/cads_catalogue/messages.py index 100323b..5d16f7f 100644 --- a/cads_catalogue/messages.py +++ b/cads_catalogue/messages.py @@ -181,7 +181,7 @@ 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) @@ -189,7 +189,7 @@ def load_portal_messages( 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) diff --git a/tests/data/cads-messages/portals/c3s/2023/Jan/2021-01-example-of-info-active.md b/tests/data/cads-messages/portals/cds/2023/Jan/2021-01-example-of-info-active.md similarity index 100% rename from tests/data/cads-messages/portals/c3s/2023/Jan/2021-01-example-of-info-active.md rename to tests/data/cads-messages/portals/cds/2023/Jan/2021-01-example-of-info-active.md diff --git a/tests/data/cads-messages/portals/c3s/2023/Jan/2023-01-example-of-archived-critical.md b/tests/data/cads-messages/portals/cds/2023/Jan/2023-01-example-of-archived-critical.md similarity index 100% rename from tests/data/cads-messages/portals/c3s/2023/Jan/2023-01-example-of-archived-critical.md rename to tests/data/cads-messages/portals/cds/2023/Jan/2023-01-example-of-archived-critical.md diff --git a/tests/data/cads-messages/portals/c3s/2023/Jan/2023-01-example-warning-active.md b/tests/data/cads-messages/portals/cds/2023/Jan/2023-01-example-warning-active.md similarity index 100% rename from tests/data/cads-messages/portals/c3s/2023/Jan/2023-01-example-warning-active.md rename to tests/data/cads-messages/portals/cds/2023/Jan/2023-01-example-warning-active.md diff --git a/tests/test_10_messages.py b/tests/test_10_messages.py index 8ecd9d6..579aa93 100644 --- a/tests/test_10_messages.py +++ b/tests/test_10_messages.py @@ -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", }, @@ -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", }, @@ -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", }, @@ -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", }, @@ -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", }, @@ -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", }, @@ -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", }