Skip to content

Commit

Permalink
Create alembic migrations for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathansick committed Jul 5, 2021
1 parent ef54fa5 commit 666d153
Showing 1 changed file with 157 additions and 0 deletions.
157 changes: 157 additions & 0 deletions migrations/versions/439738fc542e_v2_tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
"""Version 2 tables.
Revision ID: 439738fc542e
Revises: 4ace74bc8168
Create Date: 2021-07-05 13:15:34.516704
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "439738fc542e"
down_revision = "4ace74bc8168"


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"organizations",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column(
"default_dashboard_template_id", sa.Integer(), nullable=True
),
sa.Column("slug", sa.Unicode(length=255), nullable=False),
sa.Column("title", sa.Unicode(length=255), nullable=False),
sa.Column(
"layout",
sa.Enum("subdomain", "path", name="organizationlayoutmode"),
nullable=False,
),
sa.Column("fastly_support", sa.Boolean(), nullable=False),
sa.Column("root_domain", sa.Unicode(length=255), nullable=False),
sa.Column("root_path_prefix", sa.Unicode(length=255), nullable=False),
sa.Column("fastly_domain", sa.Unicode(length=255), nullable=True),
sa.Column(
"fastly_encrypted_api_key", sa.String(length=255), nullable=True
),
sa.Column("fastly_service_id", sa.Unicode(length=255), nullable=True),
sa.Column("bucket_name", sa.Unicode(length=255), nullable=True),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("slug"),
)
op.create_table(
"dashboardtemplates",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("organization_id", sa.Integer(), nullable=True),
sa.Column("comment", sa.UnicodeText(), nullable=True),
sa.Column("bucket_prefix", sa.Unicode(length=255), nullable=False),
sa.Column("created_by_id", sa.Integer(), nullable=True),
sa.Column("date_created", sa.DateTime(), nullable=False),
sa.Column("deleted_by_id", sa.Integer(), nullable=True),
sa.Column("date_deleted", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["created_by_id"],
["users.id"],
),
sa.ForeignKeyConstraint(
["deleted_by_id"],
["users.id"],
),
sa.ForeignKeyConstraint(
["organization_id"],
["organizations.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("bucket_prefix"),
)
op.create_table(
"tags",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("organization_id", sa.Integer(), nullable=True),
sa.Column("slug", sa.Unicode(length=255), nullable=False),
sa.Column("title", sa.Unicode(length=255), nullable=False),
sa.Column("comment", sa.UnicodeText(), nullable=True),
sa.ForeignKeyConstraint(
["organization_id"],
["organizations.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("slug", "organization_id"),
sa.UniqueConstraint("title", "organization_id"),
)
with op.batch_alter_table("tags", schema=None) as batch_op:
batch_op.create_index(
batch_op.f("ix_tags_organization_id"),
["organization_id"],
unique=False,
)

op.create_table(
"producttags",
sa.Column("tag_id", sa.Integer(), nullable=False),
sa.Column("product_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["product_id"],
["products.id"],
),
sa.ForeignKeyConstraint(
["tag_id"],
["tags.id"],
),
sa.PrimaryKeyConstraint("tag_id", "product_id"),
)
with op.batch_alter_table("builds", schema=None) as batch_op:
batch_op.add_column(
sa.Column("git_ref", sa.Unicode(length=255), nullable=True)
)
batch_op.add_column(
sa.Column("uploaded_by_id", sa.Integer(), nullable=True)
)
batch_op.create_foreign_key(None, "users", ["uploaded_by_id"], ["id"])

with op.batch_alter_table("editions", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"kind",
sa.Enum(
"main",
"release",
"draft",
"major",
"minor",
name="editionkind",
),
nullable=False,
)
)

with op.batch_alter_table("products", schema=None) as batch_op:
batch_op.add_column(
sa.Column("organization_id", sa.Integer(), nullable=True)
)
batch_op.create_foreign_key(
None, "organizations", ["organization_id"], ["id"]
)


def downgrade():
with op.batch_alter_table("products", schema=None) as batch_op:
batch_op.drop_constraint(None, type_="foreignkey")
batch_op.drop_column("organization_id")

with op.batch_alter_table("editions", schema=None) as batch_op:
batch_op.drop_column("kind")

with op.batch_alter_table("builds", schema=None) as batch_op:
batch_op.drop_constraint(None, type_="foreignkey")
batch_op.drop_column("uploaded_by_id")
batch_op.drop_column("git_ref")

op.drop_table("producttags")
with op.batch_alter_table("tags", schema=None) as batch_op:
batch_op.drop_index(batch_op.f("ix_tags_organization_id"))

op.drop_table("tags")
op.drop_table("dashboardtemplates")
op.drop_table("organizations")

0 comments on commit 666d153

Please sign in to comment.