forked from Gozargah/Marzban
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Gozargah/dev
Dev
- Loading branch information
Showing
36 changed files
with
1,036 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
app/db/migrations/versions/305943d779c4_add_h3_to_alpn_enum.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
"""add h3 to alpn enum | ||
Revision ID: 305943d779c4 | ||
Revises: 31f92220c0d0 | ||
Create Date: 2024-07-03 19:27:15.282711 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '305943d779c4' | ||
down_revision = '31f92220c0d0' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
# Describing of enum | ||
enum_name = "alpn" | ||
temp_enum_name = f"temp_{enum_name}" | ||
old_values = ("none", "h2", "http/1.1", "h2,http/1.1") | ||
new_values = ("h3", "h3,h2", "h3,h2,http/1.1", *old_values) | ||
# on downgrade | ||
downgrade_from = ("h3", "h3,h2", "h3,h2,http/1.1", "") | ||
downgrade_to = "none" | ||
old_type = sa.Enum(*old_values, name=enum_name) | ||
new_type = sa.Enum(*new_values, name=enum_name) | ||
temp_type = sa.Enum(*new_values, name=temp_enum_name) | ||
|
||
|
||
# Describing of table | ||
table_name = "hosts" | ||
column_name = "alpn" | ||
temp_table = sa.sql.table( | ||
table_name, | ||
sa.Column( | ||
column_name, | ||
new_type, | ||
nullable=False | ||
) | ||
) | ||
|
||
|
||
def upgrade(): | ||
# temp type to use instead of old one | ||
temp_type.create(op.get_bind(), checkfirst=False) | ||
|
||
# changing of column type from old enum to new one. | ||
# SQLite will create temp table for this | ||
with op.batch_alter_table(table_name) as batch_op: | ||
batch_op.alter_column( | ||
column_name, | ||
existing_type=old_type, | ||
type_=temp_type, | ||
existing_nullable=False, | ||
postgresql_using=f"{column_name}::text::{temp_enum_name}" | ||
) | ||
|
||
# remove old enum, create new enum | ||
old_type.drop(op.get_bind(), checkfirst=False) | ||
new_type.create(op.get_bind(), checkfirst=False) | ||
|
||
# changing of column type from temp enum to new one. | ||
# SQLite will create temp table for this | ||
with op.batch_alter_table(table_name) as batch_op: | ||
batch_op.alter_column( | ||
column_name, | ||
existing_type=temp_type, | ||
type_=new_type, | ||
existing_nullable=False, | ||
postgresql_using=f"{column_name}::text::{enum_name}" | ||
) | ||
|
||
# remove temp enum | ||
temp_type.drop(op.get_bind(), checkfirst=False) | ||
|
||
|
||
def downgrade(): | ||
# old enum don't have new value anymore. | ||
# before downgrading from new enum to old one, | ||
# we should replace new value from new enum with | ||
# somewhat of old values from old enum | ||
update_query = ( | ||
temp_table | ||
.update() | ||
.where(temp_table.c.alpn.in_(downgrade_from)) | ||
.values(alpn=downgrade_to) | ||
) | ||
op.execute(update_query) | ||
|
||
temp_type.create(op.get_bind(), checkfirst=False) | ||
|
||
with op.batch_alter_table(table_name) as batch_op: | ||
batch_op.alter_column( | ||
column_name, | ||
existing_type=new_type, | ||
type_=temp_type, | ||
existing_nullable=False, | ||
postgresql_using=f"{column_name}::text::{temp_enum_name}" | ||
) | ||
|
||
new_type.drop(op.get_bind(), checkfirst=False) | ||
old_type.create(op.get_bind(), checkfirst=False) | ||
|
||
with op.batch_alter_table(table_name) as batch_op: | ||
batch_op.alter_column( | ||
column_name, | ||
existing_type=temp_type, | ||
type_=old_type, | ||
existing_nullable=False, | ||
postgresql_using=f"{column_name}::text::{enum_name}" | ||
) | ||
|
||
temp_type.drop(op.get_bind(), checkfirst=False) |
28 changes: 28 additions & 0 deletions
28
app/db/migrations/versions/31f92220c0d0_add_support_random_user_agent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Add Support Random User-Agent | ||
Revision ID: 31f92220c0d0 | ||
Revises: 4f045f53bef8 | ||
Create Date: 2024-06-01 21:28:33.310627 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '31f92220c0d0' | ||
down_revision = '4f045f53bef8' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('hosts', sa.Column('random_user_agent', sa.Boolean(), server_default='0', nullable=False)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('hosts', 'random_user_agent') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.