Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include model name and storage type in Zendro model definitions #5

Closed
asishallab opened this issue Jun 26, 2023 · 1 comment
Closed

Comments

@asishallab
Copy link

asishallab commented Jun 26, 2023

Extend the existing code to include model name and storage information

A typical Zendro data model definition requires these two additional arguments:

  • extend your script to use named command line arguments, e.g. with argparse
  • the name of the data model, e.g. "model" : "book". Extract this from the BrApi-file-name.
  • the storage-type (command line arg -s or --storage-type), e.g. "storageType" : "sql". Provide an optional third argument to your script. This is the storage type to be used for all generated Zendro models. (for details see below)
  • add a default primary key to all data models (command line argument -p or --primary-key-name). By default this is set to id and of type Int.
  • Add another optional argument (-t or --primary-key-type). By default this is Int but can be String. Make sure to validate this and inform the user about the possible two types (see docu of argparse about how to add usage information).
  • In the usage of your programm inform the user that if any of the primary key related arguments are given, identifiers are created that Zendro will not take care of automatically, meaning that no database sequence will be used to automatically populate the primary key (id) property of new records. However, the user can write a Zendro migration to add e.g. a database sequence to do exactly that for his custom primary keys.
  • Make sure the current properties become the key-value pairs of an attributes object of the Zendro definition. See this example for details:
{
  "model" : "book",
  "storageType" : "sql",
  "attributes" : {
    "title" : {"type":"String", "description": "The book's title"},
    "publisher_id": "Int"
  }
}

Storage-Type details

If this argument is not provided, use sql as default storage-type. If it is provided, validate that it is correctly spelled and one of the accepted storage-types (see Zendro documentation). If not inform with a meaningful error message. Put this optional argument in your usage information, too.

@LzLang
Copy link
Owner

LzLang commented Jul 23, 2023

I tried to implement what you requested, here is a current example of the result.

Example of Study:

{
    "model": "Study",
    "storageType": "sql",
    "attributes": {
        "primary_id": "Int",
        "active": {
            "description": "Is this study currently active",
            "type": "Boolean"
        },
        "commonCropName": {
            "description": "Common name for the crop associated with this study",
            "type": "String"
        },
        "culturalPractices": {
            "description": "MIAPPE V1.1 (DM-28) Cultural practices - General description of the cultural practices of the study.",
            "type": "String"
        }
}

@LzLang LzLang closed this as completed Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants