PhoenixKit.Migrations.Postgres.V56 (phoenix_kit v1.7.71)

Copy Markdown View Source

V56: UUID Column Consistency Fix

Comprehensive fix for UUID column issues across all PhoenixKit tables. Ensures every table with a uuid column has:

  • DEFAULT uuid_generate_v7() (not gen_random_uuid())
  • NOT NULL constraint
  • Unique index

Also adds the missing uuid column to phoenix_kit_consent_logs (V43 schema expects it but the migration never created it).

All operations are idempotent — safe to run on fresh installs where V40 already set things up correctly, and on upgrades where uuid_repair.ex or V45/V46/V53 left columns in an inconsistent state.

Existing UUID values are NOT changed — they remain valid UUIDs regardless of version. Only defaults, constraints, and indexes are updated.

Issues Fixed

1. Wrong DEFAULT (gen_random_uuid → uuid_generate_v7)

V45, V46, V53, and V55 used gen_random_uuid() (UUIDv4) instead of the uuid_generate_v7() function created in V40.

Additionally, uuid_repair.ex (pre-1.7.0 upgrade path) adds uuid columns with gen_random_uuid(), and V40 then skips those tables because the column already exists — leaving them with the wrong default.

2. Missing NOT NULL constraint

V46 and V53 tables, plus uuid_repair.ex tables, may have nullable uuid columns.

3. Missing unique indexes

V45 tables and uuid_repair.ex tables may lack a unique index on the uuid column.

4. Missing uuid column entirely

V43 created phoenix_kit_consent_logs without a uuid column, but the Ecto schema (consent_log.ex) declares field :uuid, Ecto.UUID, read_after_writes: true.

Additionally, phoenix_kit_payment_methods, phoenix_kit_ai_endpoints, phoenix_kit_ai_prompts, phoenix_kit_sync_connections, and phoenix_kit_subscription_plans were created without uuid columns but are referenced as FK source tables in UUIDFKColumns (the backfill SQL does SET uuid_fk = s.uuid FROM source_table s).

5. Wrong DEFAULT on UUID primary keys (gen_random_uuid → uuid_generate_v7)

V55 Comments module tables use UUID as primary key with gen_random_uuid(). These need the same DEFAULT fix but on the id column instead of uuid.

Tables Fixed

  • phoenix_kit_consent_logs

V45 — Shop Module (DEFAULT + unique index)

  • phoenix_kit_shop_categories
  • phoenix_kit_shop_products
  • phoenix_kit_shop_shipping_methods
  • phoenix_kit_shop_carts
  • phoenix_kit_shop_cart_items
  • phoenix_kit_payment_options

V46 — Shop Extensions (DEFAULT + NOT NULL)

  • phoenix_kit_shop_config
  • phoenix_kit_shop_import_logs
  • phoenix_kit_shop_import_configs

V53 — Permissions (DEFAULT + NOT NULL)

  • phoenix_kit_role_permissions

V55 — Comments Module (DEFAULT on UUID primary key)

  • phoenix_kit_comments
  • phoenix_kit_comments_likes
  • phoenix_kit_comments_dislikes

uuid_repair.ex path — Core tables (DEFAULT + NOT NULL + unique index)

These are only affected on pre-1.7.0 upgrades where uuid_repair.ex ran before V40, causing V40 to skip them. On fresh installs V40 handles them correctly, and the operations here are no-ops.

  • phoenix_kit_users
  • phoenix_kit_users_tokens
  • phoenix_kit_user_roles
  • phoenix_kit_user_role_assignments
  • phoenix_kit_settings
  • phoenix_kit_email_templates

Summary

Functions

down(opts)

up(opts)