Cotton code
295 lines · 7.4 KB · JSONRaw
{  "format_version": 1,  "id": "evidence",  "name": "Evidence",  "plural": "Evidence",  "builtin": true,  "visibility": "owner",  "title": "excerpt",  "columns": [    {      "key": "transaction_id",      "type": "link",      "link_to": "transaction",      "required": true,      "readonly": true    },    {      "key": "kind",      "type": "text",      "labels": {        "statement_line": "Statement line",        "document": "Document",        "message": "Message",        "email": "Email",        "external": "External source"      },      "readonly": true    },    {      "key": "ref_id",      "type": "text",      "readonly": true    },    {      "key": "excerpt",      "type": "longtext",      "readonly": true    },    {      "key": "source_label",      "name": "Source",      "type": "text",      "readonly": true    },    {      "key": "attached_by",      "type": "text",      "readonly": true    },    {      "key": "attached_by_label",      "name": "Added by",      "type": "text",      "readonly": true    },    {      "key": "trashed_at",      "type": "date",      "format": "calendar-datetime",      "readonly": true    },    {      "key": "can_delete",      "type": "bool",      "readonly": true    }  ],  "instructions": "Money engine view. Engine columns are read-only. Evidence the owner or an assistant attached can be removed — can_delete is true on exactly that; a statement line's evidence stays with its movement, and only remove_evidence takes it off, to record that line afresh.",  "tables": [    {      "name": "cotton_money_evidence",      "columns": [        {          "name": "id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": true,          "declaration": "\n    id TEXT PRIMARY KEY",          "position": 0        },        {          "name": "workspace_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    workspace_id TEXT NOT NULL",          "position": 1        },        {          "name": "transaction_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    transaction_id TEXT NOT NULL",          "position": 2        },        {          "name": "kind",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    kind TEXT NOT NULL",          "position": 3        },        {          "name": "ref_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    ref_id TEXT",          "position": 4        },        {          "name": "excerpt",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    excerpt TEXT NOT NULL",          "position": 5        },        {          "name": "source_label",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    source_label TEXT",          "position": 6        },        {          "name": "attached_by",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    attached_by TEXT NOT NULL",          "position": 7        },        {          "name": "attached_by_label",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    attached_by_label TEXT",          "position": 8        },        {          "name": "created_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    created_at TEXT NOT NULL",          "position": 9        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 10        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 11        },        {          "name": "trashed_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    trashed_at TEXT",          "position": 12        }      ],      "constraints": [        {          "declaration": "\n    CHECK (attached_by IN ('import', 'assistant', 'owner'))",          "position": 13        },        {          "declaration": "\n    CHECK (kind IN ('statement_line', 'document', 'message', 'email', 'external'))",          "position": 14        },        {          "declaration": "\n    CHECK ((kind = 'external') OR (ref_id IS NOT NULL))",          "position": 15        },        {          "declaration": "\n    FOREIGN KEY (transaction_id) REFERENCES cotton_money_transactions(id)",          "position": 16        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 17        }      ],      "prefix": "CREATE TABLE cotton_money_evidence (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_money_evidence_ref ON cotton_money_evidence (kind, ref_id)",        "CREATE INDEX idx_cotton_money_evidence_transaction ON cotton_money_evidence (transaction_id)",        "CREATE INDEX idx_cotton_money_evidence_workspace ON cotton_money_evidence (workspace_id)",        "CREATE UNIQUE INDEX uq_cotton_money_evidence_line ON cotton_money_evidence (ref_id) WHERE kind = 'statement_line'",        "CREATE UNIQUE INDEX uq_cotton_money_evidence_ref ON cotton_money_evidence (transaction_id, kind, ref_id) WHERE ref_id IS NOT NULL",        "CREATE INDEX IF NOT EXISTS idx_cotton_money_evidence_author ON cotton_money_evidence (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ],  "picture": null,  "engine": "money",  "date": null,  "project": null,  "order": null,  "slip": {    "title": "excerpt",    "subtitle": null,    "trailing": null,    "photo": null,    "toggle": null  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "transaction_id",        "kind",        "ref_id",        "excerpt",        "source_label",        "attached_by",        "attached_by_label"      ]    }  ],  "delete_when": {    "column": "can_delete",    "present": true  },  "deletion": {    "confirm": "Remove",    "label": "Remove"  },  "commands": [    {      "id": "open-transaction-id",      "label": "Open transaction",      "kind": "open",      "opens": "transaction_id"    }  ],  "derived": true,  "parts": {    "shape": "sheet",    "head": {      "facts": []    },    "links": [],    "lists": [],    "acts": {      "more": [        "open-transaction-id"      ]    },    "cards": [      {        "column": "source_label"      },      {        "column": "attached_by_label"      }    ],    "strip": []  }}