Cotton code
308 lines · 7.7 KB · JSONRaw
{  "format_version": 1,  "id": "person_suggestion",  "name": "Suggestion",  "plural": "Suggestions",  "picture": null,  "builtin": true,  "engine": "people",  "columns": [    {      "key": "question",      "name": "Question",      "type": "text",      "readonly": true    },    {      "key": "note",      "name": "Note",      "type": "text",      "readonly": true    },    {      "key": "reason",      "name": "Why",      "type": "choice",      "choices": [        "name_exact",        "name_fuzzy"      ],      "readonly": true    },    {      "key": "state",      "name": "Answer",      "type": "choice",      "choices": [        "open",        "merged",        "different"      ]    },    {      "key": "person_id",      "name": "Person",      "type": "link",      "link_to": "person",      "readonly": true,      "contributes": false    },    {      "key": "candidate_id",      "name": "Same as",      "type": "link",      "link_to": "person",      "readonly": true,      "contributes": false    }  ],  "title": "question",  "date": null,  "project": null,  "order": null,  "slip": {    "title": "question",    "subtitle": "note",    "trailing": null,    "photo": null,    "toggle": null,    "byline": {      "column": "reason",      "words": {        "name_exact": "Same name in Photos",        "name_fuzzy": "Similar name in Photos"      }    },    "answers": {      "column": "state",      "values": {        "merged": "Merge",        "different": "Different"      },      "when": [        "open"      ]    }  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "question",        "note",        "reason",        "state",        "person_id",        "candidate_id"      ]    }  ],  "empty": {    "title": "Nobody looks like anybody else.",    "message": "When two people may be one, Cotton asks here. It never merges on its own."  },  "delete": false,  "instructions": "A suggestion that two people may be one person, asked from either side (person_id or candidate_id names the person). Answering merged merges them (the candidate survives; the change names the survivor in moved_to); different closes the question. Never answer for the owner.",  "add": false,  "tables": [    {      "name": "cotton_person_suggestions",      "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": "person_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    person_id TEXT",          "position": 2        },        {          "name": "contact_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    contact_id TEXT",          "position": 3        },        {          "name": "candidate_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    candidate_id TEXT NOT NULL",          "position": 4        },        {          "name": "reason",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    reason TEXT NOT NULL",          "position": 5        },        {          "name": "score",          "type": "REAL",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    score REAL NOT NULL",          "position": 6        },        {          "name": "state",          "type": "TEXT",          "default": "'open'",          "nullable": false,          "primary_key": false,          "declaration": "\n    state TEXT NOT NULL DEFAULT 'open'",          "position": 7        },        {          "name": "decided_at",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    decided_at 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": "updated_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    updated_at TEXT NOT NULL",          "position": 10        },        {          "name": "_hlc",          "type": "TEXT",          "default": "''",          "nullable": false,          "primary_key": false,          "declaration": "\n    _hlc TEXT NOT NULL DEFAULT ''",          "position": 11        },        {          "name": "_born",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    _born TEXT",          "position": 12        }      ],      "constraints": [        {          "declaration": "\n    CHECK (person_id <> candidate_id)",          "position": 13        },        {          "declaration": "\n    CHECK (reason IN ('name_exact', 'name_fuzzy', 'handle_name'))",          "position": 14        },        {          "declaration": "\n    CHECK (score >= 0 AND score <= 1)",          "position": 15        },        {          "declaration": "\n    CHECK (state IN ('open', 'merged', 'different'))",          "position": 16        },        {          "declaration": "\n    CHECK ((state = 'open') = (decided_at IS NULL))",          "position": 17        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 18        }      ],      "prefix": "CREATE TABLE cotton_person_suggestions (",      "suffix": ")",      "indexes": [        "CREATE UNIQUE INDEX uq_cotton_person_suggestions_pair ON cotton_person_suggestions (workspace_id, person_id, candidate_id)",        "CREATE UNIQUE INDEX uq_cotton_person_suggestions_contact ON cotton_person_suggestions (workspace_id, contact_id, candidate_id) WHERE contact_id IS NOT NULL",        "CREATE INDEX idx_cotton_person_suggestions_open ON cotton_person_suggestions (workspace_id, person_id) WHERE state = 'open'",        "CREATE INDEX idx_cotton_person_suggestions_candidate ON cotton_person_suggestions (workspace_id, candidate_id)",        "CREATE INDEX IF NOT EXISTS idx_cotton_person_suggestions_author ON cotton_person_suggestions (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ],  "parts": {    "shape": "sheet",    "head": {      "facts": []    },    "links": [],    "lists": [],    "acts": {      "more": [        "person",        "candidate"      ]    },    "cards": [      {        "column": "note"      },      {        "column": "state"      }    ],    "strip": []  },  "commands": [    {      "id": "person",      "label": "Open person",      "kind": "open",      "opens": "person_id"    },    {      "id": "candidate",      "label": "Open person",      "kind": "open",      "opens": "candidate_id"    }  ]}