firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Dataconnect schema deploy: Index names

Open federicobaiocco opened this issue 5 months ago • 0 comments

[REQUIRED] Environment info

firebase-tools: 14.0.9

Platform: Macos

[REQUIRED] Test case

Consider the following schema:

type SomeVeryLongEntityConfiguration @table(key: ["relatedEntity"]) {
  relatedEntity: AnotherEntity!
  fieldA: String!
  fieldB: String!
}

And another related type:

type SomeVeryLongEntityConfCredential @table(key: ["someVeryLongEntityConfiguration", "credentialType"]) {
  someVeryLongEntityConfiguration: SomeVeryLongEntityConfiguration! @ref(constraintName: "long_conf_cred_fk")
  credentialType: String!
}

Firebase Data Connect auto-generates an index to support this relationship. The index name includes both the table name and the foreign key fields, resulting in something like:

CREATE INDEX someverylongentityconfcredential_someverylongentityconfigurationRelate_idx ...

This index name has more than 63 characters, so PostgreSQL silently truncates it to:

someverylongentityconfcredential_someverylongentityconfigurationRel

Later, when running a deployment (firebase deploy), Firebase generates SQL trying to drop or recreate the full index name:

DROP INDEX "public"."someverylongentityconfcredential_someverylongentityconfigurationRelate_idx";

But postregs had previously truncated the name, so the original index doesn't exist under that name. This causes a misleading error:

Error: the database schema must be migrated before the application schema can be updated

[REQUIRED] Steps to reproduce

Create schema with long names and deploy

[REQUIRED] Expected behavior

Fail if the index name is too long. Avoid inconsistent state where indexes are deployed with truncated names

[REQUIRED] Actual behavior

The schema is deployed and after that you cannot deploy anymore. We had to manually delete tables, indexes, then update our schema and deploy again.

federicobaiocco avatar Jun 27 '25 12:06 federicobaiocco