-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #750 from MolSSI/next
Use computed column for dataset lname
- Loading branch information
Showing
3 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...fractal/alembic/versions/2023-09-14-13cb230def11_use_computed_column_for_dataset_lname.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,37 @@ | ||
"""Use computed column for dataset lname | ||
Revision ID: 13cb230def11 | ||
Revises: d1ee87a66b71 | ||
Create Date: 2023-09-14 18:50:20.067940 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "13cb230def11" | ||
down_revision = "d1ee87a66b71" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.execute(sa.text("ALTER TABLE base_dataset DROP COLUMN lname;")) | ||
op.execute( | ||
sa.text( | ||
"ALTER TABLE base_dataset ADD COLUMN lname CHARACTER VARYING(100) NOT NULL GENERATED ALWAYS AS (lower((name)::text)) stored;" | ||
) | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.execute(sa.text("ALTER TABLE base_dataset DROP COLUMN lname;")) | ||
op.execute(sa.text("ALTER TABLE base_dataset ADD COLUMN lname CHARACTER VARYING(100)")) | ||
op.execute(sa.text("UPDATE base_dataset SET lname = lower(name)")) | ||
op.alter_column("base_dataset", "lname", nullable=False) | ||
op.create_unique_constraint("ux_base_dataset_dataset_type_lname", "base_dataset", ["dataset_type", "lname"]) | ||
|
||
# ### end Alembic commands ### |
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