From e31df6765f7fd2c8326810f30b7e2db9541cdbe7 Mon Sep 17 00:00:00 2001 From: Hannah Eslinger Date: Wed, 25 Oct 2023 12:00:17 -0600 Subject: [PATCH] Squish --- .../3fcdf6f2886b_add_shapecollections.py | 68 ------------------ ...f624_constrain_dependencies_to_have_no_.py | 71 ------------------- .../5cacb139c494_add_manifest_to_model.py | 56 --------------- ...52795d_init_db.py => 6114d2b80bc6_init.py} | 52 ++++++++++---- ...21a0432bc_add_optional_args_to_template.py | 37 ---------- .../99fd5e88689c_add_description_to_model.py | 32 --------- 6 files changed, 38 insertions(+), 278 deletions(-) delete mode 100644 migrations/versions/3fcdf6f2886b_add_shapecollections.py delete mode 100644 migrations/versions/542bfbdef624_constrain_dependencies_to_have_no_.py delete mode 100644 migrations/versions/5cacb139c494_add_manifest_to_model.py rename migrations/versions/{ee47e252795d_init_db.py => 6114d2b80bc6_init.py} (57%) delete mode 100644 migrations/versions/66121a0432bc_add_optional_args_to_template.py delete mode 100644 migrations/versions/99fd5e88689c_add_description_to_model.py diff --git a/migrations/versions/3fcdf6f2886b_add_shapecollections.py b/migrations/versions/3fcdf6f2886b_add_shapecollections.py deleted file mode 100644 index 39e4f3014..000000000 --- a/migrations/versions/3fcdf6f2886b_add_shapecollections.py +++ /dev/null @@ -1,68 +0,0 @@ -"""Add ShapeCollections - -Revision ID: 3fcdf6f2886b -Revises: ee47e252795d -Create Date: 2022-06-20 15:51:36.992384 - -""" -import uuid - -import sqlalchemy as sa -from alembic import op -from sqlalchemy.orm import sessionmaker - -from buildingmotif.database.tables import DBLibrary, DBShapeCollection - -# revision identifiers, used by Alembic. -revision = "3fcdf6f2886b" -down_revision = "ee47e252795d" -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table( - "shape_collection", - sa.Column("id", sa.Integer(), nullable=False), - sa.Column("graph_id", sa.String(), nullable=True), - sa.PrimaryKeyConstraint("id"), - ) - with op.batch_alter_table("library", schema=None) as batch_op: - batch_op.add_column( - sa.Column("shape_collection_id", sa.Integer(), nullable=True) - ) - batch_op.create_foreign_key( - "tempalte_library_shape_collection", - "shape_collection", - ["shape_collection_id"], - ["id"], - ) - - conn = op.get_bind() - Session = sessionmaker() - - with Session(bind=conn) as session: - libraries = session.query(DBLibrary).all() - - for tl in libraries: - shape_collection = DBShapeCollection(graph_id=str(uuid.uuid4())) - session.add(shape_collection) - tl.shape_collection = shape_collection - - session.commit() - - with op.batch_alter_table("library", schema=None) as batch_op: - batch_op.alter_column("shape_collection_id", nullable=False) - - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("library", schema=None) as batch_op: - batch_op.drop_constraint(None, type_="foreignkey") - batch_op.drop_column("shape_collection_id") - - op.drop_table("shape_collection") - # ### end Alembic commands ### diff --git a/migrations/versions/542bfbdef624_constrain_dependencies_to_have_no_.py b/migrations/versions/542bfbdef624_constrain_dependencies_to_have_no_.py deleted file mode 100644 index 6dcf0b149..000000000 --- a/migrations/versions/542bfbdef624_constrain_dependencies_to_have_no_.py +++ /dev/null @@ -1,71 +0,0 @@ -"""Constrain dependencies to have no duplicates. Uses new JSON serialization/deserialization -(serde) to consistently store the dependency bindings. - -Revision ID: 542bfbdef624 -Revises: 99fd5e88689c -Create Date: 2022-09-13 10:57:44.977492 - -""" -import sqlalchemy as sa -from alembic import op -from sqlalchemy.orm import sessionmaker - -from buildingmotif.database.tables import DepsAssociation - -# revision identifiers, used by Alembic. -revision = "542bfbdef624" -down_revision = "99fd5e88689c" -branch_labels = None -depends_on = None - - -def upgrade(): - # add NULLABLE 'id' column - with op.batch_alter_table("deps_association_table", schema=None) as batch_op: - batch_op.add_column(sa.Column("id", sa.Integer(), nullable=True)) - batch_op.drop_constraint("pk_constraint", type_="primary") - batch_op.create_primary_key("deps_association_pk", columns=["id"]) - batch_op.alter_column( - existing_type=sa.INTEGER(), - column_name="id", - autoincrement=True, - existing_autoincrement=True, - nullable=False, - ) - - batch_op.alter_column( - "dependant_id", existing_type=sa.INTEGER(), nullable=False - ) - batch_op.alter_column("dependee_id", existing_type=sa.INTEGER(), nullable=False) - batch_op.create_unique_constraint( - "deps_association_unique_constraint", - ["dependant_id", "dependee_id", "args"], - ) - - # now that 'id' exists, update the serde of the deps field by copying all the deps - # out and then putting them back in - conn = op.get_bind() - Session = sessionmaker() - with Session(bind=conn) as session: - deps = session.query(DepsAssociation).all() - for dep in deps: - args = dep.args.copy() - dep.args = [(k, v) for k, v in args.items()] - session.add(dep) - session.commit() - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("template", schema=None) as batch_op: - batch_op.create_index("ix_template_name", ["name"], unique=False) - - with op.batch_alter_table("deps_association_table", schema=None) as batch_op: - batch_op.drop_constraint("deps_association_unique_constraint", type_="unique") - batch_op.alter_column("dependee_id", existing_type=sa.INTEGER(), nullable=False) - batch_op.alter_column( - "dependant_id", existing_type=sa.INTEGER(), nullable=False - ) - batch_op.drop_column("id") - - # ### end Alembic commands ### diff --git a/migrations/versions/5cacb139c494_add_manifest_to_model.py b/migrations/versions/5cacb139c494_add_manifest_to_model.py deleted file mode 100644 index 7c3826cd0..000000000 --- a/migrations/versions/5cacb139c494_add_manifest_to_model.py +++ /dev/null @@ -1,56 +0,0 @@ -"""Add manifest to Model - -Revision ID: 5cacb139c494 -Revises: 542bfbdef624 -Create Date: 2023-02-28 17:48:33.885131 - -""" -import uuid - -import sqlalchemy as sa -from alembic import op -from sqlalchemy.orm import sessionmaker - -from buildingmotif.database.tables import DBModel, DBShapeCollection - -# revision identifiers, used by Alembic. -revision = "5cacb139c494" -down_revision = "542bfbdef624" -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("models", schema=None) as batch_op: - batch_op.add_column(sa.Column("manifest_id", sa.Integer(), nullable=True)) - batch_op.create_foreign_key( - "fk_shape_collection", "shape_collection", ["manifest_id"], ["id"] - ) - - conn = op.get_bind() - Session = sessionmaker() - - with Session(bind=conn) as session: - models = session.query(DBModel).all() - - for m in models: - shape_collection = DBShapeCollection(graph_id=str(uuid.uuid4())) - session.add(shape_collection) - m.manifest = shape_collection - - session.commit() - - with op.batch_alter_table("models", schema=None) as batch_op: - batch_op.alter_column("manifest_id", nullable=False) - - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("models", schema=None) as batch_op: - batch_op.drop_constraint(None, type_="foreignkey") - batch_op.drop_column("manifest_id") - - # ### end Alembic commands ### diff --git a/migrations/versions/ee47e252795d_init_db.py b/migrations/versions/6114d2b80bc6_init.py similarity index 57% rename from migrations/versions/ee47e252795d_init_db.py rename to migrations/versions/6114d2b80bc6_init.py index c50609a02..f943bad07 100644 --- a/migrations/versions/ee47e252795d_init_db.py +++ b/migrations/versions/6114d2b80bc6_init.py @@ -1,17 +1,18 @@ -"""init db +"""init -Revision ID: ee47e252795d +Revision ID: 6114d2b80bc6 Revises: -Create Date: 2022-06-17 15:36:46.968440 +Create Date: 2023-10-16 20:10:01.622863 """ import sqlalchemy as sa from alembic import op +# from sqlalchemy.dialects.postgresql import JSON from buildingmotif.database.utils import JSONType # revision identifiers, used by Alembic. -revision = "ee47e252795d" +revision = "6114d2b80bc6" down_revision = None branch_labels = None depends_on = None @@ -20,9 +21,8 @@ def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table( - "models", + "shape_collection", sa.Column("id", sa.Integer(), nullable=False), - sa.Column("name", sa.String(), nullable=True), sa.Column("graph_id", sa.String(), nullable=True), sa.PrimaryKeyConstraint("id"), ) @@ -30,15 +30,33 @@ def upgrade(): "library", sa.Column("id", sa.Integer(), nullable=False), sa.Column("name", sa.String(), nullable=False), + sa.Column("shape_collection_id", sa.Integer(), nullable=False), + sa.ForeignKeyConstraint( + ["shape_collection_id"], + ["shape_collection.id"], + ), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name"), ) + op.create_table( + "models", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("name", sa.String(), nullable=True), + sa.Column("description", sa.Text(), nullable=False), + sa.Column("graph_id", sa.String(), nullable=True), + sa.Column("manifest_id", sa.Integer(), nullable=False), + sa.ForeignKeyConstraint( + ["manifest_id"], + ["shape_collection.id"], + ), + sa.PrimaryKeyConstraint("id"), + ) op.create_table( "template", sa.Column("id", sa.Integer(), nullable=False), sa.Column("name", sa.String(), nullable=False), - sa.Column("_head", sa.String(), nullable=False), sa.Column("body_id", sa.String(), nullable=True), + sa.Column("optional_args", JSONType(), nullable=True), sa.Column("library_id", sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ["library_id"], @@ -46,15 +64,14 @@ def upgrade(): ), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint( - "name", - "library_id", - name="name_library_unique_constraint", + "name", "library_id", name="name_library_unique_constraint" ), ) op.create_table( "deps_association_table", - sa.Column("dependant_id", sa.Integer(), nullable=False), - sa.Column("dependee_id", sa.Integer(), nullable=False), + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("dependant_id", sa.Integer(), nullable=True), + sa.Column("dependee_id", sa.Integer(), nullable=True), sa.Column("args", JSONType(), nullable=True), sa.ForeignKeyConstraint( ["dependant_id"], @@ -64,7 +81,13 @@ def upgrade(): ["dependee_id"], ["template.id"], ), - sa.PrimaryKeyConstraint("dependant_id", "dependee_id", name="pk_constraint"), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint( + "dependant_id", + "dependee_id", + "args", + name="deps_association_unique_constraint", + ), ) # ### end Alembic commands ### @@ -73,6 +96,7 @@ def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_table("deps_association_table") op.drop_table("template") - op.drop_table("library") op.drop_table("models") + op.drop_table("library") + op.drop_table("shape_collection") # ### end Alembic commands ### diff --git a/migrations/versions/66121a0432bc_add_optional_args_to_template.py b/migrations/versions/66121a0432bc_add_optional_args_to_template.py deleted file mode 100644 index 0b7968083..000000000 --- a/migrations/versions/66121a0432bc_add_optional_args_to_template.py +++ /dev/null @@ -1,37 +0,0 @@ -"""add optional_args to template - -Revision ID: 66121a0432bc -Revises: 3fcdf6f2886b -Create Date: 2022-07-02 17:02:43.455056 - -""" -import sqlalchemy as sa -from alembic import op - -from buildingmotif.database.utils import JSONType - -# revision identifiers, used by Alembic. -revision = "66121a0432bc" -down_revision = "3fcdf6f2886b" -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("template", schema=None) as batch_op: - batch_op.add_column(sa.Column("optional_args", JSONType(), nullable=True)) - batch_op.create_index(batch_op.f("ix_template_name"), ["name"], unique=False) - batch_op.drop_column("_head") - - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("template", schema=None) as batch_op: - batch_op.add_column(sa.Column("_head", sa.VARCHAR(), nullable=False)) - batch_op.drop_index(batch_op.f("ix_template_name")) - batch_op.drop_column("optional_args") - - # ### end Alembic commands ### diff --git a/migrations/versions/99fd5e88689c_add_description_to_model.py b/migrations/versions/99fd5e88689c_add_description_to_model.py deleted file mode 100644 index 6ee73b35d..000000000 --- a/migrations/versions/99fd5e88689c_add_description_to_model.py +++ /dev/null @@ -1,32 +0,0 @@ -"""Add description to Model - -Revision ID: 99fd5e88689c -Revises: 66121a0432bc -Create Date: 2022-09-26 11:37:39.308986 - -""" -import sqlalchemy as sa -from alembic import op - -# revision identifiers, used by Alembic. -revision = "99fd5e88689c" -down_revision = "66121a0432bc" -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("models", schema=None) as batch_op: - batch_op.add_column( - sa.Column("description", sa.Text(), nullable=False, server_default="") - ) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table("models", schema=None) as batch_op: - batch_op.drop_column("description") - - # ### end Alembic commands ###