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 olddocument_creator_google_oauthsettings key with locally-stored OAuth tokens → migrated into aPhoenixKit.Integrationsrow under"google:default"; (2) name-stringgoogle_connectionreferences ("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 viaPhoenixKit.ModuleRegistry.run_all_legacy_migrations/0fromApplication.start/2.GoogleDocsClient.active_integration_uuid/0— uuid-shaped read accessor for the active Google integration row. Replaces the oldactive_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 falseshared 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) ornil, rather than aprovider:nameslug. Settings shape:document_creator_settings.google_connectionis now a uuid, not aprovider:namestring. End-users transparent (auto-migrated on read + at boot); module consumers callingactive_provider_key/0directly need to switch. - Strict-UUID Integrations API.
do_migrate_oauth_credentials/1creates the integration row viaadd_connection/3(the row-birth path) and writes migrated tokens viasave_setup(uuid, ...), replacing the old upsert-by-string-key flow. Newensure_connection/2helper handles:already_existson re-runs by resolving the existing uuid. get_credentials/0,connection_status/0, andauthenticated_request/3gate on uuid presence and return:not_configuredcleanly when nothing’s picked.GoogleOAuthSettingsLive.mount/3reads the uuid via the new accessor and handlesnilgracefully.- Cross-version compat:
ensure_connection/2‘s:already_existsresolve step is gated byfunction_exported?(Integrations, :find_uuid_by_provider_name, 1)— uses the V107 primitive when available, falls back to scanninglist_connections/1on Hex~> 1.7. Themigrate_legacy/0@impl PhoenixKit.Moduleannotation was dropped because the published behaviour doesn’t list it; the orchestrator dispatches byfunction_exported?/3regardless. - After a successful credentials migration the legacy
document_creator_google_oauthrow is reset to%{}so plaintextclient_secret/access_token/refresh_tokendon’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-withadded to the three Drive folder-browse buttons inGoogleOAuthSettingsLive(templates / documents / deleted path) — multiple rapid clicks no longer spawn concurrentTask.start_linkcalls.- Lazy-read crash hardening:
find_uuid_for_data/2andrewrite_setting/1inGoogleDocsClient(both run fromactive_integration_uuid/0on every legacy-shape request) nowtry/rescue. Backend / Settings failure logsLogger.warningwith exception type and falls through cleanly instead of crashing the LV. Both rescues excludeException.message/1to avoid leaking provider strings or query bindings embedded in Ecto error structs. - Observability:
resolve_via_list_connections/1andlog_migration_activity/2now 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. @versionnow derives fromMix.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.exsnow runsEcto.Migrator.run(TestRepo, [{0, PhoenixKit.Migration}], :up, all: true, log: false)— the same call host apps use in production. The 180-line hand-rolledTest.Migration(creating tables that core already owns:phoenix_kit_settings,phoenix_kit_activities,phoenix_kit_doc_*) is gone. Same pattern asphoenix_kit_ai. - Tests dependent on the strict-UUID
add_connection/3return shape ({:ok, %{uuid: _}}) are tagged@tag :requires_unreleased_coreand excluded by default; opt in viamix test --include requires_unreleased_coreonce the matching core version is published. Standalonemix testagainst Hex~> 1.7now exits clean.
Fixed
mix precommitfailures inherited from the strict-UUID flip —find_uuid_by_provider_name/1(undefined in Hex~> 1.7) caused a hardcall_to_missingdialyzer error;@impl PhoenixKit.Moduleonmigrate_legacy/0warned because the published behaviour doesn’t declare the callback. Both addressed viafunction_exported?/3runtime 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/0modern-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_configuredgates;migrate_legacy/0combined 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/1andseed_connection!/2(used bymigrate_legacy_connection/1’s fallback path);connected!/1now also seeds a sentinel uuid indocument_creator_settings.google_connectionso existing tests that only callconnected!()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.