Skip to content

Commit 072ab9f

Browse files
Add a migration to update previous matchers to glob patterns (#1201)
* 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 * change in concat function to older version * manually changed down revision on migration
1 parent f61f357 commit 072ab9f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""migrate to glob pattern
2+
3+
Revision ID: 3ec2b4ab569c
4+
Revises: 02b710eda156
5+
Create Date: 2025-03-04 09:34:09.966863+00:00
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
from alembic import op
12+
13+
# revision identifiers, used by Alembic.
14+
revision: str = "3ec2b4ab569c"
15+
down_revision: Union[str, None] = "02b710eda156"
16+
branch_labels: Union[str, Sequence[str], None] = None
17+
depends_on: Union[str, Sequence[str], None] = None
18+
19+
20+
def upgrade() -> None:
21+
# Begin transaction
22+
op.execute("BEGIN TRANSACTION;")
23+
24+
# Update the matcher blobs to use glob patterns
25+
op.execute(
26+
"""
27+
UPDATE muxes
28+
SET matcher_blob = '*' || matcher_blob
29+
WHERE matcher_type LIKE "%filename%" AND matcher_blob LIKE ".%"
30+
"""
31+
)
32+
33+
# Finish transaction
34+
op.execute("COMMIT;")
35+
36+
37+
def downgrade() -> None:
38+
# Begin transaction
39+
op.execute("BEGIN TRANSACTION;")
40+
41+
op.execute(
42+
"""
43+
UPDATE muxes
44+
SET matcher_blob = SUBSTRING(matcher_blob, 2)
45+
WHERE matcher_type LIKE "%filename%" AND matcher_blob LIKE "*%"
46+
"""
47+
)
48+
49+
# Finish transaction
50+
op.execute("COMMIT;")

0 commit comments

Comments
 (0)