Skip to content

Commit

Permalink
Add migrations to properly deal with ProcessCalculation and `WorkCa…
Browse files Browse the repository at this point in the history
…lculation`

There has been a period, at the very beginning of the move to processes
where the node classes had the type `calculation.process.ProcessCalculation.`
These could represent either the execution of a workfunction or a workchain.

Therefore, we first convert all `ProcessCalculations` to `WorkCalculations`
and in a second step, we convert all `WorkCalculations` that have an attribute
called `function_name` to `WorkFunctionNode`. The only remaining `WorkCalculations`
then have to be `WorkChainNodes`.
  • Loading branch information
giovannipizzi committed Dec 11, 2018
1 parent ad89d51 commit 6a1d7f3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
19 changes: 14 additions & 5 deletions aiida/backends/djsite/db/migrations/0020_provenance_redesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import absolute_import

# Remove when https://github.com/PyCQA/pylint/issues/1931 is fixed
# pylint: disable=no-name-in-module,import-error
# pylint: disable=no-name-in-module,import-error,line-too-long
from django.db import migrations
from aiida.backends.djsite.db.migrations import upgrade_schema_version

Expand Down Expand Up @@ -117,6 +117,19 @@ class Migration(migrations.Migration):
AND db_dblink.type = 'createlink'
); -- Delete all outgoing CREATE links from FunctionCalculation and WorkCalculation nodes
UPDATE db_dbnode SET type = 'calculation.work.WorkCalculation.'
WHERE type = 'calculation.process.ProcessCalculation.';
-- First migrate very old `ProcessCalculation` to `WorkCalculation`
UPDATE db_dbnode SET type = 'node.process.workflow.workfunction.WorkFunctionNode.' FROM db_dbattribute
WHERE db_dbattribute.dbnode_id = db_dbnode.id
AND type = 'calculation.work.WorkCalculation.'
AND db_dbattribute.key = 'function_name';
-- WorkCalculations that have a `function_name` attribute are FunctionCalculations
UPDATE db_dbnode SET type = 'node.process.workflow.workchain.WorkChainNode.'
WHERE type = 'calculation.work.WorkCalculation.';
-- Update type for `WorkCalculation` nodes - all what is left should be `WorkChainNodes`
UPDATE db_dbnode SET type = 'node.process.calculation.calcjob.CalcJobNode.'
WHERE type LIKE 'calculation.job.%'; -- Update type for JobCalculation nodes
Expand All @@ -127,10 +140,6 @@ class Migration(migrations.Migration):
UPDATE db_dbnode SET type = 'node.process.workflow.workfunction.WorkFunctionNode.'
WHERE type = 'calculation.function.FunctionCalculation.'; -- Update type for FunctionCalculation nodes
UPDATE db_dbnode SET type = 'node.process.workflow.workchain.WorkChainNode.'
WHERE type = 'calculation.work.WorkCalculation.'; -- Update type for WorkCalculation nodes
UPDATE db_dblink SET type = 'create' WHERE type = 'createlink'; -- Rename `createlink` to `create`
UPDATE db_dblink SET type = 'return' WHERE type = 'returnlink'; -- Rename `returnlink` to `create`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from __future__ import print_function

# Remove when https://github.com/PyCQA/pylint/issues/1931 is fixed
# pylint: disable=no-name-in-module,import-error
# pylint: disable=no-name-in-module,import-error,line-too-long
from alembic import op
from sqlalchemy.sql import text

Expand Down Expand Up @@ -120,6 +120,19 @@ def upgrade():
AND db_dblink.type = 'createlink'
); -- Delete all outgoing CREATE links from WorkCalculation nodes
UPDATE db_dbnode SET type = 'calculation.work.WorkCalculation.'
WHERE type = 'calculation.process.ProcessCalculation.';
-- First migrate very old `ProcessCalculation` to `WorkCalculation`
UPDATE db_dbnode SET type = 'node.process.workflow.workfunction.WorkFunctionNode.'
WHERE type = 'calculation.work.WorkCalculation.'
AND attributes ? 'function_name';
-- WorkCalculations that have a `function_name` attribute are `WorkFunctionNode`
UPDATE db_dbnode SET type = 'node.process.workflow.workchain.WorkChainNode.'
WHERE type = 'calculation.work.WorkCalculation.';
-- Update type for `WorkCalculation` nodes - all what is left should be `WorkChainNodes`
UPDATE db_dbnode SET type = 'node.process.calculation.calcjob.CalcJobNode.'
WHERE type LIKE 'calculation.job.%'; -- Update type for JobCalculation nodes
Expand All @@ -129,9 +142,6 @@ def upgrade():
UPDATE db_dbnode SET type = 'node.process.workflow.workfunction.WorkFunctionNode.'
WHERE type = 'calculation.function.FunctionCalculation.'; -- Update type for FunctionCalculation nodes
UPDATE db_dbnode SET type = 'node.process.workflow.workchain.WorkChainNode.'
WHERE type = 'calculation.work.WorkCalculation.'; -- Update type for WorkCalculation nodes
UPDATE db_dblink SET type = 'create' WHERE type = 'createlink'; -- Rename `createlink` to `create`
UPDATE db_dblink SET type = 'return' WHERE type = 'returnlink'; -- Rename `returnlink` to `create`
Expand Down

0 comments on commit 6a1d7f3

Please sign in to comment.