-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add attributes column to
data_source
table (#750)
* feat: revision to add `attributes` column to the `data_source` table Signed-off-by: Victor Garcia Reolid <[email protected]> * feat: add `attributes` column to the DataSource model Signed-off-by: Victor Garcia Reolid <[email protected]> * feat: add sensors relationship in DataSource Signed-off-by: Victor Garcia Reolid <[email protected]> * fix: make sensors relationship viewonly Signed-off-by: Victor Garcia Reolid <[email protected]> * feat: add helper methods to DataSource Signed-off-by: Victor Garcia Reolid <[email protected]> * feat: add attributes hash Signed-off-by: Victor Garcia Reolid <[email protected]> * feat: add attributes to the function get_or_create_source Signed-off-by: Victor Garcia Reolid <[email protected]> * feat: add attribute hash to get_or_create_source Signed-off-by: Victor Garcia Reolid <[email protected]> * changing backref from "dynamic" to "select" Signed-off-by: Victor Garcia Reolid <[email protected]> * feat: add hash_attributes static method Signed-off-by: Victor Garcia Reolid <[email protected]> * fix: use hash_attributes static method Signed-off-by: Victor Garcia Reolid <[email protected]> * feat: adding attributes_hash to the DataSource unique constraint list Signed-off-by: Victor Garcia Reolid <[email protected]> * fix: add constraint to migration and downgrade Signed-off-by: Victor Garcia Reolid <[email protected]> * fix: only returning keys from the attributes field Signed-off-by: Victor Garcia Reolid <[email protected]> * docs: fix docstring Signed-off-by: Victor Garcia Reolid <[email protected]> * fix: use default value Signed-off-by: Victor Garcia Reolid <[email protected]> * fix: allow creating new attributes with the method `set_attributes` Signed-off-by: Victor Garcia Reolid <[email protected]> * docs: add changelog entry Signed-off-by: Victor Garcia Reolid <[email protected]> * docs: add db upgrade warning Signed-off-by: Victor Garcia Reolid <[email protected]> --------- Signed-off-by: Victor Garcia Reolid <[email protected]>
- Loading branch information
1 parent
9291830
commit 3772b08
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