2018-05-08 00:14:32 +02:00
|
|
|
"""Create tables and columns for the acme issuer.
|
2018-04-11 01:04:07 +02:00
|
|
|
|
|
|
|
Revision ID: 3adfdd6598df
|
|
|
|
Revises: 556ceb3e3c3e
|
|
|
|
Create Date: 2018-04-10 13:25:47.007556
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
2019-05-16 16:57:02 +02:00
|
|
|
revision = "3adfdd6598df"
|
|
|
|
down_revision = "556ceb3e3c3e"
|
2018-04-11 01:04:07 +02:00
|
|
|
|
|
|
|
import sqlalchemy as sa
|
2018-05-08 00:14:32 +02:00
|
|
|
from alembic import op
|
2018-04-11 01:04:07 +02:00
|
|
|
from sqlalchemy.dialects.postgresql import JSON
|
|
|
|
from sqlalchemy_utils import ArrowType
|
|
|
|
|
2018-05-08 00:14:32 +02:00
|
|
|
from lemur.utils import Vault
|
|
|
|
|
2018-04-11 01:04:07 +02:00
|
|
|
|
|
|
|
def upgrade():
|
|
|
|
# create provider table
|
2018-05-08 00:14:32 +02:00
|
|
|
print("Creating dns_providers table")
|
2018-04-11 01:04:07 +02:00
|
|
|
op.create_table(
|
2019-05-16 16:57:02 +02:00
|
|
|
"dns_providers",
|
|
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
|
|
sa.Column("name", sa.String(length=256), nullable=True),
|
|
|
|
sa.Column("description", sa.String(length=1024), nullable=True),
|
|
|
|
sa.Column("provider_type", sa.String(length=256), nullable=True),
|
|
|
|
sa.Column("credentials", Vault(), nullable=True),
|
|
|
|
sa.Column("api_endpoint", sa.String(length=256), nullable=True),
|
|
|
|
sa.Column(
|
|
|
|
"date_created", ArrowType(), server_default=sa.text("now()"), nullable=False
|
|
|
|
),
|
|
|
|
sa.Column("status", sa.String(length=128), nullable=True),
|
|
|
|
sa.Column("options", JSON),
|
|
|
|
sa.Column("domains", sa.JSON(), nullable=True),
|
|
|
|
sa.PrimaryKeyConstraint("id"),
|
|
|
|
sa.UniqueConstraint("name"),
|
2018-04-11 01:04:07 +02:00
|
|
|
)
|
2018-05-08 00:14:32 +02:00
|
|
|
print("Adding dns_provider_id column to certificates")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.add_column(
|
|
|
|
"certificates", sa.Column("dns_provider_id", sa.Integer(), nullable=True)
|
|
|
|
)
|
2018-05-08 00:14:32 +02:00
|
|
|
print("Adding dns_provider_id column to pending_certs")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.add_column(
|
|
|
|
"pending_certs", sa.Column("dns_provider_id", sa.Integer(), nullable=True)
|
|
|
|
)
|
2018-05-08 00:14:32 +02:00
|
|
|
print("Adding options column to pending_certs")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.add_column("pending_certs", sa.Column("options", JSON))
|
2018-05-08 00:14:32 +02:00
|
|
|
|
|
|
|
print("Creating pending_dns_authorizations table")
|
|
|
|
op.create_table(
|
2019-05-16 16:57:02 +02:00
|
|
|
"pending_dns_authorizations",
|
|
|
|
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
|
|
|
sa.Column("account_number", sa.String(length=128), nullable=True),
|
|
|
|
sa.Column("domains", JSON, nullable=True),
|
|
|
|
sa.Column("dns_provider_type", sa.String(length=128), nullable=True),
|
|
|
|
sa.Column("options", JSON, nullable=True),
|
2018-05-08 00:14:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
print("Creating certificates_dns_providers_fk foreign key")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.create_foreign_key(
|
|
|
|
"certificates_dns_providers_fk",
|
|
|
|
"certificates",
|
|
|
|
"dns_providers",
|
|
|
|
["dns_provider_id"],
|
|
|
|
["id"],
|
|
|
|
ondelete="cascade",
|
|
|
|
)
|
2018-05-08 00:14:32 +02:00
|
|
|
|
|
|
|
print("Altering column types in the api_keys table")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.alter_column("api_keys", "issued_at", existing_type=sa.BIGINT(), nullable=True)
|
|
|
|
op.alter_column("api_keys", "revoked", existing_type=sa.BOOLEAN(), nullable=True)
|
|
|
|
op.alter_column("api_keys", "ttl", existing_type=sa.BIGINT(), nullable=True)
|
|
|
|
op.alter_column("api_keys", "user_id", existing_type=sa.INTEGER(), nullable=True)
|
2018-04-11 01:04:07 +02:00
|
|
|
|
2018-05-10 21:48:49 +02:00
|
|
|
print("Creating dns_providers_id foreign key on pending_certs table")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.create_foreign_key(
|
|
|
|
None,
|
|
|
|
"pending_certs",
|
|
|
|
"dns_providers",
|
|
|
|
["dns_provider_id"],
|
|
|
|
["id"],
|
|
|
|
ondelete="CASCADE",
|
|
|
|
)
|
|
|
|
|
2018-04-11 01:04:07 +02:00
|
|
|
|
|
|
|
def downgrade():
|
2018-05-10 21:48:49 +02:00
|
|
|
print("Removing dns_providers_id foreign key on pending_certs table")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.drop_constraint(None, "pending_certs", type_="foreignkey")
|
2018-05-08 00:14:32 +02:00
|
|
|
print("Reverting column types in the api_keys table")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.alter_column("api_keys", "user_id", existing_type=sa.INTEGER(), nullable=False)
|
|
|
|
op.alter_column("api_keys", "ttl", existing_type=sa.BIGINT(), nullable=False)
|
|
|
|
op.alter_column("api_keys", "revoked", existing_type=sa.BOOLEAN(), nullable=False)
|
|
|
|
op.alter_column("api_keys", "issued_at", existing_type=sa.BIGINT(), nullable=False)
|
2018-05-08 00:14:32 +02:00
|
|
|
print("Reverting certificates_dns_providers_fk foreign key")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.drop_constraint(
|
|
|
|
"certificates_dns_providers_fk", "certificates", type_="foreignkey"
|
|
|
|
)
|
2018-05-08 00:14:32 +02:00
|
|
|
|
|
|
|
print("Dropping pending_dns_authorizations table")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.drop_table("pending_dns_authorizations")
|
2018-05-08 00:14:32 +02:00
|
|
|
print("Undoing modifications to pending_certs table")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.drop_column("pending_certs", "options")
|
|
|
|
op.drop_column("pending_certs", "dns_provider_id")
|
2018-05-08 00:14:32 +02:00
|
|
|
print("Undoing modifications to certificates table")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.drop_column("certificates", "dns_provider_id")
|
2018-05-08 00:14:32 +02:00
|
|
|
|
|
|
|
print("Deleting dns_providers table")
|
2019-05-16 16:57:02 +02:00
|
|
|
op.drop_table("dns_providers")
|