-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
app/db/migrations/versions/08b381fc1bc7_update_shadowsocks_method.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""update_shadowsocks_method | ||
Revision ID: 08b381fc1bc7 | ||
Revises: 0f720f5c54dd | ||
Create Date: 2023-11-03 13:41:57.120379 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
import json | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '08b381fc1bc7' | ||
down_revision = '0f720f5c54dd' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
bind = op.get_bind() | ||
q = bind.execute("SELECT id, settings FROM proxies WHERE type = 'Shadowsocks';") | ||
proxies = q.fetchall() | ||
for pid, settings in proxies: | ||
settings = json.loads(settings) | ||
if settings.get('method') == 'chacha20-poly1305': | ||
new_settings = settings.copy() | ||
new_settings['method'] = 'chacha20-ietf-poly1305' | ||
bind.execute(f"UPDATE proxies SET settings = '{json.dumps(new_settings)}' WHERE id = {pid}") | ||
|
||
|
||
def downgrade() -> None: | ||
bind = op.get_bind() | ||
q = bind.execute("SELECT id, settings FROM proxies WHERE type = 'Shadowsocks';") | ||
proxies = q.fetchall() | ||
for pid, settings in proxies: | ||
settings = json.loads(settings) | ||
if settings.get('method') == 'chacha20-ietf-poly1305': | ||
new_settings = settings.copy() | ||
new_settings['method'] = 'chacha20-poly1305' | ||
bind.execute(f"UPDATE proxies SET settings = '{json.dumps(new_settings)}' WHERE id = {pid}") |