data-api-builder icon indicating copy to clipboard operation
data-api-builder copied to clipboard

[CLI]: New command/verb: `delete`

Open abhishekkumams opened this issue 3 years ago • 5 comments

Command Name:

delete

delete command will allow users to remove fields from the config file.

Proposed Usage:

Deleting a relationship

dab delete <<entity_name>> --relationship "<<relationship_name>>"

An entity can have many relationship fields defined in the config file like below.

"relationships": {
        "publishers": {
          "cardinality": "one",
          "target.entity": "Publisher"
        },
        "reviews": {
          "cardinality": "many",
          "target.entity": "Review"
        },
        "authors": {
          "cardinality": "many",
          "target.entity": "Author",
          "linking.object": "book_author_link",
          "linking.source.fields": [
            "book_id"
          ],
          "linking.target.fields": [
            "author_id"
          ]
        }
      },

When a relationship name that exists in the config file is specified, then that particular relationship should be removed.

When * is specified as the relationship name, then all the relationships defined for that entity should be removed from the config file.

Deleting a mapping

dab delete <<entity_name>> --mapping "<<column_name>>"

When a valid column_name is specified, the mapping defined for that column should be deleted. When * is specified, then mappings defined for all the columns should be removed from the config file.

Delete a particular role

dab delete <<entity_name>> --permissions "<<role_name>>"

When a valid role_name is specified, it should be removed from the permissions object. However, if it is the only role present, it should result in an error as it is not possible to have an entity without any permissions defined.

Deleting an entity

dab delete <<entity_name>>

  • When an entity that is not present in the config file is specified, it should result in an error.
  • It is possible that the entity specified in the config file could have relationships defined on it. There could be other entities in the config file that could have a relationship defined with this specified entity as the target.entity. If such a case is identified, then the command should result in an error with a suggestion that these relationships need to be deleted before deleting the entity.
  • When the entity to delete is not part of any of the relationships defined in other entities, then the entity specified should be removed from the config file.

Deleting all entities

dab delete *

This essentially resets the entire config file. All the entities that were created will be removed. The resulting config will look the same as it was after running only the init command

abhishekkumams avatar Jul 04 '22 09:07 abhishekkumams

Need a option for delete mappings section

Aniruddh25 avatar Jul 19 '22 18:07 Aniruddh25

Let's re-triage and consider for May due to a growing need for this to make a complete local development experience.

seantleonard avatar May 02 '23 16:05 seantleonard

@yorek @sajeetharan @Aniruddh25 @seantleonard @abhishekkumams @ayush3797 @aaronburtle

I've triaged and come up with a proposal with regards to how the delete command could look like for removing various fields/sections in the config file.

In the first iteration, I would ideally like to refrain from introducing options for removing very specific items. For instance, removing a database policy for a given action defined under a given role (or) removing an action defined under a given role would not be supported in the first iteration. Options more removing such granular fields such can be added iteratively.

Please kindly take a look and share your thoughts.

severussundar avatar May 10 '23 15:05 severussundar

Another perspective here, Most GraphQL configuration generation tools do not include a "delete" command in their command-line interfaces (CLI). Adding a "delete" command might lead to complications. However, alternative commands such as "updateWithReplace," "updateWithSet," "updateWithAdd," or "updateWithRemove" can be considered. These commands offer different functionalities for modifying or updating config data without performing direct deletions.

sajeetharan avatar May 15 '23 08:05 sajeetharan

Thanks for the suggestion. When you get a chance, please elaborate with more details and usage examples for each of the commands - updateWithReplace, updateWithSet and updateWithAdd.

Adding more context: In this discussion thread, one of the users had requested a way for removing an incorrectly created relationship.

severussundar avatar May 16 '23 05:05 severussundar

Less necessary now that we are considering the UI.

JerryNixon avatar Sep 06 '24 16:09 JerryNixon