Cotton code
284 lines · 7.3 KB · JSONRaw
{  "format_version": 1,  "id": "transaction_line",  "name": "Line",  "plural": "Lines",  "builtin": true,  "engine": "money",  "derived": true,  "delete": false,  "columns": [    {      "key": "transaction_id",      "type": "link",      "link_to": "transaction",      "readonly": true,      "name": "Transaction"    },    {      "key": "account_id",      "type": "link",      "link_to": "money_account",      "readonly": true,      "name": "Account"    },    {      "key": "amount_minor",      "type": "amount",      "currency": "currency",      "readonly": true,      "name": "Amount"    },    {      "key": "currency",      "type": "text",      "readonly": true    },    {      "key": "title",      "name": "With",      "type": "text",      "readonly": true    },    {      "key": "description",      "name": "For",      "type": "text",      "readonly": true    },    {      "key": "payee_text",      "name": "With",      "type": "text",      "readonly": true    },    {      "key": "occurred_on",      "name": "Date",      "type": "date",      "readonly": true,      "fact": true,      "reading": "{date}"    },    {      "key": "category",      "name": "Went on",      "type": "text",      "readonly": true    }  ],  "title": "description",  "slip": {    "title": "title",    "subtitle": null,    "trailing": null,    "photo": null,    "toggle": null,    "figure": "amount_minor",    "title_fallback": "description",    "caption": {      "columns": [        "occurred_on",        "category"      ]    }  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "description",        "amount_minor",        "occurred_on",        "payee_text",        "account_id",        "transaction_id"      ]    }  ],  "picture": null,  "date": null,  "project": null,  "order": null,  "instructions": "Read-only legs of the money engine, one per account a transaction moved through; amounts remain in their account currency, signed as the ledger holds them. Each leg carries what its transaction was for, who it was with and its day, newest first; under an account it opens its transaction, under a transaction the account it moved. category is what its transaction went on, in words (a category, a person's ledger, or the other account of a move: \"To Savings\" where it left, \"From Wallet\" where it arrived).",  "sort": {    "column": "occurred_on",    "descending": true  },  "tables": [    {      "name": "cotton_money_transaction_lines",      "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": "account_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    account_id TEXT NOT NULL",          "position": 3        },        {          "name": "amount_minor",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    amount_minor INTEGER NOT NULL",          "position": 4        },        {          "name": "currency",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    currency TEXT NOT NULL CHECK (length(currency) = 3)",          "position": 5        },        {          "name": "original_amount_minor",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    original_amount_minor INTEGER",          "position": 6        },        {          "name": "original_currency",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    original_currency TEXT",          "position": 7        },        {          "name": "fx_rate_micro",          "type": "INTEGER",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    fx_rate_micro INTEGER",          "position": 8        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 9        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 10        }      ],      "constraints": [        {          "declaration": "\n    CHECK (((original_amount_minor IS NULL) AND (original_currency IS NULL) AND (fx_rate_micro IS NULL)) OR ((original_amount_minor IS NOT NULL) AND (original_currency IS NOT NULL) AND (fx_rate_micro IS NOT NULL)))",          "position": 11        },        {          "declaration": "\n    FOREIGN KEY (account_id) REFERENCES cotton_money_accounts(id)",          "position": 12        },        {          "declaration": "\n    FOREIGN KEY (transaction_id) REFERENCES cotton_money_transactions(id)",          "position": 13        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 14        }      ],      "prefix": "CREATE TABLE cotton_money_transaction_lines (",      "suffix": ")",      "indexes": [        "CREATE INDEX idx_cotton_money_lines_account ON cotton_money_transaction_lines (account_id)",        "CREATE INDEX idx_cotton_money_lines_transaction ON cotton_money_transaction_lines (transaction_id)",        "CREATE INDEX idx_cotton_money_lines_workspace ON cotton_money_transaction_lines (workspace_id)",        "CREATE INDEX IF NOT EXISTS idx_cotton_money_transaction_lines_author ON cotton_money_transaction_lines (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ],  "parts": {    "shape": "sheet",    "head": {      "facts": [        "occurred_on"      ]    },    "links": [],    "lists": [],    "acts": {      "more": [        "open-account-id",        "open-transaction-id"      ]    },    "cards": [      {        "column": "amount_minor"      },      {        "column": "category"      }    ],    "strip": []  },  "commands": [    {      "id": "open-account-id",      "label": "Open account",      "kind": "open",      "opens": "account_id"    },    {      "id": "open-transaction-id",      "label": "Open transaction",      "kind": "open",      "opens": "transaction_id"    }  ]}