MultiPaaS

Model your data

The model describes the data your application keeps. Read the model first if its words are new. This guide uses APP_ID, the id that multipaas apps create printed.

See the model

multipaas model show --app APP_ID

It prints your entities, fields, enums and constraints with their ids. Use those ids in the commands below, and never guess one.

Add entities

multipaas entity create --app APP_ID --name Recipe

The entity's id is RECIPE_ID. entity create prints it, and model show lists it. Make a second entity the same way, so the fields below have something to point at:

multipaas entity create --app APP_ID --name Cookbook

Its id is COOKBOOK_ID.

An entity's GraphQL type name comes from its name. It can't be one the generated API has for itself, such as Query, User or File. Each entity's and enum's type name also reserves names the API builds from it, such as ItemFilter, ItemPage and ItemReferenceFilter for Item, and two of them can't reserve the same name: an entity named ItemPage beside Item is refused, and so is one named ItemReference, since it and Item both reserve ItemReferenceFilter. Keep the entity's name and pass another --type-name, such as --type-name ItemLink. See the model.

In an application with workflows, WorkflowRun and WorkflowRunStatus are type names the generated API has for itself too, and WorkflowRun is such a plural name, because it makes the entity's generated query workflowRun. An entity or enum with one is refused in an application that has workflows, and the first workflow is refused in an application that has such an entity or enum. Both are refused with WORKFLOW_RUN_NAME_CLASH, not the code the other names get. To clear it, give the entity or enum a different --type-name with multipaas entity create or update, or multipaas enum create or update, and give the entity a different --plural-name when the plural clashes. Changing only --name keeps the type name of one that already exists. Or delete the workflows. See the model.

Add fields

multipaas field add --app APP_ID --entity RECIPE_ID --name Title --type text --required

--type is one of text, number, boolean, timestamp, enum, reference, related or file. file, and --max-file-bytes for its size limit, need CLI 1.1.0 or later. The new field's id is TITLE_FIELD_ID. field add prints it.

A text or enum field can hold a list of values instead of one. Add --list when you add the field. You can't add it to a field later or remove it. A list's default is a JSON array. --list needs CLI 1.5.0 or later:

multipaas field add --app APP_ID --entity RECIPE_ID --name Tags --type text --list --default '["a"]'

A field can have a default, which a record gets when it is written without a value. --not-null makes the field always hold one, and gives the default to existing records that have none:

multipaas field add --app APP_ID --entity RECIPE_ID --name Servings --type number --default 2 --not-null

Write the default as the field's type: a number, true or false, an enum value, an ISO timestamp, a record id for a reference field, or text. A file or related field has no default. field update changes it, removes it and turns not-null off. FIELD_ID is the field's id, from model show:

multipaas field update --app APP_ID --id FIELD_ID --default VALUE
multipaas field update --app APP_ID --id FIELD_ID --clear-default --nullable
multipaas field update --app APP_ID --id FIELD_ID --nullable

A not-null field can't lose its default, so remove one with --clear-default --nullable together. These flags need CLI 1.4.0 or later.

A reference field points at a record of another entity. Add one to Recipe, and give it Cookbook's id:

multipaas field add --app APP_ID --entity RECIPE_ID --name Cookbook --type reference --references COOKBOOK_ID

Its id is COOKBOOK_FIELD_ID, printed by field add.

A related field lists the records that point back. Add it to Cookbook, and give it the id of the reference field:

multipaas field add --app APP_ID --entity COOKBOOK_ID --name Recipes --type related --related COOKBOOK_FIELD_ID

Add an enum

An enum is a fixed list of values. Create it, then give a field that type:

multipaas enum create --app APP_ID --name Difficulty --values easy,medium,hard
multipaas field add --app APP_ID --entity RECIPE_ID --name Difficulty --type enum --enum-type ENUM_ID

ENUM_ID is the id that enum create printed.

Describe your model

