From 8f662d417c3f846fed43403c18ba2b1973979a7c Mon Sep 17 00:00:00 2001 From: Mohammad Date: Thu, 12 Dec 2024 20:45:45 +0330 Subject: [PATCH] feat(db): increase length of the host and sni columns (#1505) * feat(db): increase length of the host and sni columns * remove unnesserly code --- ...b4_increase_length_of_the_host_and_sni_.py | 41 +++++++++++++++++++ app/db/models.py | 37 ++++++++++++----- 2 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 app/db/migrations/versions/e7b869e999b4_increase_length_of_the_host_and_sni_.py diff --git a/app/db/migrations/versions/e7b869e999b4_increase_length_of_the_host_and_sni_.py b/app/db/migrations/versions/e7b869e999b4_increase_length_of_the_host_and_sni_.py new file mode 100644 index 000000000..4d55b674b --- /dev/null +++ b/app/db/migrations/versions/e7b869e999b4_increase_length_of_the_host_and_sni_.py @@ -0,0 +1,41 @@ +"""increase length of the host and sni columns + +Revision ID: e7b869e999b4 +Revises: be0c5f840473 +Create Date: 2024-12-12 15:41:55.487859 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = 'e7b869e999b4' +down_revision = 'be0c5f840473' +branch_labels = None +depends_on = None + + +def upgrade(): + # Increase the length of 'sni' and 'host' columns to 1000 + with op.batch_alter_table('hosts') as batch_op: + batch_op.alter_column('host', + existing_type=sa.String(length=256), + type_=sa.String(length=1000), + nullable=True) + batch_op.alter_column('sni', + existing_type=sa.String(length=256), + type_=sa.String(length=1000), + nullable=True) + + +def downgrade(): + # Revert the column lengths back to their original size + with op.batch_alter_table('hosts') as batch_op: + batch_op.alter_column('host', + existing_type=sa.String(length=1000), + type_=sa.String(length=256), + nullable=True) + batch_op.alter_column('sni', + existing_type=sa.String(length=1000), + type_=sa.String(length=256), + nullable=True) diff --git a/app/db/models.py b/app/db/models.py index fe1f70f9b..f29d10296 100644 --- a/app/db/models.py +++ b/app/db/models.py @@ -1,20 +1,35 @@ import os from datetime import datetime -from sqlalchemy import (JSON, BigInteger, Boolean, Column, DateTime, Enum, - Float, ForeignKey, Integer, String, Table, - UniqueConstraint, func) +from sqlalchemy import ( + JSON, + BigInteger, + Boolean, + Column, + DateTime, + Enum, + Float, + ForeignKey, + Integer, + String, + Table, + UniqueConstraint, + func, +) from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import relationship -from sqlalchemy.sql.expression import text, select +from sqlalchemy.sql.expression import select, text from app import xray from app.db.base import Base from app.models.node import NodeStatus -from app.models.proxy import (ProxyHostALPN, ProxyHostFingerprint, - ProxyHostSecurity, ProxyTypes) -from app.models.user import (ReminderType, UserDataLimitResetStrategy, - UserStatus) +from app.models.proxy import ( + ProxyHostALPN, + ProxyHostFingerprint, + ProxyHostSecurity, + ProxyTypes, +) +from app.models.user import ReminderType, UserDataLimitResetStrategy, UserStatus class Admin(Base): @@ -79,7 +94,7 @@ class User(Base): edit_at = Column(DateTime, nullable=True, default=None) last_status_change = Column(DateTime, default=datetime.utcnow, nullable=True) - + next_plan = relationship( "NextPlan", uselist=False, @@ -217,8 +232,8 @@ class ProxyHost(Base): address = Column(String(256), unique=False, nullable=False) port = Column(Integer, nullable=True) path = Column(String(256), unique=False, nullable=True) - sni = Column(String(256), unique=False, nullable=True) - host = Column(String(256), unique=False, nullable=True) + sni = Column(String(1000), unique=False, nullable=True) + host = Column(String(1000), unique=False, nullable=True) security = Column( Enum(ProxyHostSecurity), unique=False,