gitscope
← marzneshin / v0.5.1 / app/db/migrations/versions/5410d8ec78ff_alpn_to_string.py
https://dev.kronoz.win/r/marzneshin.git
app/db/migrations/versions/5410d8ec78ff_alpn_to_string.py · Python
Blame Raw
 1"""make host alpn string
 2
 3Revision ID: 5410d8ec78ff
 4Revises: b0357faf51c8
 5Create Date: 2024-07-24 22:47:51.528849
 6
 7"""
 8
 9import sqlalchemy as sa
10from alembic import op
11from sqlalchemy.dialects import postgresql, mysql
12
13# revision identifiers, used by Alembic.
14revision = "5410d8ec78ff"
15down_revision = "b0357faf51c8"
16branch_labels = None
17depends_on = None
18
19
20def upgrade() -> None:
21    # ### commands auto generated by Alembic - please adjust! ###
22    if (dialect := op.get_bind().dialect.name) == "postgresql":
23        op.alter_column(
24            "hosts",
25            "alpn",
26            existing_type=postgresql.ENUM(
27                "none", "h2", "http/1.1", "h2,http/1.1", name="proxyhostalpn"
28            ),
29            type_=sa.String(length=32),
30            existing_nullable=False,
31            nullable=True,
32            server_default=None,
33        )
34    elif dialect == "mysql" or dialect == "mariadb":
35        op.alter_column(
36            "hosts",
37            "alpn",
38            existing_type=mysql.ENUM("none", "h2", "http/1.1", "h2,http/1.1"),
39            type_=sa.String(length=32),
40            nullable=True,
41        )
42    # ### end Alembic commands ###
43
44
45def downgrade() -> None:
46    # ### commands auto generated by Alembic - please adjust! ###
47    if (dialect := op.get_bind().dialect.name) == "postgresql":
48        op.alter_column(
49            "hosts",
50            "alpn",
51            existing_type=sa.String(length=32),
52            type_=postgresql.ENUM(
53                "none", "h2", "http/1.1", "h2,http/1.1", name="proxyhostalpn"
54            ),
55            existing_nullable=True,
56            nullable=False,
57            existing_server_default=None,
58            server_default=sa.text("'none'::proxyhostalpn"),
59        )
60    elif dialect == "mysql" or dialect == "mariadb":
61        op.alter_column(
62            "hosts",
63            "alpn",
64            existing_type=sa.String(length=32),
65            type_=mysql.ENUM("none", "h2", "http/1.1", "h2,http/1.1"),
66            nullable=False,
67            existing_server_default=None,
68            server_default=sa.text("'none'"),
69        )
70    # ### end Alembic commands ###