feat(db): increase length of the host and sni columns (#1505)

* feat(db): increase length of the host and sni columns

* remove unnesserly code
This commit is contained in:
Mohammad
2024-12-12 20:45:45 +03:30
committed by GitHub
parent dab0cdbbf7
commit 8f662d417c
2 changed files with 67 additions and 11 deletions

View File

@@ -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)

View File

@@ -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,