Skip to content

fix(firestore): do not create a missing database on deploy --dry-run - #11509

Merged
joehan merged 4 commits into
firebase:mainfrom
gauranshahuja:11491/firestore-dry-run
Nov 17, 2026
Merged

joehan merged 4 commits into
firebase:mainfrom
gauranshahuja:11491/firestore-dry-run

Conversation

@gauranshahuja

Copy link
Copy Markdown
Contributor

Description

Fixes #11491.

firebase deploy --dry-run only skips the deploy and release phases; prepare still runs. Firestore's prepare step calls createDatabase(), so a dry run against a project where the configured database does not exist created it for real, in nam5 when location is not set.

With this change, on a dry run:

  • A missing database is not created. The CLI logs which database a deploy would create and in which location, and says when that location is the nam5 default because firebase.json sets none.
  • Rules are still checked. On a project that has no Firestore database at all, the rules :test endpoint returns 403 until the first database exists (the reason Fixing firestore deploy on fresh projects #9220 creates the database before compiling). In that case only, the dry run logs a warning that the rules could not be checked instead of failing. A 403 when the database exists, and any compilation error, still fail the dry run.

A normal deploy behaves as before.

Two things I noticed in the same function and left out to keep this focused (happy to send follow-ups):

  • With an array of databases in firebase.json, createDatabase() only checks the first one.
  • A non-404 error from getDatabase() is swallowed.

Scenarios Tested

Unit tests in src/deploy/firestore/prepare.spec.ts (new dry run block, 7 tests):

  • dry run, database missing: createDatabase not called, warning names the database and nam5 (the default ...), rules still compiled
  • dry run, database missing, location: "eur3": warning names eur3
  • dry run, database exists: no create, no warning
  • dry run, database missing, rules check returns 403: warning, dry run succeeds
  • dry run, database missing, rules compilation error: still fails
  • dry run, database exists, rules check returns 403: still fails
  • not a dry run, database missing: database is created in nam5 as before

Without the fix in prepare.ts, the first, second and fourth fail. Firestore prepare/deploy/release specs, src/deploy/index.spec.ts and src/rulesDeploy.spec.ts: 78 passing. ESLint and Prettier clean on the changed files.

Sample Commands

firebase deploy --dry-run (or --only firestore) with a firestore.database in firebase.json that does not exist in the project.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request updates the Firestore preparation logic to prevent 'firebase deploy --dry-run' from creating a missing Firestore database, instead reporting where the database would be created. It also handles 403 errors gracefully during dry runs when checking rules on projects without an existing database. The review feedback recommends extracting the default location 'nam5' into a top-level constant and removing a redundant inline comment that narrates self-evident code, aligning with the repository's style guide.

Comment thread src/deploy/firestore/prepare.ts Resolved
Comment thread src/deploy/firestore/prepare.ts Resolved
@joehan

joehan commented Nov 13, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution, this looks good!

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@4434f03). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11509   +/-   ##
=======================================
  Coverage        ?   60.72%           
=======================================
  Files           ?      864           
  Lines           ?    50587           
  Branches        ?    10168           
=======================================
  Hits            ?    30721           
  Misses          ?    18778           
  Partials        ?     1088           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joehan
joehan merged commit 21492f2 into firebase:main Nov 17, 2026
7 checks passed
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.

deploy with --dry-run still changes production (Firestore)

3 participants