-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Import + export support for the data connect emulator #7836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
26241ce
094164a
6e03ec1
6c9834d
872b150
d8355f3
31560d9
84074cf
f510a73
5d046cf
79f651c
1a13dfa
9c9e139
8b56148
0fe172f
45fdcc2
779d48c
1db3bd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - Added `--import` and `emulators:export` support to the Data Connect emulator. | ||
| - Added `firebase.json#emulators.dataconnect.dataDir`. When set, Data Connect data will be persisted to the configured directory between emulator runs. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,7 @@ | |
| import { AuthEmulator, SingleProjectMode } from "./auth"; | ||
| import { DatabaseEmulator, DatabaseEmulatorArgs } from "./databaseEmulator"; | ||
| import { EventarcEmulator } from "./eventarcEmulator"; | ||
| import { DataConnectEmulator } from "./dataconnectEmulator"; | ||
| import { DataConnectEmulator, DataConnectEmulatorArgs } from "./dataconnectEmulator"; | ||
| import { FirestoreEmulator, FirestoreEmulatorArgs } from "./firestoreEmulator"; | ||
| import { HostingEmulator } from "./hostingEmulator"; | ||
| import { PubsubEmulator } from "./pubsubEmulator"; | ||
|
|
@@ -70,19 +70,20 @@ | |
|
|
||
| /** | ||
| * Exports emulator data on clean exit (SIGINT or process end) | ||
| * @param options | ||
|
Check warning on line 73 in src/emulator/controller.ts
|
||
| */ | ||
| export async function exportOnExit(options: any) { | ||
| const exportOnExitDir = options.exportOnExit; | ||
| export async function exportOnExit(options: Options): Promise<void> { | ||
| // Note: options.exportOnExit is coerced to a string before this point in commandUtils.ts#setExportOnExitOptions | ||
| const exportOnExitDir = options.exportOnExit as string; | ||
| if (exportOnExitDir) { | ||
| try { | ||
| utils.logBullet( | ||
| `Automatically exporting data using ${FLAG_EXPORT_ON_EXIT_NAME} "${exportOnExitDir}" ` + | ||
| "please wait for the export to finish...", | ||
| ); | ||
| await exportEmulatorData(exportOnExitDir, options, /* initiatedBy= */ "exit"); | ||
| } catch (e: any) { | ||
| utils.logWarning(e); | ||
| } catch (e: unknown) { | ||
| utils.logWarning(`${e}`); | ||
| utils.logWarning(`Automatic export to "${exportOnExitDir}" failed, going to exit now...`); | ||
| } | ||
| } | ||
|
|
@@ -90,10 +91,10 @@ | |
|
|
||
| /** | ||
| * Hook to do things when we're exiting cleanly (this does not include errors). Will be skipped on a second SIGINT | ||
| * @param options | ||
|
Check warning on line 94 in src/emulator/controller.ts
|
||
| */ | ||
| export async function onExit(options: any) { | ||
|
Check warning on line 96 in src/emulator/controller.ts
|
||
| await exportOnExit(options); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -112,9 +113,9 @@ | |
|
|
||
| /** | ||
| * Filters a list of emulators to only those specified in the config | ||
| * @param options | ||
|
Check warning on line 116 in src/emulator/controller.ts
|
||
| */ | ||
| export function filterEmulatorTargets(options: { only: string; config: any }): Emulators[] { | ||
| let targets = [...ALL_SERVICE_EMULATORS]; | ||
| targets.push(Emulators.EXTENSIONS); | ||
| targets = targets.filter((e) => { | ||
|
|
@@ -871,19 +872,41 @@ | |
| `TODO: Add support for multiple services in the Data Connect emulator. Currently emulating first service ${config[0].source}`, | ||
| ); | ||
| } | ||
| const configDir = config[0].source; | ||
| const dataConnectEmulator = new DataConnectEmulator({ | ||
|
|
||
| const args: DataConnectEmulatorArgs = { | ||
| listen: listenForEmulator.dataconnect, | ||
| projectId, | ||
| auto_download: true, | ||
| configDir, | ||
| configDir: config[0].source, | ||
| rc: options.rc, | ||
| config: options.config, | ||
| autoconnectToPostgres: true, | ||
| postgresListen: listenForEmulator["dataconnect.postgres"], | ||
| enable_output_generated_sdk: true, // TODO: source from arguments | ||
| enable_output_schema_extensions: true, | ||
| }); | ||
| }; | ||
|
|
||
| if (exportMetadata.dataconnect) { | ||
| utils.assertIsString(options.import); | ||
| const importDirAbsPath = path.resolve(options.import); | ||
| const exportMetadataFilePath = path.resolve( | ||
| importDirAbsPath, | ||
| exportMetadata.dataconnect.path, | ||
| ); | ||
|
|
||
| EmulatorLogger.forEmulator(Emulators.DATACONNECT).logLabeled( | ||
| "BULLET", | ||
| "dataconnect", | ||
| `Importing data from ${exportMetadataFilePath}`, | ||
| ); | ||
| args.importPath = exportMetadataFilePath; | ||
| void trackEmulator("emulator_import", { | ||
| initiated_by: "start", | ||
| emulator_name: Emulators.DATACONNECT, | ||
| }); | ||
| } | ||
|
|
||
| const dataConnectEmulator = new DataConnectEmulator(args); | ||
| await startEmulator(dataConnectEmulator); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can one still clear the DB even if running a separate postgres? I'd say yes, but any concerns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good product q - I think it's reasonable to offer, but if they're connecting to a real DB that becomes a pretty scary big red button.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chatted in local tooling sync - decision is that this is ok, as long as we have a confirmation dialogue in vsce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But given the code as it is written right now, this seems to noop if it's not using pglite.
I think it should either do what it says on the label, or fail with a clear error message (e.g. "unimplemented"), but not noop.