# 4.0 Migration Guide

In this document we describe the steps that should be taken to migrate from `orchestrator-core` v3 to v4.

## About 4.0

### Removed caching of domain models

In this release we have removed the caching of domain models. Domain models will always be loaded from the database.

### Added Target.VALIDATE

In this release, a new workflow target, `VALIDATE`, has been added
for [validation workflows](../architecture/application/workflow.md#validate).
Previously, the `SYSTEM` target was used for validation workflows, which implied that they were expected to run in a
system context. However, this was not appropriate for all validation workflows.
To address this, the new `VALIDATE` target has been introduced specifically for validation workflows. The `SYSTEM`
target is now reserved exclusively for system workflows.

The change of the `SYSTEM` target to `VALIDATE` is a breaking change, as it will break any workflows that are using the
`SYSTEM` target for validation workflows. You will need to update your workflows to use the `VALIDATE` target instead.

In the Steps section below we describe how to update your workflows to use the new `VALIDATE` target.

## Steps

To use 4.0.0, all workflows must have run to completion. The `cache_domain_models` step no longer is part of the codebase
therefore `in flight` workflows will fail.

After running the migration `(2025-05-08_cdf8758831d4_add_is_task_to_workflow.py)`, the workflow table should look like this:

```sql
| workflow_id                          | name                       | target | is_task | description                                                             | created_at                        | deleted_at |
|--------------------------------------|----------------------------|--------|---------|-------------------------------------------------------------------------|-----------------------------------|------------|
| ded79954-f16e-422b-a204-7770a59757e8 | modify_note                | MODIFY | FALSE   | Modify Note                                                             | 2025-05-01 09:57:28.033504 +00:00 | <null>     |
| ca6a76ff-dd4e-4f66-9fb0-cee1878f0d20 | task_clean_up_tasks        | SYSTEM | FALSE   | Clean up old tasks                                                      | 2025-05-01 09:57:28.033504 +00:00 | <null>     |
| 40058c3d-0c95-47f4-a75f-93719299c5be | task_resume_workflows      | SYSTEM | FALSE   | Resume all workflows that are stuck on tasks with the status 'waiting'  | 2025-05-01 09:57:28.033504 +00:00 | <null>     |
| 33b5520e-85d4-4ca1-8713-d26f7de5b7a5 | task_validate_products     | SYSTEM | FALSE   | Validate products                                                       | 2025-05-01 09:57:28.033504 +00:00 | <null>     |
| 94d4889e-6bb6-4724-a9d2-f21696fe6f43 | task_validate_product_type | SYSTEM | FALSE   | Validate all subscriptions of Product Type                              | 2025-05-01 09:57:28.033504 +00:00 | <null>     |
| 0c4f3b8d-2a1e-4b5f-9a7c-6d8e0f1b2c3d | validate_some_thing        | SYSTEM | FALSE   | Validate The thing                                                      | 2025-05-01 09:57:28.033504 +00:00 | <null>     |
| f4b0a2c1-5d3e-4c8f-9b6d-7a2e5f3b8c4e | validate_another_thing     | SYSTEM | FALSE   | Validate Another thing                                                  | 2025-05-01 09:57:28.033504 +00:00 | <null>     |
```

The `target` in this table is no longer valid for the `validate_some_thing` and `validate_another_thing`
workflows. You will need to update the `target` to `VALIDATE` for these workflows. You will also need to update the
is_task column to `TRUE` for all targets that are `SYSTEM` or `VALIDATE`. This is because the `is_task` column is used to
determine if a workflow is a task or not. If the `is_task` column is set to `FALSE`, the workflow will not be run as a task.
Tasks are `SYSTEM` or `VALIDATE` workflows that are run in the context of a system.

Example on how to update the `target` and `is_task` for all workflows that start with `validate_`:

```sql
UPDATE workflow
SET target = 'VALIDATE', is_task = TRUE
WHERE name LIKE 'validate_%';
```

Example on how to update the `target` and `is_task` for all workflows that are `SYSTEM` or `VALIDATE`:

```sql
UPDATE workflow
SET is_task = TRUE
WHERE target IN ('SYSTEM', 'VALIDATE');
```

This will update the `target` for all workflows that are `SYSTEM` or `VALIDATE` and set the `is_task` column to `TRUE`.

This is a breaking change, so you will need to test your workflows after making this change to ensure that they are
working as expected.
