-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create migration for v2 tables update
- Loading branch information
1 parent
94cddb3
commit a6b54e2
Showing
1 changed file
with
152 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
"""Add v2 tables | ||
Revision ID: f2c293621c3e | ||
Revises: 4ace74bc8168 | ||
Create Date: 2021-07-05 16:09:02.274225 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "f2c293621c3e" | ||
down_revision = "4ace74bc8168" | ||
|
||
|
||
def upgrade(): | ||
from keeper.models import EditionKind | ||
|
||
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.Integer(), | ||
default=EditionKind.draft.value, | ||
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") |