Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 628bd5b

Browse files
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
1 parent a9951dd commit 628bd5b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""migrate to glob pattern
2+
3+
Revision ID: 3ec2b4ab569c
4+
Revises: 5e5cd2288147
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] = "5e5cd2288147"
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 types. We need to do this every time we change the matcher types.
25+
# in /muxing/models.py
26+
op.execute(
27+
"""
28+
UPDATE muxes
29+
SET matcher_blob = CONCAT('*', matcher_blob)
30+
WHERE matcher_type LIKE "%filename%" AND matcher_blob LIKE ".%"
31+
"""
32+
)
33+
34+
# Finish transaction
35+
op.execute("COMMIT;")
36+
37+
38+
def downgrade() -> None:
39+
# Begin transaction
40+
op.execute("BEGIN TRANSACTION;")
41+
42+
op.execute(
43+
"""
44+
UPDATE muxes
45+
SET matcher_blob = SUBSTRING(matcher_blob, 2)
46+
WHERE matcher_type LIKE "%filename%" AND matcher_blob LIKE "*%"
47+
"""
48+
)
49+
50+
# Finish transaction
51+
op.execute("COMMIT;")

0 commit comments

Comments
 (0)