Skip to content

civex schema

Manage schemas (data structure definitions)

Command Description
add-field Add a field to a schema.
add-unique Require a combination of fields to be unique.
charts The charts a list of a kind of record opens with
create Define a new schema.
delete Delete a schema (and the records typed by it) to Recently Deleted.
exports Exports saved with a schema: which files, how they are laid out
index Index a field in this computer's database, or stop indexing it.
lint Report schema and field names that aren't valid slugs.
list List all schemas.
preview-formula Try a formula without saving it.
purge Permanently delete a schema that's already in Recently Deleted. Irreversible.
remove-field Remove a field from a schema.
remove-unique Remove a uniqueness key (give the same fields it was added with).
restore Restore a soft-deleted schema (and the records cascade-deleted with it).
restore-field Restore a removed field, with the values records still hold for it.
show Inspect a schema's fields (including inherited).
unique List a schema's uniqueness keys.
update Update a schema's name, label, description, or record name template.
update-field Update a field's name, label, required flag, or restrictions.

civex schema add-field

Add a field to a schema.

The field name is a slug because workflow steps reference it by name (e.g. civex.get_field's field:). Use --label for the human-readable version shown in the UI and in civex schema show.

Restriction examples:

--type integer --min 0 --max 100
--type string --choices "left,right,bilateral"
--type string --max-length 255
--type file --accept ".csv,.txt" --max-size 10485760
--type float --unit m --min 0
--type date --precision month
--type geo --geometry-types Point --bbox "-12,48,4,62"
--type datetime --from-file audio --filename-pattern "YYYYMMDD[-_]HHmmSS"
--type formula --expression "mass / height ** 2" --decimals 1

Usage

civex schema add-field [OPTIONS] SCHEMA_NAME FIELD_NAME

Arguments

Argument Type Required Description
SCHEMA_NAME str yes Schema to add the field to
FIELD_NAME str yes Field name — the machine key used by workflows and CSV headers (lowercase, underscores, e.g. visited_on)

Options

Option Type Default Description
--label, -l str Human-facing display name, free text (e.g. 'Visited On')
--type, -t str Field type: integer | float | string | longtext | boolean | date | datetime | geo | file | file_list | reference | reference_list | tags | url | formula (required)
--required, --optional flag --optional Whether the field is required
--references str Target schema (--type reference)
--min float Minimum value (integer/float)
--max float Maximum value (integer/float)
--choices str Comma-separated allowed values (string)
--max-length int Maximum character length (string)
--accept str Allowed extensions e.g. '.csv,.txt' (file/file_list)
--max-size int Maximum file size in bytes (file/file_list)
--unit str Unit every value is stored in, e.g. m or degC (float). Values are never converted after the fact.
--precision str Least precise date accepted: year | month | day (date)
--geometry-types str Comma-separated shapes allowed, e.g. Point,Polygon (geo)
--bbox str Allowed area as WEST,SOUTH,EAST,NORTH in degrees; west greater than east crosses the 180th meridian (geo)
--from-file str Fill this field from the name of the file in this file field when it is left blank (string, integer, float, date, datetime). Needs --filename-pattern.
--filename-pattern str How to read the value out of the file name: for a date or datetime a token format such as YYYYMMDD[-_]HHmmSS (tokens YYYY MM DD HH mm SS, anything else a regular expression) or a regular expression with named groups year, month, day, hour, minute, second; for text and numbers a regular expression whose first capture group is the value. Give it more than once to try several patterns in order.
--expression, -e str The formula (--type formula): field names, numbers, "text", + - * / // % **, comparisons, and/or/not, a if condition else b, and functions such as round(x, 2), days_between(start, end) and concat(a, "-", b). Worked out when a record is read, never stored.
--result str What a formula gives: float | integer | string | boolean | date | datetime. Left out, it is worked out from the formula.
--decimals int Decimal places for a formula giving a float

civex schema add-unique

Require a combination of fields to be unique.

No two records of the schema may then hold the same values in all of the given fields, within the same parent record (or the same collection, for a top-level record). A record with a blank in any of them is not constrained. Refused while existing records already share values.

Usage

civex schema add-unique NAME FIELDS...

Arguments

Argument Type Required Description
NAME str yes Schema name
FIELDS... str yes The fields of the key (the schema's own)

civex schema charts

The charts a list of a kind of record opens with

Usage

civex schema charts COMMAND [ARGS]...

civex schema create

Define a new schema.

The name is a slug because workflow YAML, CSV headers and display fields all reference it as text. Put spaces and capitals in --label instead — that is what the UI and CLI show, and it can be changed freely.

Usage

civex schema create [OPTIONS] NAME

Arguments

Argument Type Required Description
NAME str yes Schema name — the machine key used by workflows and CSV headers (lowercase, underscores, e.g. soil_sample)

Options

Option Type Default Description
--label, -l str Human-facing display name, free text (e.g. 'Soil Sample')
--description, -d str Schema description
--parent, -p str Inherit fields from this schema

civex schema delete

Delete a schema (and the records typed by it) to Recently Deleted.

Reversible with civex schema restore within the retention window (see civex trash list); civex schema purge deletes permanently.

Usage

civex schema delete [OPTIONS] NAME

Arguments

Argument Type Required Description
NAME str yes Schema name

Options

Option Type Default Description
--yes, -y flag false Skip confirmation prompt

civex schema exports

Exports saved with a schema: which files, how they are laid out

Usage

civex schema exports COMMAND [ARGS]...

civex schema index

Index a field in this computer's database, or stop indexing it.

Sorting by an indexed field, and filtering it by a value or a range, is fast however many records there are; saving records of its kind gets slightly slower. The choice is a setting of this computer's database, never synced. The index is built in the background (a while on a big table; lists work meanwhile, only slower). A field in a uniqueness key is always indexed.

Usage

civex schema index [OPTIONS] NAME FIELD_NAME

Arguments

Argument Type Required Description
NAME str yes Schema name
FIELD_NAME str yes The field to index

Options

Option Type Default Description
--off flag false Stop asking for the index

civex schema lint

Report schema and field names that aren't valid slugs.

Names are validated when they're created or renamed, so anything listed here predates that rule. Nothing is broken — these names still resolve — but they read badly in workflow YAML and CSV headers. Rename with civex schema update --rename / civex schema update-field --rename and move the human-readable text to --label.

Usage

civex schema lint

civex schema list

List all schemas.

Usage

civex schema list

civex schema preview-formula

Try a formula without saving it.

Checks it as adding the field would (the fields it reads exist, their kinds fit, no formulas read each other in a circle), then works it out for one record and prints what it gives. Exits 1 when the formula can't be saved.

Usage

civex schema preview-formula [OPTIONS] SCHEMA_NAME EXPRESSION

Arguments

Argument Type Required Description
SCHEMA_NAME str yes Schema the formula is on
EXPRESSION str yes The formula (--type formula): field names, numbers, "text", + - * / // % **, comparisons, and/or/not, a if condition else b, and functions such as round(x, 2), days_between(start, end) and concat(a, "-", b). Worked out when a record is read, never stored.

Options

Option Type Default Description
--record, -r str Work it out for this record (its id or the start of it). Left out, the schema's most recently changed record.
--result str What it gives: float | integer | string | boolean | date | datetime
--decimals int Decimal places for a float
--field str The formula field being changed, if it exists already

civex schema purge

Permanently delete a schema that's already in Recently Deleted. Irreversible.

Usage

civex schema purge [OPTIONS] NAME

Arguments

Argument Type Required Description
NAME str yes Schema name

Options

Option Type Default Description
--yes, -y flag false Skip confirmation prompt

civex schema remove-field

Remove a field from a schema.

Reversible: the field goes to Recently Deleted and every record keeps the value it held for it. Bring it back with civex schema restore-field (find its ID with civex trash list --kind field).

Usage

civex schema remove-field [OPTIONS] SCHEMA_NAME FIELD_NAME

Arguments

Argument Type Required Description
SCHEMA_NAME str yes Schema containing the field
FIELD_NAME str yes Field to remove

Options

Option Type Default Description
--yes, -y flag false Skip confirmation prompt

civex schema remove-unique

Remove a uniqueness key (give the same fields it was added with).

Usage

civex schema remove-unique NAME FIELDS...

Arguments

Argument Type Required Description
NAME str yes Schema name
FIELDS... str yes The fields of the key (the schema's own)

civex schema restore

Restore a soft-deleted schema (and the records cascade-deleted with it).

Usage

civex schema restore NAME

Arguments

Argument Type Required Description
NAME str yes Schema name

civex schema restore-field

Restore a removed field, with the values records still hold for it.

Usage

civex schema restore-field SCHEMA_NAME FIELD_ID

Arguments

Argument Type Required Description
SCHEMA_NAME str yes Schema the field was removed from
FIELD_ID str yes ID of the removed field (see civex trash list --kind field)

civex schema show

Inspect a schema's fields (including inherited).

Usage

civex schema show NAME

Arguments

Argument Type Required Description
NAME str yes Schema name

civex schema unique

List a schema's uniqueness keys.

Usage

civex schema unique NAME

Arguments

Argument Type Required Description
NAME str yes Schema name

civex schema update

Update a schema's name, label, description, or record name template.

Usage

civex schema update [OPTIONS] NAME

Arguments

Argument Type Required Description
NAME str yes Schema name

Options

Option Type Default Description
--rename str New name (slug) for the schema
--label, -l str New display name for the schema; pass '' to clear it
--description, -d str New description for the schema
--display-template str Template that names the schema's records, e.g. '{site}-{taken_on:YYYY-MM}'. Fields go in braces; formats follow a colon.
--clear-display-template flag false Remove the record name template (revert to auto)

civex schema update-field

Update a field's name, label, required flag, or restrictions.

Usage

civex schema update-field [OPTIONS] SCHEMA_NAME FIELD_NAME

Arguments

Argument Type Required Description
SCHEMA_NAME str yes Schema containing the field
FIELD_NAME str yes Field name

Options

Option Type Default Description
--rename str New name (slug) for the field
--label, -l str New display name for the field; pass '' to clear it
--required, --optional flag Set required/optional
--min float Minimum value (integer/float)
--max float Maximum value (integer/float)
--choices str Comma-separated allowed values (string)
--max-length int Maximum character length (string)
--accept str Allowed extensions e.g. '.csv,.txt'
--max-size int Maximum file size in bytes
--unit str Unit every value is stored in, e.g. m or degC (float). Values are never converted after the fact.
--precision str Least precise date accepted: year | month | day (date)
--geometry-types str Comma-separated shapes allowed, e.g. Point,Polygon (geo)
--bbox str Allowed area as WEST,SOUTH,EAST,NORTH in degrees; west greater than east crosses the 180th meridian (geo)
--from-file str Fill this field from the name of the file in this file field when it is left blank (string, integer, float, date, datetime). With --filename-pattern; either alone changes just that part of an existing rule.
--filename-pattern str How to read the value out of the file name: a token format such as YYYYMMDD[-_]HHmmSS or a regular expression with named groups (year, month, day, ...) for a date or datetime, else a regular expression whose first capture group is the value. Give it more than once to try several patterns in order.
--expression, -e str The formula (--type formula): field names, numbers, "text", + - * / // % **, comparisons, and/or/not, a if condition else b, and functions such as round(x, 2), days_between(start, end) and concat(a, "-", b). Worked out when a record is read, never stored.
--result str What a formula gives: float | integer | string | boolean | date | datetime.
--decimals int Decimal places for a formula giving a float
--clear-restrictions flag false Remove all restrictions