Skip to content

Commit

Permalink
feat(db): increase length of the host and sni columns (#1505)
Browse files Browse the repository at this point in the history
* feat(db): increase length of the host and sni columns

* remove unnesserly code
  • Loading branch information
ImMohammad20000 authored Dec 12, 2024
1 parent dab0cdb commit 8f662d4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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)
37 changes: 26 additions & 11 deletions app/db/models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8f662d4

Please sign in to comment.