Cotton code
354 lines · 8.7 KB · JSONRaw
{  "format_version": 1,  "id": "duplicate",  "name": "Duplicate",  "plural": "Duplicates",  "builtin": true,  "visibility": "owner",  "columns": [    {      "key": "record_kind",      "type": "text",      "readonly": true    },    {      "key": "keep_id",      "name": "Keep",      "type": "link",      "link_to": "photo",      "readonly": true,      "contributes": false,      "media": true    },    {      "key": "copy_id",      "name": "Copy",      "type": "link",      "link_to": "photo",      "readonly": true,      "contributes": false,      "media": true    },    {      "key": "distance",      "name": "Distance",      "type": "number",      "readonly": true,      "units": {        "one": "bit apart",        "other": "bits apart"      }    },    {      "key": "method",      "name": "Method",      "type": "choice",      "choices": [        "phash",        "features"      ],      "labels": {        "phash": "perceptual hash",        "features": "visual features"      },      "readonly": true    },    {      "key": "state",      "name": "State",      "type": "choice",      "choices": [        "open",        "confirmed",        "dismissed"      ],      "labels": {        "open": "Open",        "confirmed": "Confirmed",        "dismissed": "Dismissed"      },      "readonly": true    },    {      "key": "decided_at",      "type": "date",      "format": "calendar-datetime",      "readonly": true    },    {      "key": "keep_key",      "name": "Keep",      "type": "photo",      "readonly": true,      "caption": "keep_facts",      "opens": {        "column": "keep_id"      }    },    {      "key": "copy_key",      "name": "Copy",      "type": "photo",      "readonly": true,      "caption": "copy_facts",      "opens": {        "column": "copy_id"      }    },    {      "key": "keep_facts",      "name": "Keep facts",      "type": "text",      "readonly": true    },    {      "key": "copy_facts",      "name": "Copy facts",      "type": "text",      "readonly": true    }  ],  "instructions": "A pair of pictures the Mac thinks are copies of one another: keep names the one to keep, copy the likely copy. The owner answers: keep this one (the other is a copy) or they are different. Nothing is deleted for them.",  "tables": [    {      "name": "cotton_media_duplicates",      "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": "keep_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    keep_id TEXT NOT NULL",          "position": 3        },        {          "name": "copy_id",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    copy_id TEXT NOT NULL",          "position": 4        },        {          "name": "distance",          "type": "INTEGER",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    distance INTEGER NOT NULL",          "position": 5        },        {          "name": "method",          "type": "TEXT",          "default": null,          "nullable": false,          "primary_key": false,          "declaration": "\n    method TEXT 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 (record_kind IN ('photo', 'video'))",          "position": 13        },        {          "declaration": "\n    CHECK (keep_id <> copy_id)",          "position": 14        },        {          "declaration": "\n    CHECK (substr(keep_id, 1, length(record_kind) + 1) = record_kind || ':')",          "position": 15        },        {          "declaration": "\n    CHECK (substr(copy_id, 1, length(record_kind) + 1) = record_kind || ':')",          "position": 16        },        {          "declaration": "\n    CHECK (distance >= 0 AND distance <= 64)",          "position": 17        },        {          "declaration": "\n    CHECK (method IN ('phash', 'featureprint'))",          "position": 18        },        {          "declaration": "\n    CHECK (state IN ('open', 'confirmed', 'dismissed'))",          "position": 19        },        {          "declaration": "\n    CHECK ((state = 'open') = (decided_at IS NULL))",          "position": 20        },        {          "declaration": "\n    FOREIGN KEY (workspace_id) REFERENCES cotton_workspaces(id) ON DELETE CASCADE\n  ",          "position": 21        }      ],      "prefix": "CREATE TABLE cotton_media_duplicates (",      "suffix": ")",      "indexes": [        "CREATE UNIQUE INDEX uq_cotton_media_duplicates_pair ON cotton_media_duplicates (workspace_id, keep_id, copy_id)",        "CREATE INDEX idx_cotton_media_duplicates_open ON cotton_media_duplicates (workspace_id, keep_id) WHERE state = 'open'",        "CREATE INDEX idx_cotton_media_duplicates_copy ON cotton_media_duplicates (workspace_id, copy_id)",        "CREATE INDEX IF NOT EXISTS idx_cotton_media_duplicates_author ON cotton_media_duplicates (substr(_hlc, 20), _hlc)"      ],      "full_text": [],      "triggers": []    }  ],  "card": {    "face": "plain",    "fields": [      {        "slot": "photo",        "column": "keep_key"      },      {        "slot": "title",        "column": "keep_facts"      },      {        "slot": "subtitle",        "column": "copy_facts"      },      {        "slot": "facts",        "column": "method",        "also": [          "state",          "distance"        ]      }    ]  },  "picture": null,  "engine": "media",  "title": "keep_facts",  "date": null,  "project": null,  "order": null,  "slip": {    "title": "keep_facts",    "subtitle": null,    "trailing": null,    "photo": "keep_key",    "toggle": null,    "trailing_picture": "copy_key",    "answers": {      "column": "state",      "values": {        "confirmed": "Keep this one",        "dismissed": "They are different"      },      "when": [        "open"      ],      "primary": "confirmed"    }  },  "tile": {    "face": "slip-list"  },  "page": [    {      "heading": null,      "columns": [        "keep_key",        "copy_key"      ]    }  ],  "group": {    "column": "keep_id"  },  "empty": {    "title": "Nothing to review.",    "message": "When the Mac finds pictures that look like copies of each other, they are listed here for you to decide. Nothing is ever deleted for you."  },  "delete": false}