Cotton code
348 lines · 8.3 KB · JSONRaw
{  "format_version": 1,  "id": "sighting",  "name": "Sighting",  "plural": "Seen in",  "builtin": true,  "visibility": "owner",  "date": "seen_at",  "columns": [    {      "key": "record_kind",      "type": "text",      "readonly": true    },    {      "key": "record_id",      "type": "text",      "readonly": true    },    {      "key": "source",      "name": "Where",      "type": "choice",      "choices": [        "message",        "share",        "library",        "apple_library",        "email"      ],      "labels": {        "message": "A chat",        "share": "Shared into Cotton",        "library": "Added from this phone's library",        "apple_library": "Imported from the Apple Photos library",        "email": "Attached to an email"      },      "readonly": true    },    {      "key": "source_id",      "type": "text",      "readonly": true    },    {      "key": "thread_id",      "name": "Chat",      "type": "text",      "readonly": true    },    {      "key": "key",      "type": "text",      "readonly": true    },    {      "key": "seen_at",      "name": "Seen",      "type": "date",      "readonly": true    },    {      "key": "photo_id",      "name": "Photo",      "type": "link",      "link_to": "photo",      "readonly": true,      "media": true    },    {      "key": "video_id",      "name": "Video",      "type": "link",      "link_to": "video",      "readonly": true,      "media": true    },    {      "key": "thread_name",      "name": "Chat name",      "type": "text",      "readonly": true    }  ],  "seal": {    "clear": [      "record_kind",      "record_id",      "source",      "source_id",      "thread_id",      "key",      "seen_at",      "photo_id",      "video_id"    ]  },  "instructions": "Where a picture or film was seen: a chat (with its thread), shared into Cotton, added from the phone's library, imported from Apple Photos, or attached to an email. Read-only.",  "tables": [    {      "name": "cotton_media_sightings",      "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": "record_kind",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    record_kind TEXT NOT NULL",          "position": 2        },        {          "name": "record_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    record_id TEXT NOT NULL",          "position": 3        },        {          "name": "source",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    source TEXT NOT NULL",          "position": 4        },        {          "name": "source_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    source_id TEXT",          "position": 5        },        {          "name": "thread_id",          "type": "TEXT",          "default": null,          "nullable": true,          "primary_key": false,          "declaration": "\n    thread_id TEXT",          "position": 6        },        {          "name": "key",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    key TEXT NOT NULL",          "position": 7        },        {          "name": "seen_at",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    seen_at TEXT NOT NULL",          "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 (record_kind IN ('photo', 'video'))",          "position": 13        },        {          "declaration": "\n    CHECK (substr(record_id, 1, length(record_kind) + 1) = record_kind || ':')",          "position": 14        },        {          "declaration": "\n    CHECK (source IN ('message', 'share', 'library', 'apple_library', 'email'))",          "position": 15        },        {          "declaration": "\n    CHECK ((source = 'message') = (thread_id IS NOT NULL))",          "position": 16        },        {          "declaration": "\n    CHECK (source NOT IN ('message', 'apple_library', 'email') OR source_id IS NOT NULL)",          "position": 17        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 18        }      ],      "prefix": "CREATE TABLE \"cotton_media_sightings\" (",      "suffix": ")",      "indexes": [        "CREATE UNIQUE INDEX uq_cotton_media_sightings_natural ON cotton_media_sightings (workspace_id, record_kind, record_id, source, ifnull(source_id, ''))",        "CREATE INDEX idx_cotton_media_sightings_record ON cotton_media_sightings (workspace_id, record_id)",        "CREATE INDEX idx_cotton_media_sightings_thread ON cotton_media_sightings (workspace_id, thread_id) WHERE thread_id IS NOT NULL",        "CREATE INDEX idx_cotton_media_sightings_source ON cotton_media_sightings (workspace_id, source, source_id)",        "CREATE INDEX IF NOT EXISTS idx_cotton_media_sightings_author ON cotton_media_sightings (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ],  "picture": null,  "engine": "media",  "title": "thread_name",  "project": null,  "order": null,  "slip": {    "title": "thread_name",    "subtitle": null,    "trailing": null,    "photo": null,    "toggle": null,    "title_fallback": "source"  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "thread_name",        "source",        "seen_at"      ]    }  ],  "sort": {    "column": "seen_at"  },  "delete": false,  "opens": {    "column": "thread_id",    "table": "message_thread"  },  "commands": [    {      "id": "open-photo",      "label": "Open photo",      "object": "picture",      "kind": "open",      "opens": "photo_id"    },    {      "id": "open-video",      "label": "Open video",      "object": "picture",      "kind": "open",      "opens": "video_id"    }  ],  "parts": {    "shape": "sheet",    "head": {      "facts": []    },    "links": [],    "lists": [],    "acts": {      "more": [        "open-photo",        "open-video"      ]    },    "cards": [      {        "column": "source"      },      {        "column": "seen_at"      }    ]  },  "card": {    "face": "plain",    "fields": [      {        "slot": "title",        "column": "thread_name"      },      {        "slot": "facts",        "column": "source",        "also": [          "seen_at"        ]      }    ]  }}