-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into berkeley-schema-migration
- Loading branch information
Showing
15 changed files
with
493 additions
and
60 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
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
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
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
50 changes: 50 additions & 0 deletions
50
nmdc_server/migrations/versions/317274ad8137_add_cog_mappings.py
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,50 @@ | ||
"""Add COG mappings | ||
Revision ID: 317274ad8137 | ||
Revises: 5403c7fe0b33 | ||
Create Date: 2024-08-30 20:13:12.480955 | ||
""" | ||
|
||
from typing import Optional | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "317274ad8137" | ||
down_revision: Optional[str] = "5403c7fe0b33" | ||
branch_labels: Optional[str] = None | ||
depends_on: Optional[str] = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"cog_term_to_function", | ||
sa.Column("term", sa.String(), nullable=False), | ||
sa.Column("function", sa.String(), nullable=False), | ||
sa.PrimaryKeyConstraint("term", "function", name=op.f("pk_cog_term_to_function")), | ||
) | ||
op.create_index( | ||
op.f("ix_cog_term_to_function_function"), "cog_term_to_function", ["function"], unique=False | ||
) | ||
op.create_table( | ||
"cog_term_to_pathway", | ||
sa.Column("term", sa.String(), nullable=False), | ||
sa.Column("pathway", sa.String(), nullable=False), | ||
sa.PrimaryKeyConstraint("term", "pathway", name=op.f("pk_cog_term_to_pathway")), | ||
) | ||
op.create_index( | ||
op.f("ix_cog_term_to_pathway_pathway"), "cog_term_to_pathway", ["pathway"], unique=False | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f("ix_cog_term_to_pathway_pathway"), table_name="cog_term_to_pathway") | ||
op.drop_table("cog_term_to_pathway") | ||
op.drop_index(op.f("ix_cog_term_to_function_function"), table_name="cog_term_to_function") | ||
op.drop_table("cog_term_to_function") | ||
# ### end Alembic commands ### |
52 changes: 52 additions & 0 deletions
52
nmdc_server/migrations/versions/5403c7fe0b33_migrate_study_names.py
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,52 @@ | ||
"""Migrate Study names | ||
Revision ID: 5403c7fe0b33 | ||
Revises: 0ff690fb929d | ||
Create Date: 2024-09-09 18:50:11.771035 | ||
""" | ||
|
||
from typing import Optional | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects.postgresql import JSONB | ||
from sqlalchemy.sql import column, table | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "5403c7fe0b33" | ||
down_revision: Optional[str] = "0ff690fb929d" | ||
branch_labels: Optional[str] = None | ||
depends_on: Optional[str] = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
submission_metadata = table( | ||
"submission_metadata", | ||
column("id", sa.String), | ||
column("metadata_submission", JSONB), | ||
column("study_name", sa.String), | ||
) | ||
|
||
connection = op.get_bind() | ||
submissions = connection.execute( | ||
sa.select([submission_metadata.c.id, submission_metadata.c.metadata_submission]) | ||
) | ||
|
||
for submission in submissions: | ||
study_name = submission.metadata_submission["studyForm"].get("studyName") | ||
if study_name: | ||
connection.execute( | ||
submission_metadata.update() | ||
.where(submission_metadata.c.id == submission.id) | ||
.values(study_name=study_name) | ||
) | ||
pass | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
pass | ||
# ### end Alembic commands ### |
Oops, something went wrong.