Firebase CLI を使用すると、ローカルのバージョン管理可能なプロジェクト ディレクトリで Firebase プロジェクトを管理できます。これには、プロジェクトの Data Connect サービス、これらのサービスのコネクタ、各コネクタのスキーマ、クエリ、ミューテーション ソースなどのリソースが含まれます。CLI を使用して、Firebase Data Connect エミュレータをインストールして操作することもできます。CLI は、Firebase コンソールでの作業に代わる効率的な方法です。
プライベート プレビュー プログラム用の Firebase CLI 試験運用版のインストール手順と Data Connect 関連の CLI コマンドについては、CLI リファレンスをご覧ください。
このリファレンス ガイドでは、次の内容について説明します。
- firebase.jsonプロジェクト構成ファイル内の Data Connect 固有のエントリ。
- dataconnect.yamlと- connector.yamlの Data Connect 構成。
- Data Connect を使用するプロジェクト用に構成する必要がある IAM ロール。
Firebase プロジェクト構成ファイル
firebase.json 構成リファレンス
dataconnect 鍵を使用して、プロジェクトで 1 つ以上の Data Connect サービスを構成します。
dataconnect: {
   source: string // Path to the directory containing the dataconnect.yaml service file.
}
dataconnect.yaml 構成リファレンス
dataconnect.yaml ファイルには、アプリケーション スキーマ ソース、コネクタ ソース、データソース接続情報の場所に関する構成情報が保存されます。このファイルは、Firebase CLI のプロジェクト ディレクトリの識別子としても機能します。
schemaValidation キーは、デプロイ中にスキーマが移行されるときに実行されるスキーマ検証のレベルを制御します。値を設定しない場合、dataconect:sql:migrate コマンドは互換性のある変更を適用し、厳密な変更を実行する前にプロンプトを表示します。設定すると、次のように動作します。
- STRICTモード。アプリケーション スキーマをデプロイするには、データベース スキーマがアプリケーション スキーマと完全に一致している必要があります。Data Connect スキーマで使用されていないテーブルまたは列は、データベースから削除されます。
- COMPATIBLEモード。アプリケーション スキーマをデプロイする前に、データベース スキーマがアプリケーション スキーマと互換性がある必要があります。追加の変更は任意と見なされます。互換性があるとは、スキーマ移行がユーザーが作成したアプリケーション スキーマに基づいていることを意味します。アプリケーション スキーマで使用されていないデータベース内の要素は変更されません。そのため、デプロイ後にバックエンドに未使用のスキーマ、テーブル、列が含まれることがあります。
このファイル内の他のキーの値については、以下のコメントで説明します。
# The top-level Firebase Data Connect YAML file.
# The Firebase Data Connect API version to target.
# Optional. Defaults to the latest version.
specVersion: string
# The ID of the Firebase Data Connect service resource.
# Required.
serviceId: string
# The location of the Firebase Data Connect service.
# Required.
location: string
# Required.
schema:
  # Relative path to directory for schema definitions.
  # Recursively loads all .gql files in this directory.
  # Optional. If not present, defaults to ./schema.
  source: string
  # Datasource connection information.
  # Required.
  datasource:
    # Required.
    postgresql:
      # The name of the PostgreSQL database.
      # Required.
      database: string
      cloudSql:
        # The ID of the CloudSQL instance resource.
        # Required.
        instanceId: string
        # Schema validation mode for schema migrations.
        # Defaults to unspecified/commented out, meaning you are prompted to
        # review all changes during migration.
        # If desired, uncomment and indicate one of "STRICT" or "COMPATIBLE".
        schemaValidation: string
# Required.
# Relative paths to directories for connector definitions.
# Recursively loads all .gql files in the listed directories.
# All directories specified MUST contain a connector.yaml file.
connectorDirs: [string]
この YAML ファイルは、次のようなデフォルト(ただし構成可能)のディレクトリ構造を想定しています。
./(project root)
   /dataconnect
      dataconnect.yaml
      /schema
        *.gql
      /connector
        connector.yaml
        *.gql
