Repository navigation
Description
[REQUIRED] Environment info
firebase-tools: 15.34.2 (also seen on 15.2.1)
Platform: Windows 10 (the logic involved is platform independent)
[REQUIRED] Test case
firebase.json with the multi-database array form:
{
"firestore": [
{ "database": "(default)", "rules": "a.rules", "indexes": "a.indexes.json" },
{ "database": "db2", "rules": "a.rules", "indexes": "a.indexes.json" }
]
}The Manage and deploy Security Rules page says:
Deploy rules for the specified database configured in your firebase.json:
firebase deploy --only firestore:<databaseId>
[REQUIRED] Steps to reproduce
firebase deploy --only firestore:db2
firebase deploy --only firestore:db2:rules
What each --only value deploys on 15.34.2. I got this by running the CLI's own lib/deploy/firestore/prepare.js and deploy.js with only the network calls stubbed, so it shows which rulesets and index specs would be sent (script below):
--only firestore => rules -> (default) | rules -> db2 | indexes -> (default) | indexes -> db2
--only firestore:rules => rules -> (default) | rules -> db2
--only firestore:indexes => indexes -> (default) | indexes -> db2
--only firestore:db2 => rules -> db2 | indexes -> db2
--only firestore:db2:rules => rules -> db2 | indexes -> db2
--only firestore:db2:indexes => rules -> db2 | indexes -> db2
We first hit this with a real deploy on 15.2.1. During a cutover rehearsal we ran firebase deploy --only firestore:<db>:rules against a named test database, meaning to change only the rules. The command also deployed that database's indexes and finished with "Deploy complete!".
Why: getFirestoreConfig (src/firestore/fsConfig.ts) takes only value.split(":")[1] as the database. Then prepare.ts keeps indexes unless the exact string firestore:rules is in --only (and rules unless firestore:indexes is). A database-scoped value matches neither, so both are deployed. Any third segment is dropped without a warning.
[REQUIRED] Expected behavior
--only firestore:db2: if it is meant to deploy rules only (as the docs say), it should not touch db2's indexes. If it is meant to deploy rules and indexes, the docs should say that.--only firestore:db2:rules/firestore:db2:indexesshould deploy only that part for that database. Or, if that form isn't supported, it should fail with an error rather than ignore the suffix.
Right now there is no way to deploy the rules of one database without also deploying its indexes. That matters when an index build is still running or when the indexes file has changes that aren't ready yet.
[REQUIRED] Actual behavior
Both rules and indexes for db2 are deployed for all three database-scoped forms, and the CLI exits 0.
I'd be happy to send a PR that accepts firestore:<databaseId|target>:rules and firestore:<databaseId|target>:indexes (per database, alongside the existing firestore:rules / firestore:indexes) and rejects any other third segment, with tests in fsConfig.spec.ts and prepare.spec.ts. Does that direction work for you, or would you prefer only the error for unknown suffixes plus a docs fix?
Script used for the table
// node only-scope.cjs <path to an installed firebase-tools package>
const path = require("path"), fs = require("fs"), os = require("os");
const pkg = path.resolve(process.argv[2]);
const lib = (p) => require(path.join(pkg, "lib", p));
const calls = [];
lib("ensureApiEnabled").ensure = async () => {};
const { FirestoreApi } = lib("firestore/api");
FirestoreApi.prototype.getDatabase = async () => ({});
FirestoreApi.prototype.deploy = async (_o, _i, _f, db) => calls.push(`indexes -> ${db}`);
const { RulesDeploy } = lib("rulesDeploy");
RulesDeploy.prototype.compile = async () => {};
RulesDeploy.prototype.createRulesets = async function () {
for (const r of this.rulesFiles) calls.push(`rules -> ${r.databaseId}`);
};
const prepare = lib("deploy/firestore/prepare").default;
const deploy = lib("deploy/firestore/deploy").default;
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fs-only-"));
fs.writeFileSync(path.join(dir, "a.rules"), "rules_version = '2';\n");
fs.writeFileSync(path.join(dir, "a.indexes.json"), '{"indexes":[],"fieldOverrides":[]}');
const firestore = [
{ database: "(default)", rules: "a.rules", indexes: "a.indexes.json" },
{ database: "db2", rules: "a.rules", indexes: "a.indexes.json" },
];
(async () => {
for (const only of ["firestore", "firestore:rules", "firestore:indexes",
"firestore:db2", "firestore:db2:rules", "firestore:db2:indexes"]) {
calls.length = 0;
const options = { only, projectId: "demo-p", rc: {},
config: { src: { firestore }, data: { firestore }, path: (f) => path.join(dir, f) } };
const context = { projectId: "demo-p" };
await prepare(context, options);
await deploy(context, options);
console.log(`--only ${only.padEnd(22)} => ${calls.join(" | ") || "(nothing)"}`);
}
})();
Activity
aalej commentedon Nov 5, 2026
Thanks for the very detailed bug report and for taking the time to analyze the deployment behavior, @ppcvote! I am able to reproduce the reported issue.
Your analysis of
src/firestore/fsConfig.tsandsrc/deploy/firestore/prepare.tslooks spot on, since we get the target usingvalue.split(":")[1], the last suffix:rulesor:indexesgets ignored when runningfirebase deploy --only firestore:db2:rules.My preference for the deploy filter would be the behavior below, since it would allow better control over what is being deployed
firebase deploy --only firestore- deploys bothindexesandrulesfor all databasesfirebase deploy --only firestore:rules- deploys onlyrulesfor all databasesfirebase deploy --only firestore:indexes- deploys onlyindexesfor all databasesfirebase deploy --only firestore:db2- deploys bothindexesandrulesfor databasedb2firebase deploy --only firestore:db2:rules- deploys onlyrulesfor databasedb2firebase deploy --only firestore:db2:indexes- deploys onlyindexesfor databasedb2I agree that we need to update the documentation to mention that commands like
--only firestore:db2will also deployindexes, or update the command to be--only firestore:db2:rules.I will get feedback from our engineering team to confirm what behavior they prefer for FIrestore deployments. Since you mentioned you'd be happy to send a PR, feel free to open one with the approach you suggested! Our engineering team would be able to review the implementation and behavior there directly.