| 1 |
4056c66 |
Dawsh |
1y ago |
"""unbound host |
| 2 |
4056c66 |
Dawsh |
1y ago |
|
| 3 |
4056c66 |
Dawsh |
1y ago |
Revision ID: 57eba0a293f2 |
| 4 |
4056c66 |
Dawsh |
1y ago |
Revises: 982867b533e6 |
| 5 |
4056c66 |
Dawsh |
1y ago |
Create Date: 2024-12-18 20:22:11.860923 |
| 6 |
4056c66 |
Dawsh |
1y ago |
|
| 7 |
4056c66 |
Dawsh |
1y ago |
""" |
| 8 |
4056c66 |
Dawsh |
1y ago |
|
| 9 |
4056c66 |
Dawsh |
1y ago |
import sqlalchemy as sa |
| 10 |
4056c66 |
Dawsh |
1y ago |
from alembic import op |
| 11 |
4056c66 |
Dawsh |
1y ago |
|
| 12 |
4056c66 |
Dawsh |
1y ago |
# revision identifiers, used by Alembic. |
| 13 |
4056c66 |
Dawsh |
1y ago |
revision = "57eba0a293f2" |
| 14 |
4056c66 |
Dawsh |
1y ago |
down_revision = "982867b533e6" |
| 15 |
4056c66 |
Dawsh |
1y ago |
branch_labels = None |
| 16 |
4056c66 |
Dawsh |
1y ago |
depends_on = None |
| 17 |
4056c66 |
Dawsh |
1y ago |
|
| 18 |
4056c66 |
Dawsh |
1y ago |
|
| 19 |
4056c66 |
Dawsh |
1y ago |
def upgrade() -> None: |
| 20 |
4056c66 |
Dawsh |
1y ago |
# ### commands auto generated by Alembic - please adjust! ### |
| 21 |
4056c66 |
Dawsh |
1y ago |
op.create_table( |
| 22 |
4056c66 |
Dawsh |
1y ago |
"hosts_services", |
| 23 |
4056c66 |
Dawsh |
1y ago |
sa.Column("host_id", sa.Integer(), nullable=False), |
| 24 |
4056c66 |
Dawsh |
1y ago |
sa.Column("service_id", sa.Integer(), nullable=False), |
| 25 |
4056c66 |
Dawsh |
1y ago |
sa.ForeignKeyConstraint( |
| 26 |
4056c66 |
Dawsh |
1y ago |
["host_id"], |
| 27 |
4056c66 |
Dawsh |
1y ago |
["hosts.id"], |
| 28 |
4056c66 |
Dawsh |
1y ago |
), |
| 29 |
4056c66 |
Dawsh |
1y ago |
sa.ForeignKeyConstraint( |
| 30 |
4056c66 |
Dawsh |
1y ago |
["service_id"], |
| 31 |
4056c66 |
Dawsh |
1y ago |
["services.id"], |
| 32 |
4056c66 |
Dawsh |
1y ago |
), |
| 33 |
4056c66 |
Dawsh |
1y ago |
sa.PrimaryKeyConstraint("host_id", "service_id"), |
| 34 |
4056c66 |
Dawsh |
1y ago |
) |
| 35 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 36 |
4056c66 |
Dawsh |
1y ago |
"hosts", |
| 37 |
4056c66 |
Dawsh |
1y ago |
sa.Column("host_protocol", sa.String(length=32), nullable=True), |
| 38 |
4056c66 |
Dawsh |
1y ago |
) |
| 39 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 40 |
4056c66 |
Dawsh |
1y ago |
"hosts", sa.Column("host_network", sa.String(length=32), nullable=True) |
| 41 |
4056c66 |
Dawsh |
1y ago |
) |
| 42 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 43 |
4056c66 |
Dawsh |
1y ago |
"hosts", sa.Column("uuid", sa.String(length=36), nullable=True) |
| 44 |
4056c66 |
Dawsh |
1y ago |
) |
| 45 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 46 |
4056c66 |
Dawsh |
1y ago |
"hosts", sa.Column("password", sa.String(length=128), nullable=True) |
| 47 |
4056c66 |
Dawsh |
1y ago |
) |
| 48 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 49 |
4056c66 |
Dawsh |
1y ago |
"hosts", sa.Column("header_type", sa.String(length=32), nullable=True) |
| 50 |
4056c66 |
Dawsh |
1y ago |
) |
| 51 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 52 |
4056c66 |
Dawsh |
1y ago |
"hosts", |
| 53 |
4056c66 |
Dawsh |
1y ago |
sa.Column("reality_public_key", sa.String(length=128), nullable=True), |
| 54 |
4056c66 |
Dawsh |
1y ago |
) |
| 55 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 56 |
4056c66 |
Dawsh |
1y ago |
"hosts", sa.Column("reality_short_ids", sa.JSON(), nullable=True) |
| 57 |
4056c66 |
Dawsh |
1y ago |
) |
| 58 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 59 |
4056c66 |
Dawsh |
1y ago |
"hosts", sa.Column("flow", sa.String(length=32), nullable=True) |
| 60 |
4056c66 |
Dawsh |
1y ago |
) |
| 61 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 62 |
4056c66 |
Dawsh |
1y ago |
"hosts", sa.Column("shadowtls_version", sa.Integer(), nullable=True) |
| 63 |
4056c66 |
Dawsh |
1y ago |
) |
| 64 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 65 |
4056c66 |
Dawsh |
1y ago |
"hosts", |
| 66 |
4056c66 |
Dawsh |
1y ago |
sa.Column("shadowsocks_method", sa.String(length=32), nullable=True), |
| 67 |
4056c66 |
Dawsh |
1y ago |
) |
| 68 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 69 |
4056c66 |
Dawsh |
1y ago |
"hosts", sa.Column("splithttp_settings", sa.JSON(), nullable=True) |
| 70 |
4056c66 |
Dawsh |
1y ago |
) |
| 71 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "mux") |
| 72 |
4056c66 |
Dawsh |
1y ago |
op.add_column("hosts", sa.Column("mux_settings", sa.JSON(), nullable=True)) |
| 73 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 74 |
4056c66 |
Dawsh |
1y ago |
"hosts", sa.Column("early_data", sa.Integer(), nullable=True) |
| 75 |
4056c66 |
Dawsh |
1y ago |
) |
| 76 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 77 |
4056c66 |
Dawsh |
1y ago |
"hosts", |
| 78 |
4056c66 |
Dawsh |
1y ago |
sa.Column( |
| 79 |
4056c66 |
Dawsh |
1y ago |
"universal", |
| 80 |
4056c66 |
Dawsh |
1y ago |
sa.Boolean(), |
| 81 |
4056c66 |
Dawsh |
1y ago |
server_default=sa.sql.false(), |
| 82 |
4056c66 |
Dawsh |
1y ago |
nullable=False, |
| 83 |
4056c66 |
Dawsh |
1y ago |
), |
| 84 |
4056c66 |
Dawsh |
1y ago |
) |
| 85 |
4056c66 |
Dawsh |
1y ago |
if op.get_bind().dialect.name == "sqlite": |
| 86 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 87 |
4056c66 |
Dawsh |
1y ago |
"hosts", sa.Column("inbound_id_new", sa.Integer, nullable=True) |
| 88 |
4056c66 |
Dawsh |
1y ago |
) |
| 89 |
4056c66 |
Dawsh |
1y ago |
|
| 90 |
4056c66 |
Dawsh |
1y ago |
# Copy data from the old column to the new column |
| 91 |
4056c66 |
Dawsh |
1y ago |
op.execute( |
| 92 |
4056c66 |
Dawsh |
1y ago |
""" |
| 93 |
4056c66 |
Dawsh |
1y ago |
UPDATE hosts |
| 94 |
4056c66 |
Dawsh |
1y ago |
SET inbound_id_new = inbound_id |
| 95 |
4056c66 |
Dawsh |
1y ago |
""" |
| 96 |
4056c66 |
Dawsh |
1y ago |
) |
| 97 |
4056c66 |
Dawsh |
1y ago |
|
| 98 |
4056c66 |
Dawsh |
1y ago |
# Drop the old column (SQLite requires recreating the table for this step) |
| 99 |
4056c66 |
Dawsh |
1y ago |
with op.batch_alter_table("hosts") as batch_op: |
| 100 |
4056c66 |
Dawsh |
1y ago |
batch_op.drop_column("inbound_id") |
| 101 |
4056c66 |
Dawsh |
1y ago |
|
| 102 |
4056c66 |
Dawsh |
1y ago |
# Rename the new column to the old column's name |
| 103 |
4056c66 |
Dawsh |
1y ago |
op.alter_column( |
| 104 |
4056c66 |
Dawsh |
1y ago |
"hosts", "inbound_id_new", new_column_name="inbound_id" |
| 105 |
4056c66 |
Dawsh |
1y ago |
) |
| 106 |
4056c66 |
Dawsh |
1y ago |
else: |
| 107 |
4056c66 |
Dawsh |
1y ago |
op.alter_column( |
| 108 |
4056c66 |
Dawsh |
1y ago |
"hosts", "inbound_id", existing_type=sa.INTEGER(), nullable=True |
| 109 |
4056c66 |
Dawsh |
1y ago |
) |
| 110 |
4056c66 |
Dawsh |
1y ago |
# ### end Alembic commands ### |
| 111 |
4056c66 |
Dawsh |
1y ago |
|
| 112 |
4056c66 |
Dawsh |
1y ago |
|
| 113 |
4056c66 |
Dawsh |
1y ago |
def downgrade() -> None: |
| 114 |
4056c66 |
Dawsh |
1y ago |
# ### commands auto generated by Alembic - please adjust! ### |
| 115 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "universal") |
| 116 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "early_data") |
| 117 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 118 |
4056c66 |
Dawsh |
1y ago |
"hosts", |
| 119 |
4056c66 |
Dawsh |
1y ago |
sa.Column( |
| 120 |
4056c66 |
Dawsh |
1y ago |
"mux", sa.Boolean(), server_default=sa.sql.true(), nullable=False |
| 121 |
4056c66 |
Dawsh |
1y ago |
), |
| 122 |
4056c66 |
Dawsh |
1y ago |
) |
| 123 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "mux_settings") |
| 124 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "splithttp_settings") |
| 125 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "shadowsocks_method") |
| 126 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "shadowtls_version") |
| 127 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "flow") |
| 128 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "reality_short_ids") |
| 129 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "reality_public_key") |
| 130 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "header_type") |
| 131 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "password") |
| 132 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "uuid") |
| 133 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "host_network") |
| 134 |
4056c66 |
Dawsh |
1y ago |
op.drop_column("hosts", "host_protocol") |
| 135 |
4056c66 |
Dawsh |
1y ago |
op.drop_table("hosts_services") |
| 136 |
4056c66 |
Dawsh |
1y ago |
if op.get_bind().dialect.name == "sqlite": |
| 137 |
4056c66 |
Dawsh |
1y ago |
op.add_column( |
| 138 |
4056c66 |
Dawsh |
1y ago |
"hosts", sa.Column("inbound_id_old", sa.Integer, nullable=False) |
| 139 |
4056c66 |
Dawsh |
1y ago |
) |
| 140 |
4056c66 |
Dawsh |
1y ago |
|
| 141 |
4056c66 |
Dawsh |
1y ago |
# Copy data from the new column back to the old column |
| 142 |
4056c66 |
Dawsh |
1y ago |
op.execute( |
| 143 |
4056c66 |
Dawsh |
1y ago |
""" |
| 144 |
4056c66 |
Dawsh |
1y ago |
UPDATE hosts |
| 145 |
4056c66 |
Dawsh |
1y ago |
SET inbound_id_old = inbound_id |
| 146 |
4056c66 |
Dawsh |
1y ago |
""" |
| 147 |
4056c66 |
Dawsh |
1y ago |
) |
| 148 |
4056c66 |
Dawsh |
1y ago |
|
| 149 |
4056c66 |
Dawsh |
1y ago |
# Drop the modified column |
| 150 |
4056c66 |
Dawsh |
1y ago |
with op.batch_alter_table("hosts") as batch_op: |
| 151 |
4056c66 |
Dawsh |
1y ago |
batch_op.drop_column("inbound_id") |
| 152 |
4056c66 |
Dawsh |
1y ago |
|
| 153 |
4056c66 |
Dawsh |
1y ago |
# Rename the old column back to the original name |
| 154 |
4056c66 |
Dawsh |
1y ago |
op.alter_column( |
| 155 |
4056c66 |
Dawsh |
1y ago |
"hosts", "inbound_id_old", new_column_name="inbound_id" |
| 156 |
4056c66 |
Dawsh |
1y ago |
) |
| 157 |
4056c66 |
Dawsh |
1y ago |
else: |
| 158 |
4056c66 |
Dawsh |
1y ago |
op.alter_column( |
| 159 |
4056c66 |
Dawsh |
1y ago |
"hosts", "inbound_id", existing_type=sa.INTEGER(), nullable=False |
| 160 |
4056c66 |
Dawsh |
1y ago |
) |
| 161 |
4056c66 |
Dawsh |
1y ago |
# ### end Alembic commands ### |