Skip to content

Commit

Permalink
fix(db): noise settings migration (#1352)
Browse files Browse the repository at this point in the history
* fix:(db) noise settings migration

* fix(db): set character limit to 2000 for sqlite
  • Loading branch information
M03ED authored Oct 11, 2024
1 parent a556c49 commit e7277de
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
32 changes: 32 additions & 0 deletions app/db/migrations/versions/2ea33513efc0_noise_for_sqlite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""noise for sqlite
Revision ID: 2ea33513efc0
Revises: a9cfd5611a82
Create Date: 2024-10-11 15:36:32.096594
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '2ea33513efc0'
down_revision = 'a9cfd5611a82'
branch_labels = None
depends_on = None


def upgrade() -> None:
bind = op.get_bind()

if bind.engine.name == 'sqlite':
with op.batch_alter_table('hosts') as batch_op:
batch_op.alter_column('noise_setting',
existing_type=sa.String(length=2000),
nullable=True)


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('hosts', sa.Column('noise_setting', sa.String(), nullable=True))
op.add_column('hosts', sa.Column('noise_setting', sa.String(length=2000), nullable=True))
# ### end Alembic commands ###


Expand Down
2 changes: 1 addition & 1 deletion app/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class ProxyHost(Base):
is_disabled = Column(Boolean, nullable=True, default=False)
mux_enable = Column(Boolean, nullable=False, default=False, server_default='0')
fragment_setting = Column(String(100), nullable=True)
noise_setting = Column(String(), nullable=True)
noise_setting = Column(String(2000), nullable=True)
random_user_agent = Column(Boolean, nullable=False, default=False, server_default='0')


Expand Down
4 changes: 4 additions & 0 deletions app/models/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ def validate_noise(cls, v):
raise ValueError(
"Noise setting must be like this: packet,delay (rand:10-20,100-200)."
)
if len(v) > 2000:
raise ValueError(
"Noise can't be longer that 2000 character"
)
return v


Expand Down

0 comments on commit e7277de

Please sign in to comment.