PhoenixKit.Migrations.Postgres.V183 (phoenix_kit v2.15.0)

Copy Markdown View Source

V183: annotations can anchor to something other than a file.

Why

Every annotation row pointed at a phoenix_kit_files row through a NOT NULL file_uuid. That was right for the media viewer, where a shape is always drawn over an image, and wrong for a whiteboard, where there is no image at all — Fresco's canvas renders a scene with zero images and Etcher draws over empty canvas without needing one. The projects module bridged the gap by minting a solid-white PNG per board, registering it as a Storage file and drawing over that. Etcher's own API has always been keyed by target_type + target_uuid; this migration lets the table say the same.

What it does

  • file_uuid becomes nullable.
  • target_type (varchar(32), NOT NULL, default 'file') and target_uuid (uuid) are added; every existing row is backfilled with target_type = 'file', target_uuid = file_uuid.
  • An index on (target_type, target_uuid) for the board lookups.
  • A CHECK constraint pins the two shapes: a 'file' target carries its file in BOTH columns (file_uuid = target_uuid), and any other target carries no file at all. Nothing in between.

Reads of existing rows are unchanged — file_uuid is still there and still the file. Rolling back deletes the non-file annotations (they have no home in the old shape), drops the two columns and the constraint, and makes file_uuid NOT NULL again.

Summary

Functions

down(opts)

up(opts)