Make a Construction

Real members, following a Template’s rules.

A Construction is a named tree of real members, made from a Template. Where the Template says that a plot holds beds, a Construction says which beds this plot has. It captures the Template’s revision and its own copy of the types, so it can be read and saved without the Template, and later Template changes can’t alter it.

Make one #

Name it and say which Template it follows. It starts from the skeleton, with the Template’s required map children and every list empty, and receives revision 1. Barntree makes it from the Template’s saved state, so a Template with unsaved edits must be saved or discarded first. Construction names can repeat, because each is its own document with its own id:

$ vendor/bin/barntree construction:create Allotment --name="Plot 12"
Saved: Plot 12
Construction: 3207a1c11fb74907574c9158b2fa812f
Revision: 1 (3ead1efb447667fabc3edc3520dc4d39)
Barn: …/allotment
$ vendor/bin/barntree construction:list
Barn: …/allotment
+--------------------+----------------------------------+----------+-----------------+
| Name               | Document ID                      | Revision | Source Template |
+--------------------+----------------------------------+----------+-----------------+
| Plot 12            | cb10aae9af5e9815f70da04037b71055 | 1        | Allotment       |
| Plot 12, north end | 3207a1c11fb74907574c9158b2fa812f | 7        | Allotment       |
+--------------------+----------------------------------+----------+-----------------+

A deliberate construction:create always makes a new one. If the output is lost, list before trying again.

Read it #

$ vendor/bin/barntree construction:show 3207a1c11fb74907574c9158b2fa812f
Plot 12
Revision: 3 (f3d1bd75b615327c68370767096738d8)
Allotment [Allotment, map] id=a6613e89bc389b77
  Beds [Beds, list] id=dc06e11b23467d1a
    Beans [Bed, leaf] id=67186afc688414fe
    Carrots [Bed, leaf] id=7c49afd08c65dd98
  Compost [Compost, leaf] id=2b278038cbdda93e
  Shed [Shed, leaf] id=c3c827fbf214f947

Each item shows its id. You point at an item by its id, so a member’s name can hold spaces, slashes or other punctuation without any escaping. --view=overview gives the Construction’s summary, and --view=source reads the exact Template revision it was made from:

$ vendor/bin/barntree construction:show 3207a1c11fb74907574c9158b2fa812f --view=source
Allotment
Revision: 1 (3c46bfb7e7251ee4a668cf2dd6a79557)
Allotment [Allotment, map]
  Beds [Beds, list]
    Bed [Bed, leaf]
  Compost [Compost, leaf]
  Shed [Shed, leaf]

That is the Template as it was when the Construction was made, even though the Template has since gained a Greenhouse, been renamed or been deleted.

Add, rename and remove members #

Only two things about a Construction change: its name, and the members of its lists. The required map children and the types it captured are protected. Each successful change saves at once as one revision. A change that alters nothing records none.

$ vendor/bin/barntree member:add 3207a1c11fb74907574c9158b2fa812f --list=dc06e11b23467d1a --name="Beans"
Saved: Plot 12
Construction: 3207a1c11fb74907574c9158b2fa812f
Revision: 2 (372bbb6fad1f6bde9869042c7fcfcb29)
Barn: …/allotment

Rename keeps a member’s id, kind and children:

$ vendor/bin/barntree member:rename 3207a1c11fb74907574c9158b2fa812f 7c49afd08c65dd98 --name="Courgettes"
Saved: Plot 12
Construction: 3207a1c11fb74907574c9158b2fa812f
Revision: 4 (774a0ce3377400ef1a4a0d2edd23c570)
Barn: …/allotment

Removing a member removes everything below it, so it asks. Interactively, the preview lists every item that would go and the answer defaults to No. Scripts, piped input and --no-interaction refuse unless you say --yes:

$ vendor/bin/barntree member:remove 3207a1c11fb74907574c9158b2fa812f 7c49afd08c65dd98
Removal needs confirmation. Use --yes to confirm.
$ vendor/bin/barntree member:remove 3207a1c11fb74907574c9158b2fa812f 7c49afd08c65dd98 --yes
Saved: Plot 12
Construction: 3207a1c11fb74907574c9158b2fa812f
Revision: 5 (99459a8719ba0fb2f78c9342ba13a818)
Barn: …/allotment
$ vendor/bin/barntree construction:rename 3207a1c11fb74907574c9158b2fa812f "Plot 12, north end"
Saved: Plot 12, north end
Construction: 3207a1c11fb74907574c9158b2fa812f
Revision: 6 (b22d76bfef58f6ed13433a0c2dda5e33)
Barn: …/allotment

What is refused #

$ vendor/bin/barntree member:add 3207a1c11fb74907574c9158b2fa812f --list=dc06e11b23467d1a --name="Beans"
List item 'dc06e11b23467d1a' has two members named 'Beans'.
$ vendor/bin/barntree member:add 3207a1c11fb74907574c9158b2fa812f --list=<Compost’s id> --name="X"
The item at 'Compost' follows 'Compost', a leaf, so it can't hold members: only a list item can.

The members of one list must have different names, and only a list item can hold members.

Scripts and the same change twice #

Every write command takes --json. Standard output then holds only the JSON, and anything else goes to standard error. The result says what changed, with the new revision and the revision it follows:

$ vendor/bin/barntree member:add 3207a1c11fb74907574c9158b2fa812f --list=dc06e11b23467d1a --name=Leeks --json
{
    "schemaVersion": 1,
    "barnRoot": "…/allotment",
    "operation": "member:add",
    "changed": true,
    "name": "Plot 12, north end",
    "documentId": "3207a1c11fb74907574c9158b2fa812f",
    "revisionId": "2bf0d1a7305e04466b1bf67af4dfb5d8",
    "number": 7,
    "token": null,
    "baseline": false,
    "source": {
        "documentId": "bd3708f38810ec991ef9a2470b5abe52",
        "revisionId": "3c46bfb7e7251ee4a668cf2dd6a79557",
        "number": 1,
        "name": "Allotment"
    },
    "matchesSavedRevision": true,
    "kind": "construction",
    "previousRevisionId": "b22d76bfef58f6ed13433a0c2dda5e33",
  …

To make a change on the strength of something you read, give --expect-revision=REVISION. If the Construction has moved on since, the change is refused and the newer work is kept. Every save also checks its base at the moment it commits, even while a confirmation is waiting.

$ vendor/bin/barntree member:add 3207a1c11fb74907574c9158b2fa812f --list=dc06e11b23467d1a --name="Leeks" --expect-revision=00000000000000000000000000000000
Construction revision conflict.

Exit status is 0 on success, and 1 for a refusal, a conflict or a declined confirmation.

In the browser app #

The same records open in the app. Select Construct on a Template to make one. In a Construction, + Add on a list adds a member, and the member’s own page renames or removes it. The browser app has the rest.

A Construction called Plot 12, north end. Beds holds two members, Beans and Leeks, each of type Bed and tagged Watered, with a dashed Add Bed button beneath them.
A Construction in the browser app, with its members and the type each follows.