connector.yaml 構成リファレンス
connector.yaml を使用して、デフォルトの認証モードと SDK 生成オプションを構成します。
# The connector-level YAML file.
# Required. The connector name of the Firebase Data Connect connector resource.
connectorId: string
# Optional. If not specified, no generated libraries (i.e. type-safe SDKs) will be generated.
generate:
    # Optional.
    javascriptSdk:
        # Path to the directory that will be updated with the latest generated
        # web SDK.
        # Required.
      - outputDir: string
        # Path to your package.json directory. If specified, the new generated sdk will be installed in this path.
        # Optional. If not provided, the package will not be auto-installed for you.
      - packageJsonDir: string
        # Name of the package to be created.
        # Optional. Defaults to @firebasegen/<connectorID>
      - package: string
        <option>: string
    # Optional.
    swiftSdk:
        # Path to the directory that will be updated with the latest generated
        # iOS Swift SDK.
        # Required.
      - outputDir: string
        # Name of the package to be created.
      - package: string
        <option>: string
    # Optional.
    kotlinSdk:
        # Path to the directory that will be updated with the latest generated
        # Android SDK.
        # Required.
      - outputDir: string
        # Name of the package to be created.
      - package: string
        <option>: string
Data Connect プロジェクトの IAM 構成
Data Connect のきめ細かい IAM ロール
Firebase の基本ロールと事前定義ロールは、下位レベルの Data Connect ロールにマッピングされます。マッピングについては、表を参照してください。
Data Connect の個々の IAM ロールの割り当てをより詳細なレベルで管理するには、Google Cloud コンソールを使用します。
| IAM ロール | 権限 | 
|---|---|
| firebasedataconnect.googleapis.com/adminFirebase Data Connect API 管理者 このロールには Firebase Data Connect API 閲覧者が含まれます。 firebasedataconnect.*と同等です。これは、Cloud オーナー、Cloud 編集者、 Firebase 管理者、Firebase Develop 管理者のロールによって提供されます。 | Firebase Data Connect API リソース(データを含む)への完全アクセス権。 firebasedataconnect.googleapis.com/operations.deletefirebasedataconnect.googleapis.com/operations.cancelfirebasedataconnect.googleapis.com/services.createfirebasedataconnect.googleapis.com/services.updatefirebasedataconnect.googleapis.com/services.deletefirebasedataconnect.googleapis.com/services.executeGraphqlfirebasedataconnect.googleapis.com/services.executeGraphqlReadfirebasedataconnect.googleapis.com/schemas.createfirebasedataconnect.googleapis.com/schemas.updatefirebasedataconnect.googleapis.com/schemas.deletefirebasedataconnect.googleapis.com/schemaRevisions.createfirebasedataconnect.googleapis.com/schemaRevisions.deletefirebasedataconnect.googleapis.com/connectors.createfirebasedataconnect.googleapis.com/connectors.updatefirebasedataconnect.googleapis.com/connectors.deletefirebasedataconnect.googleapis.com/connectorRevisions.createfirebasedataconnect.googleapis.com/connectorRevisions.delete | 
| firebasedataconnect.googleapis.com/viewerFirebase Data Connect API 閲覧者 これは、Cloud オーナー、Cloud 編集者、 Cloud 閲覧者、Firebase 管理者、Firebase 閲覧者、 Firebase Develop 管理者、Firebase Develop 閲覧者のロールによって提供されます。 | Firebase Data Connect API リソースに対する読み取り専用アクセス権。ロールによりデータへのアクセスが許可されることはありません。 cloudresourcemanager.googleapis.com/projects.listcloudresourcemanager.googleapis.com/projects.getfirebasedataconnect.googleapis.com/operations.listfirebasedataconnect.googleapis.com/operations.getfirebasedataconnect.googleapis.com/locations.listfirebasedataconnect.googleapis.com/locations.getfirebasedataconnect.googleapis.com/services.listfirebasedataconnect.googleapis.com/services.getfirebasedataconnect.googleapis.com/schemas.listfirebasedataconnect.googleapis.com/schemas.getfirebasedataconnect.googleapis.com/schemaRevisions.listfirebasedataconnect.googleapis.com/schemaRevisions.getfirebasedataconnect.googleapis.com/connectors.listfirebasedataconnect.googleapis.com/connectors.getfirebasedataconnect.googleapis.com/connectorRevisions.listfirebasedataconnect.googleapis.com/connectorRevisions.get | 
| firebasedataconnect.googleapis.com/dataAdminFirebase Data Connect API データ管理者 これは、Cloud オーナー、Cloud 編集者、 Firebase 管理者、Firebase Develop 管理者のロールによって提供されます。 | データソースに対する完全な読み取り / 書き込みアクセス権。 firebasedataconnect.googleapis.com/services.executeGraphqlfirebasedataconnect.googleapis.com/services.executeGraphqlRead | 
| firebasedataconnect.googleapis.com/dataViewerFirebase Data Connect API データ閲覧者 これは、Cloud オーナー、Cloud 編集者、 Firebase 管理者、Firebase Develop 管理者のロールによって提供されます。 | データソースに対する読み取り専用アクセス権。 firebasedataconnect.googleapis.com/services.executeGraphqlRead |