Skip to content

Commit

Permalink
fix: shadowsocks method in database
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintShit committed Nov 3, 2023
1 parent d55bfcc commit 55facaa
Showing 1 changed file with 40 additions and 0 deletions.
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}")

0 comments on commit 55facaa

Please sign in to comment.