Skip to content

docs: document phone number normalization migration#2510

Open
hperl wants to merge 7 commits intomasterfrom
hperl/phone-normalization
Open

docs: document phone number normalization migration#2510
hperl wants to merge 7 commits intomasterfrom
hperl/phone-normalization

Conversation

@hperl
Copy link
Copy Markdown
Collaborator

@hperl hperl commented Apr 14, 2026

Summary

Adds documentation for the new kratos migrate normalize-phone-numbers CLI command for self-hosted (OSS and OEL) Kratos administrators.

The new guide at docs/kratos/guides/normalize-phone-numbers.mdx explains:

  • Why phone number normalization matters
  • The required deploy-then-migrate rollout sequence (deploying the migration before the new code locks users out)
  • Command flags (--dry-run, --batch-size, -e)
  • How to interpret the output and handle duplicates
  • How to roll back

Also updates the upgrade guide (docs/kratos/guides/upgrade.mdx) to link to the new guide as a step when upgrading to a version that introduces phone normalization.

Ory Network customers don't need to take any action — this is for self-hosted only.

Companion to ory-corp/cloud#11283.

Test plan

  • Preview docs locally and verify the new guide renders correctly
  • Verify the upgrade guide links to the new guide
  • Verify the new guide appears in the sidebar under Kratos > Guides

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Added a comprehensive guide for phone number normalization, covering rollout sequence, migration behavior, CLI options, dry-run output, and error handling.
    • Updated upgrade guide with a new checklist step to run the phone-number normalization migration after deployment.
    • Clarified that new phone numbers are normalized on write while legacy data requires an explicit migration.
    • Minor formatting and clarity improvements in upgrade guidance.

Document the new kratos migrate normalize-phone-numbers command for
self-hosted (OSS and OEL) Kratos administrators. The guide explains
why normalization matters, the required deploy-then-migrate rollout
sequence, command flags, and how to interpret the output.

Also link to the new guide from the upgrade guide so admins see it
when planning a version upgrade that introduces phone normalization.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 14, 2026 12:06
@hperl hperl requested review from piotrmsc and zepatrik as code owners April 14, 2026 12:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds self-hosted documentation for the new Kratos phone number normalization migration and wires it into the docs navigation/upgrade flow.

Changes:

  • Add a new guide explaining the kratos migrate normalize-phone-numbers rollout sequence, flags, output, and rollback considerations.
  • Update the Kratos upgrade guide to reference the new normalization guide during upgrades.
  • Add the new guide to the Kratos Guides section in the docs sidebar.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/sidebar.ts Adds the new normalization guide to the Kratos “Self-Hosted > Guides” sidebar list.
docs/kratos/guides/upgrade.mdx Adds an upgrade checklist step linking to the phone normalization guide.
docs/kratos/guides/normalize-phone-numbers.mdx New end-to-end migration guide for phone normalization to E.164.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/kratos/guides/normalize-phone-numbers.mdx Outdated
Comment thread docs/kratos/guides/upgrade.mdx Outdated
@hperl hperl changed the title docs(kratos): document phone number normalization migration feat: document phone number normalization migration Apr 14, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

Adds a new guide documenting phone number normalization and a migration CLI, and updates the upgrade guide to include a new checklist step and small formatting fixes.

Changes

