capactio / capact

Simple way to manage applications and infrastructure.
https://capact.io
Apache License 2.0
80 stars 19 forks source link

Prevent TypeInstance deletion when it's used by others #632

Closed mszostok closed 2 years ago

mszostok commented 2 years ago

Description

Blocked by: https://github.com/capactio/capact/issues/645

Prevent delete action when TypeInstance is used by others. Currently, we can delete TypeInstance without any notification that others are linked to it. In case of delegated storage proposal, this may break our flow as we won't be able to retrieve data for all linked TypeInstances.

Reason

Currently, we allow deleting TypeInstance that is used by others. Until now, it wasn't a big issue but after introducing delegated storage functionality, it will become more problematic as we use this relation to ask to resolve stored information.

Use cases

Additional

It's a small piece of the rollback proposal: https://github.com/capactio/capact/blob/main/docs/proposal/20201209-action-rollback.md - rest logic will be handled by dedicated issue #502

mszostok commented 2 years ago

Example:

                    // Check if a given TypeInstance is not used by others
                    CALL {
                        WITH ti
                        WITH ti
                        MATCH (ti)-[:USES]->(others:TypeInstance)
                        WITH count(others) as othersLen
                        RETURN  othersLen > 1 as isUsed
                    }
                    CALL apoc.util.validate(isUsed, apoc.convert.toJson({code: 400}), null)
mszostok commented 2 years ago

It turns out that it was implemented but there was a bug that is fixed by https://github.com/capactio/capact/pull/654