-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
110 additions
and
4 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
51 changes: 51 additions & 0 deletions
51
flexmeasures/data/migrations/versions/2ac7fb39ce0c_add_attribute_column_to_data_source.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,51 @@ | ||
"""add attribute column to data source | ||
Revision ID: 2ac7fb39ce0c | ||
Revises: d814c0688ae0 | ||
Create Date: 2023-06-05 23:41:31.788961 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "2ac7fb39ce0c" | ||
down_revision = "d814c0688ae0" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# add the column `attributes` to the table `data_source` | ||
op.add_column( | ||
"data_source", | ||
sa.Column("attributes", sa.JSON(), nullable=True, default={}), | ||
) | ||
|
||
# add the column `attributes_hash` to the table `data_source` | ||
op.add_column( | ||
"data_source", | ||
sa.Column("attributes_hash", sa.LargeBinary(length=256), nullable=True), | ||
) | ||
|
||
# remove previous uniqueness constraint and add a new that takes attributes_hash into account | ||
op.drop_constraint(op.f("data_source_name_key"), "data_source", type_="unique") | ||
op.create_unique_constraint( | ||
"data_source_name_key", | ||
"data_source", | ||
["name", "user_id", "model", "version", "attributes_hash"], | ||
) | ||
|
||
|
||
def downgrade(): | ||
|
||
op.drop_constraint("data_source_name_key", "data_source", type_="unique") | ||
op.create_unique_constraint( | ||
"data_source_name_key", | ||
"data_source", | ||
["name", "user_id", "model", "version"], | ||
) | ||
|
||
op.drop_column("data_source", "attributes") | ||
op.drop_column("data_source", "attributes_hash") |
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