Skip to content

Document Creator 0.2.9: Google connection stored by ID, old tokens moved

Document Creator 0.2.9 moves the module’s Google login fully onto PhoenixKit Integrations. At boot, old Google tokens stored in the module’s own settings are moved into an Integrations connection named google:default, and the plain-text copy is then emptied.

The module’s setting for which Google connection to use now holds the connection’s ID instead of a name such as google:my-name. Old values are converted at boot and again when first read, so nothing needs to be redone by hand. With no connection chosen, the module reports that it is not configured instead of failing. The three Drive folder browse buttons on the settings page can no longer be clicked several times in a row.

Upgrading

The boot step runs when the host app calls PhoenixKit.ModuleRegistry.run_all_legacy_migrations/0 from its Application.start/2; without it, the connection setting is still converted on first read. Code that called GoogleDocsClient.active_provider_key/0 must switch to active_integration_uuid/0.

Full release notes: Document Creator 0.2.9

0.2.9 · 2 May 2026

Added

  • PhoenixKitDocumentCreator.migrate_legacy/0 — boot-time legacy migration callback covering both kinds of pre-uuid data: (1) the old document_creator_google_oauth settings key with locally-stored OAuth tokens → migrated into a PhoenixKit.Integrations row under "google:default"; (2) name-string google_connection references ("google" / "google:my-name") → rewritten to the matching row’s uuid. Idempotent across boots; activity emissions per migration (action: "integration.legacy_migrated"); errors logged but never crash boot. Host apps trigger via PhoenixKit.ModuleRegistry.run_all_legacy_migrations/0 from Application.start/2.
  • GoogleDocsClient.active_integration_uuid/0 — uuid-shaped read accessor for the active Google integration row. Replaces the old active_provider_key/0. Detects legacy values, resolves them to the matching integration’s uuid, rewrites the setting in place, and returns the uuid; subsequent reads are direct.
  • GoogleDocsClient.uuid?/1 — @doc false shared regex helper for “is this a uuid-shaped string”. Used by both the lazy on-read path and the boot-time sweep.

Changed

  • (potentially breaking — module API) GoogleDocsClient.active_provider_key/0 → active_integration_uuid/0. Returns the integration row’s uuid (string) or nil, rather than a provider:name slug. Settings shape: document_creator_settings.google_connection is now a uuid, not a provider:name string. End-users transparent (auto-migrated on read + at boot); module consumers calling active_provider_key/0 directly need to switch.
  • Strict-UUID Integrations API. do_migrate_oauth_credentials/1 creates the integration row via add_connection/3 (the row-birth path) and writes migrated tokens via save_setup(uuid, ...), replacing the old upsert-by-string-key flow. New ensure_connection/2 helper handles :already_exists on re-runs by resolving the existing uuid.
  • get_credentials/0, connection_status/0, and authenticated_request/3 gate on uuid presence and return :not_configured cleanly when nothing’s picked. GoogleOAuthSettingsLive.mount/3 reads the uuid via the new accessor and handles nil gracefully.
  • Cross-version compat: ensure_connection/2‘s :already_exists resolve step is gated by function_exported?(Integrations, :find_uuid_by_provider_name, 1) — uses the V107 primitive when available, falls back to scanning list_connections/1 on Hex ~> 1.7. The migrate_legacy/0 @impl PhoenixKit.Module annotation was dropped because the published behaviour doesn’t list it; the orchestrator dispatches by function_exported?/3 regardless.
  • After a successful credentials migration the legacy document_creator_google_oauth row is reset to %{} so plaintext client_secret / access_token / refresh_token don’t survive the move to encrypted Integrations storage. Failure to clear is best-effort with a warning log; doesn’t roll back the migration.
  • phx-disable-with added to the three Drive folder-browse buttons in GoogleOAuthSettingsLive (templates / documents / deleted path) — multiple rapid clicks no longer spawn concurrent Task.start_link calls.
  • Lazy-read crash hardening: find_uuid_for_data/2 and rewrite_setting/1 in GoogleDocsClient (both run from active_integration_uuid/0 on every legacy-shape request) now try/rescue. Backend / Settings failure logs Logger.warning with exception type and falls through cleanly instead of crashing the LV. Both rescues exclude Exception.message/1 to avoid leaking provider strings or query bindings embedded in Ecto error structs.
  • Observability: resolve_via_list_connections/1 and log_migration_activity/2 now log exception type before swallowing — operators investigating “why is the resolver returning :resolver_failed” or “why is my activity feed empty after upgrade” have something to grep.
  • @version now derives from Mix.Project.config()[:version] at compile time so the runtime function can’t drift from the declared package version.
  • Test suite migration shim removed. test_helper.exs now runs Ecto.Migrator.run(TestRepo, [{0, PhoenixKit.Migration}], :up, all: true, log: false) — the same call host apps use in production. The 180-line hand-rolled Test.Migration (creating tables that core already owns: phoenix_kit_settings, phoenix_kit_activities, phoenix_kit_doc_*) is gone. Same pattern as phoenix_kit_ai.
  • Tests dependent on the strict-UUID add_connection/3 return shape ({:ok, %{uuid: _}}) are tagged @tag :requires_unreleased_core and excluded by default; opt in via mix test --include requires_unreleased_core once the matching core version is published. Standalone mix test against Hex ~> 1.7 now exits clean.

Fixed

  • mix precommit failures inherited from the strict-UUID flip — find_uuid_by_provider_name/1 (undefined in Hex ~> 1.7) caused a hard call_to_missing dialyzer error; @impl PhoenixKit.Module on migrate_legacy/0 warned because the published behaviour doesn’t declare the callback. Both addressed via function_exported?/3 runtime gating; mix precommit (compile + format + credo + dialyzer) now exits clean.

Tests

  • New integration coverage in test/integration/active_integration_test.exs (271 lines): active_integration_uuid/0 modern-shape passthrough, legacy "google:name" exact match, bare "google" first-row fallback, unresolvable target → setting cleared; get_credentials/0 / connection_status/0 / authenticated_request/3 :not_configured gates; migrate_legacy/0 combined entry point — {:ok, summary} shape, credentials migration converts OAuth → integration row, credentials short-circuit on existing row, reference sweep rewrites string → uuid, idempotency, legacy oauth key wiped after success.
  • Test stub additions: StubIntegrations.list_connections/1 and seed_connection!/2 (used by migrate_legacy_connection/1’s fallback path); connected!/1 now also seeds a sentinel uuid in document_creator_settings.google_connection so existing tests that only call connected!() keep working under the new resolver.

Document Creator 0.2.9. Install or update: {:phoenix_kit_document_creator, "~> 0.2"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.