PhoenixKit.Migrations.Postgres.V203 (phoenix_kit v2.40.1)

Copy Markdown View Source

V203: storage libraries, user libraries (phase 2 of dev_docs/plans/2026-09-22-storage-libraries.md).

  • phoenix_kit_storage_library_members — who else may use a user library, and as what (manager | contributor | viewer). The owner is the library's owner_uuid, never a member row. A member row goes with its library and with its user.
  • Deleting a user no longer deletes their files. The uploader FK fk_files_user_uuid moves from ON DELETE CASCADE to SET NULL, and phoenix_kit_files_user_or_parent_check accepts a file that has a library instead (every file has one since V202). Their uploads in the site's libraries and in other people's stay, with no uploader. The media-folder creator FK moves to SET NULL too: with no ON DELETE it refused to delete anyone who had ever created a folder.
  • A user's own libraries must be trashed before the user goes. The library owner FK moves from RESTRICT to SET NULL, and the owner check allows a user library without an owner only once it is trashed. Deleting a user whose live library still names them fails on that check, so the step Auth.delete_user/2 takes first (trash every library they own) cannot be skipped, and a trashed library outlives its owner until the purge job empties it.
  • The library slug statements again, from V202 (#871): a database that ran an earlier build of V202 is marked 202 without the slug column. They are idempotent, so everywhere else they change nothing.

Deliberately NOT here: dedup per library needs no schema change. A file in a library other than Media gets a user_file_checksum that folds the library in, so the existing unique index already holds one copy per uploader per library, and Media's keys are the ones every existing row has (Storage.user_file_checksum/3). V200's user-keyed capture-date index stays (the schema manifest cannot say "removed in version N" yet).

Locks

Every FK and CHECK is replaced only while it still has its old shape, so a re-run changes nothing. The new one is added NOT VALID under a temporary name, validated in a statement of its own (a SHARE UPDATE EXCLUSIVE scan: reads and writes go on), and then swapped in for the old one. Each validation scans its table once.

Re-runnable.

Summary

Functions

Rolls V203 back: drops the members table and puts the uploader, folder creator and library owner FKs and their checks back as V202 had them. Files whose uploader has been deleted since cannot satisfy the old check; the rollback refuses (the CHECK fails) rather than delete them. The slug stays — it is V202's.

Functions

down(opts)

Rolls V203 back: drops the members table and puts the uploader, folder creator and library owner FKs and their checks back as V202 had them. Files whose uploader has been deleted since cannot satisfy the old check; the rollback refuses (the CHECK fails) rather than delete them. The slug stays — it is V202's.