Give an entity, a field or an enum a --description of up to 1000 characters. Each is plain text saying what it means. Agents that connect to your app see it. You can also give one when you create it. --description and --value-description need CLI 1.19.0 or later. These commands describe the Recipe entity, its Servings field and the Difficulty enum from the sections above. SERVINGS_FIELD_ID is the id that field add printed for Servings:

multipaas entity update --app APP_ID --id RECIPE_ID --description 'A dish with its ingredients and steps.'
multipaas field update --app APP_ID --id SERVINGS_FIELD_ID --description 'How many people the recipe feeds.'
multipaas enum update --app APP_ID --id ENUM_ID --values easy,medium,hard --description 'How hard a recipe is to cook.' --value-description 'hard=Needs a food processor or an oven.'

--value-description VALUE=TEXT describes one value of an enum. Repeat it for each value, and give it only together with --values. VALUE must be one of the values given. --values replaces the whole list of values, so give --value-description again for each value that should keep its description.

--description '' clears an entity's, a field's or an enum's description. --value-description 'VALUE=' clears one value's description, and so does leaving that value out of --value-description when you send --values again:

multipaas entity update --app APP_ID --id RECIPE_ID --description ''
multipaas enum update --app APP_ID --id ENUM_ID --values easy,medium,hard --value-description 'hard='

Make fields unique together

multipaas constraint add --app APP_ID --entity RECIPE_ID --fields TITLE_FIELD_ID,COOKBOOK_FIELD_ID

No two records in the same app-tenant can then hold the same values in both of those fields, and the same goes for the app-wide records of one environment. Two app-tenants, or two environments, can hold the same values.

You can add more constraints to the same entity, up to 10, each over a different set of fields. Each one is enforced separately: a record is refused if it repeats another's values for any one of them. Adding the same set of fields twice is refused with DUPLICATE_CONSTRAINT, and an eleventh constraint with CONSTRAINT_LIMIT. When a write breaks a constraint, the API's VALIDATION error lists one fieldErrors entry per field of each broken constraint, and each entry's constraint is that constraint's id, as multipaas model show lists it.

The model is shared by every environment, so adding the constraint checks all of the application's live environments, and a duplicate in any of them refuses it. A deleted environment's records don't count. constraint add takes no --env and acts in the application's default environment, and the refusal names the duplicate records only when they are in that environment and you can read them. A duplicate anywhere else is reported only as being in another environment, and that can be the environment your project is pinned to. The refusal can name some duplicates and also say that records in another environment, or in other app-tenants, share values, so you may have more than one set to fix. A caller who can't read a duplicate, such as someone who can read app-tenant records but not app-wide ones, is told nothing about it, and can get only the bare "existing records share values" message.

To find the duplicates, take an ENV_ID from multipaas envs list --app APP_ID. List that environment's app-wide records with multipaas records list --app APP_ID --entity RECIPE_ID --app-wide --env ENV_ID, or an app-tenant's with multipaas records list --app APP_ID --entity RECIPE_ID --tenant APP_TENANT_ID. multipaas tenants list --app APP_ID --env ENV_ID shows that environment's app-tenants. Fix or remove the duplicates that are named first, then those in the other environment, and run constraint add again each time. If you can't read the records, ask someone who can to clear them.

Change or delete

entity update, field update and enum update take --id and change only the flags you give.

entity delete, enum delete, field delete and constraint delete need CLI 1.9.0 or later. entity retire, enum retire, field retire and constraint retire are the deprecated names and still work.

The four delete commands also take --id:

multipaas field delete --app APP_ID --id FIELD_ID

FIELD_ID is the id of the field to delete, from model show. Other items take their own ids the same way.

Deleting is refused while something else depends on the item. Delete what depends on it first.

What a change does

Each change takes effect at once and prints a new API version. Your apps stay on the version they are pinned to. Read about the generated API to see how. To get newer API features with no model change, see Upgrade to a newer API version.

More