From 7bdffa6d836ac526b1de13e536d3d26a8d703d68 Mon Sep 17 00:00:00 2001 From: Alejandro Ponce Date: Tue, 4 Mar 2025 11:41:52 +0200 Subject: [PATCH 1/3] Add a migration to update previous matchers to glob patterns On #1193 we put in place code for using glob patterns in muxing. This PR also updates the DB entries --- ...34-3ec2b4ab569c_migrate_to_glob_pattern.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py diff --git a/migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py b/migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py new file mode 100644 index 00000000..8194a6c1 --- /dev/null +++ b/migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py @@ -0,0 +1,51 @@ +"""migrate to glob pattern + +Revision ID: 3ec2b4ab569c +Revises: 5e5cd2288147 +Create Date: 2025-03-04 09:34:09.966863+00:00 + +""" + +from typing import Sequence, Union + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "3ec2b4ab569c" +down_revision: Union[str, None] = "5e5cd2288147" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # Begin transaction + op.execute("BEGIN TRANSACTION;") + + # Update the matcher types. We need to do this every time we change the matcher types. + # in /muxing/models.py + op.execute( + """ + UPDATE muxes + SET matcher_blob = CONCAT('*', matcher_blob) + WHERE matcher_type LIKE "%filename%" AND matcher_blob LIKE ".%" + """ + ) + + # Finish transaction + op.execute("COMMIT;") + + +def downgrade() -> None: + # Begin transaction + op.execute("BEGIN TRANSACTION;") + + op.execute( + """ + UPDATE muxes + SET matcher_blob = SUBSTRING(matcher_blob, 2) + WHERE matcher_type LIKE "%filename%" AND matcher_blob LIKE "*%" + """ + ) + + # Finish transaction + op.execute("COMMIT;") From 74c8d9999bbb73442f6d7d9efb30f6df82236212 Mon Sep 17 00:00:00 2001 From: Alejandro Ponce Date: Tue, 4 Mar 2025 13:40:23 +0200 Subject: [PATCH 2/3] change in concat function to older version --- .../2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py b/migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py index 8194a6c1..21726ee2 100644 --- a/migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py +++ b/migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py @@ -21,12 +21,11 @@ def upgrade() -> None: # Begin transaction op.execute("BEGIN TRANSACTION;") - # Update the matcher types. We need to do this every time we change the matcher types. - # in /muxing/models.py + # Update the matcher blobs to use glob patterns op.execute( """ UPDATE muxes - SET matcher_blob = CONCAT('*', matcher_blob) + SET matcher_blob = '*' || matcher_blob WHERE matcher_type LIKE "%filename%" AND matcher_blob LIKE ".%" """ ) From 1387040935c255098be422582d13d16826a4d59f Mon Sep 17 00:00:00 2001 From: Alejandro Ponce Date: Tue, 4 Mar 2025 13:45:01 +0200 Subject: [PATCH 3/3] manually changed down revision on migration --- .../2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py b/migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py index 21726ee2..9f090d1c 100644 --- a/migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py +++ b/migrations/versions/2025_03_04_0934-3ec2b4ab569c_migrate_to_glob_pattern.py @@ -1,7 +1,7 @@ """migrate to glob pattern Revision ID: 3ec2b4ab569c -Revises: 5e5cd2288147 +Revises: 02b710eda156 Create Date: 2025-03-04 09:34:09.966863+00:00 """ @@ -12,7 +12,7 @@ # revision identifiers, used by Alembic. revision: str = "3ec2b4ab569c" -down_revision: Union[str, None] = "5e5cd2288147" +down_revision: Union[str, None] = "02b710eda156" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None