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
7 changed files
with
275 additions
and
7 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
115 changes: 115 additions & 0 deletions
115
aiida/backends/djsite/db/migrations/0023_calc_job_option_attribute_keys.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,115 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida_core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
# pylint: disable=invalid-name,too-few-public-methods | ||
"""Migration of CalcJobNode attributes for metadata options whose key changed.""" | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
from __future__ import absolute_import | ||
|
||
# Remove when https://github.com/PyCQA/pylint/issues/1931 is fixed | ||
# pylint: disable=no-name-in-module,import-error | ||
from django.db import migrations | ||
|
||
from aiida.backends.djsite.db.migrations import upgrade_schema_version | ||
|
||
REVISION = '1.0.23' | ||
DOWN_REVISION = '1.0.22' | ||
|
||
|
||
class Migration(migrations.Migration): | ||
"""Migration of CalcJobNode attributes for metadata options whose key changed. | ||
Renamed attribute keys: | ||
* `custom_environment_variables` -> `environment_variables` | ||
* `jobresource_params` -> `resources` | ||
* `_process_label` -> `process_label` | ||
* `parser` -> `parser_name` | ||
Deleted attributes: | ||
* `linkname_retrieved` (We do not actually delete it just in case some relies on it) | ||
""" | ||
|
||
dependencies = [ | ||
('db', '0022_dbgroup_type_string_change_content'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL( | ||
sql=""" | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^custom_environment_variables', 'environment_variables') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key like 'custom_environment_variables%' AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- custom_environment_variables -> environment_variables | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^jobresource_params', 'resources') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key like 'jobresource_params%' AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- jobresource_params -> resources | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^_process_label', 'process_label') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key like '_process_label' AND | ||
node.type like 'node.process.%'; | ||
-- _process_label -> process_label | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^parser', 'parser_name') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key like 'parser%' AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- parser -> parser_name | ||
""", | ||
reverse_sql=""" | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^environment_variables', 'custom_environment_variables') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key like 'environment_variables%' AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- environment_variables -> custom_environment_variables | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^resources', 'jobresource_params') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key like 'resources%' AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- resources -> jobresource_params | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^process_label', '_process_label') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key like 'process_label%' AND | ||
node.type like 'node.process.%'; | ||
-- process_label -> _process_label | ||
UPDATE db_dbattribute AS attribute | ||
SET key = regexp_replace(attribute.key, '^parser_name', 'parser') | ||
FROM db_dbnode AS node | ||
WHERE | ||
attribute.key like 'parser_name%' AND | ||
node.type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- parser_name -> parser | ||
"""), | ||
upgrade_schema_version(REVISION, DOWN_REVISION) | ||
] |
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
98 changes: 98 additions & 0 deletions
98
aiida/backends/sqlalchemy/migrations/versions/7ca08c391c49_calc_job_option_attribute_keys.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,98 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida_core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
# pylint: disable=invalid-name,no-member | ||
"""Migration of CalcJobNode attributes for metadata options whose key changed. | ||
Revision ID: 7ca08c391c49 | ||
Revises: e72ad251bcdb | ||
Create Date: 2019-01-15 15:03:43.876133 | ||
""" | ||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
|
||
# Remove when https://github.com/PyCQA/pylint/issues/1931 is fixed | ||
# pylint: disable=no-name-in-module,import-error | ||
from alembic import op | ||
from sqlalchemy.sql import text | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '7ca08c391c49' | ||
down_revision = 'e72ad251bcdb' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
"""Migration of CalcJobNode attributes for metadata options whose key changed. | ||
Renamed attribute keys: | ||
* `custom_environment_variables` -> `environment_variables` | ||
* `jobresource_params` -> `resources` | ||
* `_process_label` -> `process_label` | ||
* `parser` -> `parser_name` | ||
Deleted attributes: | ||
* `linkname_retrieved` (We do not actually delete it just in case some relies on it) | ||
""" | ||
conn = op.get_bind() | ||
|
||
statement = text(""" | ||
UPDATE db_dbnode | ||
SET attributes = jsonb_set(attributes, '{environment_variables}', to_jsonb(attributes->>'custom_environment_variables')) | ||
WHERE | ||
attributes ? 'custom_environment_variables' AND | ||
type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
UPDATE db_dbnode SET attributes = attributes - 'custom_environment_variables' | ||
WHERE | ||
attributes ? 'custom_environment_variables' AND | ||
type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- custom_environment_variables -> environment_variables | ||
UPDATE db_dbnode | ||
SET attributes = jsonb_set(attributes, '{resources}', to_jsonb(attributes->>'jobresource_params')) | ||
WHERE | ||
attributes ? 'jobresource_params' AND | ||
type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
UPDATE db_dbnode SET attributes = attributes - 'jobresource_params' | ||
WHERE | ||
attributes ? 'jobresource_params' AND | ||
type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- jobresource_params -> resources | ||
UPDATE db_dbnode | ||
SET attributes = jsonb_set(attributes, '{process_label}', to_jsonb(attributes->>'_process_label')) | ||
WHERE | ||
attributes ? '_process_label' AND | ||
type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
UPDATE db_dbnode SET attributes = attributes - '_process_label' | ||
WHERE | ||
attributes ? '_process_label' AND | ||
type like 'node.process.%'; | ||
-- _process_label -> process_label | ||
UPDATE db_dbnode | ||
SET attributes = jsonb_set(attributes, '{parser_name}', to_jsonb(attributes->>'parser')) | ||
WHERE | ||
attributes ? 'parser' AND | ||
type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
UPDATE db_dbnode SET attributes = attributes - 'parser' | ||
WHERE | ||
attributes ? 'parser' AND | ||
type = 'node.process.calculation.calcjob.CalcJobNode.'; | ||
-- parser -> parser_name | ||
""") | ||
conn.execute(statement) | ||
|
||
|
||
def downgrade(): | ||
pass |
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