Skip to content

Commit

Permalink
DB Migration for Collections Data Model
Browse files Browse the repository at this point in the history
  • Loading branch information
bencap committed Oct 15, 2024
1 parent 8b62627 commit 21b6ae9
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions alembic/versions/c404b6719110_collections_data_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
"""Collections data model
Revision ID: c404b6719110
Revises: 2b6f40ea2fb6
Create Date: 2024-10-15 12:57:29.682271
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "c404b6719110"
down_revision = "2b6f40ea2fb6"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"collections",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("urn", sa.String(length=64), nullable=True),
sa.Column("private", sa.Boolean(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("badge_name", sa.String(), nullable=True),
sa.Column("description", sa.String(), nullable=True),
sa.Column("created_by_id", sa.Integer(), nullable=True),
sa.Column("modified_by_id", sa.Integer(), nullable=True),
sa.Column("creation_date", sa.Date(), nullable=False),
sa.Column("modification_date", sa.Date(), nullable=False),
sa.ForeignKeyConstraint(
["created_by_id"],
["users.id"],
),
sa.ForeignKeyConstraint(
["modified_by_id"],
["users.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_collections_created_by_id"), "collections", ["created_by_id"], unique=False)
op.create_index(op.f("ix_collections_modified_by_id"), "collections", ["modified_by_id"], unique=False)
op.create_index(op.f("ix_collections_urn"), "collections", ["urn"], unique=True)

op.create_table(
"collection_user_associations",
sa.Column("collection_id", sa.Integer(), nullable=False),
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column(
"contribution_role",
sa.Enum(
"admin",
"editor",
"viewer",
name="contributionrole",
native_enum=False,
create_constraint=True,
length=32,
),
nullable=False,
),
sa.ForeignKeyConstraint(
["collection_id"],
["collections.id"],
),
sa.ForeignKeyConstraint(
["user_id"],
["users.id"],
),
sa.PrimaryKeyConstraint("collection_id", "user_id"),
)

op.create_table(
"collection_experiments",
sa.Column("collection_id", sa.Integer(), nullable=False),
sa.Column("experiment_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["collection_id"],
["collections.id"],
),
sa.ForeignKeyConstraint(
["experiment_id"],
["experiments.id"],
),
sa.PrimaryKeyConstraint("collection_id", "experiment_id"),
)

op.create_table(
"collection_score_sets",
sa.Column("collection_id", sa.Integer(), nullable=False),
sa.Column("score_set_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["collection_id"],
["collections.id"],
),
sa.ForeignKeyConstraint(
["score_set_id"],
["scoresets.id"],
),
sa.PrimaryKeyConstraint("collection_id", "score_set_id"),
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("collection_score_sets")
op.drop_table("collection_experiments")
op.drop_table("collection_user_associations")
op.drop_index(op.f("ix_collections_urn"), table_name="collections")
op.drop_index(op.f("ix_collections_modified_by_id"), table_name="collections")
op.drop_index(op.f("ix_collections_created_by_id"), table_name="collections")
op.drop_table("collections")
# ### end Alembic commands ###

0 comments on commit 21b6ae9

Please sign in to comment.