Firebase CLI command reference for Data Connect

The Firebase CLI is a tool that lets you to manage and configure Firebase products and services from the command line.

The CLI provides commands that can be used to perform a variety of Data Connect tasks, like creating a new Data Connect project, initializing a corresponding local working directory, setting up the Data Connect emulator, listing Data Connect resources, generating client SDKs and more.

Setup commands

Add Data Connect to a Firebase project

firebase init

Use firebase init to set up a new local project configuration. This workflow creates or updates Firebase configuration files in your directory.

firebase init

The firebase init flow guides you through setting up a service and database, and optionally installing the Data Connect emulator and configuring generated SDKs.

Service and database setup

If you select dataconnect for product setup, the CLI prompts you for a new service name and location, and whether to link and existing Cloud SQL for PostgreSQL instance or create a new instance.

If an existing instance is linked, the CLI checks for compatible settings, such as IAM authentication and public IP addresses.

Local Emulator Suite setup

The CLI flow offers to set up emulators, including the Data Connect emulator.

Data Connect emulator commands

Start the Data Connect emulator

emulators:start/exec

firebase emulators:start/exec

Use the Local Emulator Suite version of the Data Connect emulator in interactive mode with start or script-driven, non-interactive mode with exec.

Schema and connector management commands

This section contains CLI reference information for commands you use to manage schemas and connectors.

For how-to use cases and recommended practices related to these commands, see the schema and connector management guide.

Deploy schema and connector resources

deploy

firebase deploy

This command deploys resources for Data Connect services indexed in firebase.json. A schema migration is performed if necessary.

Command Description

firebase deploy

Flag Description

–-only dataconnect

Deploy schemas and connectors for all Data Connect services for this project, but don't deploy other Firebase product resources.

–-only dataconnect:serviceId

Deploy schema and connectors for specified Data Connect service.

–-only dataconnect:serviceId:connectorId

Deploy a single connector for specified Data Connect service.

–-only dataconnect:serviceId:schema

Deploy the schema for the specified Data Connect service.

With the –-only flags, you can pass comma-separated values to deploy any subset of resources you want.

firebase deploy --only dataconnect:service1:schema,dataconnect:service2

List Data Connect services, schemas and connectors

dataconnect:services:list

firebase dataconnect:services:list

This command prints out basic info about the services, schemas, and connectors deployed on a project.

Compare and migrate SQL schemas

dataconnect:sql:diff

firebase dataconnect:sql:diff

This command compares local schema for a service with the current schema of the corresponding Cloud SQL database. It prints out the commands that would be run to migrate the database to your new schema.

Command Description

firebase dataconnect:sql:diff

Flag/Parameter Description

serviceId

Specify the service. If omitted, print the diff for all services in firebase.json.

dataconnect:sql:migrate

firebase dataconnect:sql:migrate

This command applies local schema changes to a service's Cloud SQL database.

When you set up a new local Data Connect project, with the default dataconnect.yaml file, the behavior of the dataconect:sql:migrate command is to prompt you for any required changes, and then prompt for any optional changes, before executing the changes. You can modify this behavior to always include or ignore optional changes by updating your dataconnect.yaml configuration, as discussed in migrate a schema in strict or compatible mode

In interactive environments, the CLI displays each migration SQL statement (and whether it is destructive) and prompts for the changes you want to apply. Passing the --force flag is equivalent to accepting all prompts.

In noninteractive environments:

  • without --force, only non-destructive changes are made. If there are destructive changes, the CLI aborts with no changes made.
  • with --force, all changes are made. If this includes any destructive changes, they are printed and you are prompted whether you want to continue, unless the --force flag is provided.
Command Description

firebase dataconnect:sql:migrate

Flag Description

serviceId

Migrate the database for the specified service. The serviceId is inferred if your project has only one service.

–-force

Automatically accept prompts.

As with other --only flags, you can provide multiple services separated by commas.

Migrate a schema in strict or compatible mode

Data Connect schema migrations have two different schema validation modes: strict and compatible. Strict mode validation requires that the database schema exactly match the application schema before the application schema can be deployed. Compatible mode validation requires that the database schema be compatible with the application schema, meaning elements in your database that are not used by your application schema are left unmodified.

These schema validation modes and best practices for schema migration are covered in the schema and connector management guide

The validation mode is defined using the schemaValidation key in your dataconnect.yaml file. If schemaValidation is unspecified, the CLI applies compatible changes and prompts you before executing any strict changes. See the configuration reference.

SDK commands

Generate SDKs

dataconnect:sdk:generate

firebase dataconnect:sdk:generate

This command generates the typed SDKs declared in connector.yaml.

Also see the guides for working with the web SDKs, the Android SDKs and the iOS SDKs.

Command Description

firebase dataconnect:sdk:generate

Flag Description

–-watch

Keeps the process running and generates new SDKs whenever you save changes to your schema and connector GQL files.

If generation fails, errors will be printed to stdout, the generated code won't be changed, and the command will continue running.

–-only connectorId:platform

Only generate SDKs for a single platform and single connector.

With the –only flags, you can pass comma-separated values.

firebase dataconnect:sdk:generate –-only connector1, connector1:kotlin

Cloud SQL management commands

Grant SQL roles for Cloud SQL

dataconnect:sql:grant

firebase dataconnect:sql:grant

Data Connect operates on top of your own PostgreSQL instance hosted on Cloud SQL. In some cases, you might want to access your database directly to query or update the data generated by your Data Connect apps. To do this, you will need to grant one of the roles defined in this section to the needed user or service account.

For details on the granted roles, see PostgreSQL user roles.

Role SQL Role Permissions Usage Grantable
reader firebasereader_<db_name>_<schema_name> Read-only access to the database.

Can perform SELECT operations on all tables within the specified schema.
Ideal for users or services requiring data retrieval but not modification. Yes
writer firebasewriter_<db_name>_<schema_name> Read and write access to the database.

Can perform SELECT, INSERT, UPDATE, DELETE, and TRUNCATE operations on all tables within the schema.
Suitable for users or services that need to modify data within the database. Yes
owner firebaseowner_<db_name>_<schema_name> Schema owner.

Has all privileges on all tables and sequences in the schema.
This role, in combination of the IAM roles/cloudsql.client role, grants permission to performing migration on the database.

For example, when calling firebase dataconnect:sql:migrate.
Yes
superuser cloudsqlsuperuser Built-in superuser role with full privileges on the database.

In addition to owner permissions, it can create schemas, drop schemas, install extensions, and perform any other administrative tasks.

Accessed in the CLI by logging in as "firebasesuperuser".
Required for installing extensions, creating the initial schema, and granting any of the grantable SQL roles to other users.

If a non-admin user needs superuser privileges, the migration will fail and prompt the user to ask the database administrator (i.e., a user with roles/cloudsql.admin) to run the privileged SQL commands.
Granted to users with roles/cloudsql.admin and can't be directly granted from Firebase CLI
Command Description

firebase dataconnect:sql:grant

Flag/Parameter Description

-R, --role role

The SQL role to grant, one of: owner, writer, or reader.

-E, --email email_address

Email for a user or service account to grant the role to.

Global options

The following global options apply to all commands:

  • --json switches CLI output to JSON for parsing by other tools.
  • --noninteractive and --interactive override, as needed, automatic detection of non-TTY environments.