Cohort / File(s) Summary
Upgrade Guide Updates
docs/kratos/guides/upgrade.mdx
Reflowed text and removed trailing double-spaces; added upgrade checklist step instructing to run kratos migrate normalize-phone-numbers after deploying the release that enables phone number normalization, linking to the new guide.
New Normalization Guide
docs/kratos/guides/normalize-phone-numbers.mdx
Added a guide describing normalization behavior and a two-step rollout (deploy then run migration). Documents the kratos migrate normalize-phone-numbers CLI, flags (--read-from-env/-e, --batch-size/-b, --dry-run), scan targets/filters, parsing to E.164 with nyaruka/phonenumbers, dry-run diffs, summary counters (scanned, updated, skipped, errors), idempotency, error/unique-constraint handling, and rollback guidance (DB restore).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Admin as Admin
  participant Deploy as Deploy (New Kratos)
  participant Migrate as Migrator (kratos migrate)
  participant DB as Database
  participant Parser as phonenumbers

  Admin->>Deploy: Deploy new version that normalizes on write
  Deploy-->>Admin: New instance serves traffic
  Admin->>Migrate: Run `kratos migrate normalize-phone-numbers`
  Migrate->>DB: Scan target tables & rows (with filters)
  loop per row
    Migrate->>Parser: Parse phone-like value
    alt parsed
      Parser-->>Migrate: E.164 value
      Migrate->>DB: UPDATE row (handle unique conflicts/log)
    else unparsable/skip
      Parser-->>Migrate: skip
    end
  end
  Migrate-->>Admin: Summary (scanned, updated, skipped, errors)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description provides a comprehensive summary of changes, explains the purpose for self-hosted administrators, includes relevant test plan items, and references a companion change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: adding documentation for phone number normalization migration, which is the primary focus of the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hperl/phone-normalization

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/kratos/guides/upgrade.mdx`:
- Around line 20-22: The inline CLI command "kratos migrate
normalize-phone-numbers" is missing its opening backtick and has a dangling
backtick; update the sentence in the upgrade guide to wrap the command in
backticks (e.g., `kratos migrate normalize-phone-numbers`) so the inline code is
properly formatted and renders correctly in the docs; verify the closing
backtick remains and preview the MDX to ensure the command is styled as inline
code.

In `@src/sidebar.ts`:
- Line 610: The sidebar entry "kratos/guides/normalize-phone-numbers" in
src/sidebar.ts is referencing a nonexistent doc id and is breaking the docs
build; fix it by either adding a doc file whose frontmatter defines the id
"kratos/guides/normalize-phone-numbers" (matching the sidebar entry) or change
the sidebar entry in src/sidebar.ts to the actual existing doc id used by the
guide (e.g., the correct id string found in the guide's frontmatter), ensuring
the id in the sidebar and the doc frontmatter match exactly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 50ee6436-99ea-402d-8b56-6e6f13f80690

📥 Commits

Reviewing files that changed from the base of the PR and between 86f766a and c01ba19.

📒 Files selected for processing (2)
  • docs/kratos/guides/upgrade.mdx
  • src/sidebar.ts

Comment thread docs/kratos/guides/upgrade.mdx Outdated
Comment thread src/sidebar.ts Outdated
@hperl hperl changed the title feat: document phone number normalization migration docs: document phone number normalization migration Apr 15, 2026

This guide is for self-hosted Kratos administrators (OSS and OEL). Ory Network customers don't need to take any action.

:::info
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:::info
:::important


:::info

Back up your database before running the migration.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Back up your database before running the migration.
Back up your database before running the migration. The migration doesn't store the original value, therefore there's no automatic rollback after migration. To revert, you will need to restore your backed-up database.

Comment on lines +54 to +57
:::caution

Don't run the migration before deploying the new Kratos version. The previous version does exact-string matching on identifiers.
If you normalize the database first, users who type their phone number in the original (non-E.164) format won't be able to log in
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this caution to beneath Rollout sequence.

sidebar_label: Normalize phone numbers
---

Starting with this release, Ory Kratos normalizes phone numbers to [E.164 format](https://en.wikipedia.org/wiki/E.164) when
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Starting with this release, Ory Kratos normalizes phone numbers to [E.164 format](https://en.wikipedia.org/wiki/E.164) when
Ory Kratos normalizes phone numbers to [E.164 format](https://en.wikipedia.org/wiki/E.164) when

Copy link
Copy Markdown
Contributor

@unatasha8 unatasha8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are you planning to put normalize-phone-numbers.mdx in the sidebar? This content is a mix of 1. "how Ory Kratos normalizes phone numbers" and 2. "migrate existing phone numbers to normalized phone numbers". I'd suggest two separate articles. 1. should live in the Kratos OSS/OEL docs (remove 'starting with this release' to keep content fresh) and 2 should be with the upgrade docs. QUESTION: what happens if the customer upgrade but decides not to migrate their phone numbers. What would happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants