firebase-tools-with-isolate 14.10.1 → 14.16.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api.js +5 -1
- package/lib/apphosting/backend.js +40 -15
- package/lib/apptesting/ensureProjectConfigured.js +56 -0
- package/lib/apptesting/invokeTests.js +40 -0
- package/lib/apptesting/parseTestFiles.js +75 -0
- package/lib/apptesting/types.js +18 -0
- package/lib/auth.js +37 -2
- package/lib/command.js +24 -5
- package/lib/commands/apphosting-backends-create.js +8 -5
- package/lib/commands/apptesting-execute.js +101 -0
- package/lib/commands/dataconnect-sdk-generate.js +28 -26
- package/lib/commands/dataconnect-services-list.js +1 -1
- package/lib/commands/dataconnect-sql-diff.js +2 -2
- package/lib/commands/dataconnect-sql-grant.js +7 -2
- package/lib/commands/dataconnect-sql-migrate.js +2 -2
- package/lib/commands/dataconnect-sql-setup.js +3 -5
- package/lib/commands/dataconnect-sql-shell.js +2 -2
- package/lib/commands/ext-export.js +1 -1
- package/lib/commands/firestore-bulkdelete.js +73 -0
- package/lib/commands/firestore-databases-create.js +11 -0
- package/lib/commands/firestore-operations-cancel.js +44 -0
- package/lib/commands/firestore-operations-describe.js +29 -0
- package/lib/commands/firestore-operations-list.js +29 -0
- package/lib/commands/firestore-utils.js +15 -0
- package/lib/commands/functions-config-clone.js +2 -0
- package/lib/commands/functions-config-export.js +5 -2
- package/lib/commands/functions-config-get.js +2 -0
- package/lib/commands/functions-config-set.js +2 -0
- package/lib/commands/functions-config-unset.js +2 -0
- package/lib/commands/index.js +9 -0
- package/lib/commands/init.js +24 -4
- package/lib/commands/internaltesting-functions-discover.js +20 -5
- package/lib/commands/login.js +13 -9
- package/lib/commands/use.js +5 -0
- package/lib/config.js +16 -4
- package/lib/crashlytics/addNote.js +27 -0
- package/lib/crashlytics/buildToolsJarHelper.js +1 -2
- package/lib/crashlytics/deleteNote.js +23 -0
- package/lib/crashlytics/getIssueDetails.js +26 -0
- package/lib/crashlytics/getSampleCrash.js +34 -0
- package/lib/crashlytics/listNotes.js +29 -0
- package/lib/crashlytics/listTopDevices.js +33 -0
- package/lib/crashlytics/listTopIssues.js +8 -23
- package/lib/crashlytics/listTopOperatingSystems.js +32 -0
- package/lib/crashlytics/listTopVersions.js +32 -0
- package/lib/crashlytics/updateIssue.js +35 -0
- package/lib/crashlytics/utils.js +38 -0
- package/lib/dataconnect/appFinder.js +102 -0
- package/lib/dataconnect/client.js +23 -15
- package/lib/dataconnect/ensureApis.js +6 -9
- package/lib/dataconnect/errors.js +7 -1
- package/lib/dataconnect/freeTrial.js +16 -38
- package/lib/dataconnect/load.js +105 -6
- package/lib/dataconnect/provisionCloudSql.js +67 -70
- package/lib/dataconnect/schemaMigration.js +219 -169
- package/lib/deploy/dataconnect/deploy.js +7 -9
- package/lib/deploy/dataconnect/prepare.js +7 -12
- package/lib/deploy/dataconnect/release.js +43 -31
- package/lib/deploy/firestore/deploy.js +10 -0
- package/lib/deploy/functions/backend.js +7 -1
- package/lib/deploy/functions/build.js +28 -14
- package/lib/deploy/functions/deploy.js +3 -2
- package/lib/deploy/functions/ensure.js +1 -1
- package/lib/deploy/functions/functionsDeployHelper.js +8 -1
- package/lib/deploy/functions/params.js +4 -0
- package/lib/deploy/functions/prepare.js +25 -13
- package/lib/deploy/functions/pricing.js +12 -5
- package/lib/deploy/functions/release/fabricator.js +25 -3
- package/lib/deploy/functions/release/reporter.js +1 -0
- package/lib/deploy/functions/runtimes/discovery/index.js +52 -5
- package/lib/deploy/functions/runtimes/node/index.js +83 -51
- package/lib/emulator/auth/operations.js +10 -1
- package/lib/emulator/commandUtils.js +7 -1
- package/lib/emulator/controller.js +22 -34
- package/lib/emulator/dataconnectEmulator.js +27 -24
- package/lib/emulator/downloadableEmulatorInfo.json +18 -18
- package/lib/emulator/env.js +2 -1
- package/lib/emulator/functionsEmulator.js +12 -2
- package/lib/emulator/hub.js +11 -8
- package/lib/emulator/tasksEmulator.js +1 -1
- package/lib/emulator/ui.js +3 -1
- package/lib/env.js +18 -0
- package/lib/experiments.js +20 -0
- package/lib/extensions/extensionsHelper.js +4 -15
- package/lib/extensions/runtimes/common.js +3 -2
- package/lib/extensions/utils.js +1 -12
- package/lib/firestore/api-sort.js +96 -3
- package/lib/firestore/api-types.js +20 -1
- package/lib/firestore/api.js +144 -15
- package/lib/firestore/pretty-print.js +35 -1
- package/lib/firestore/validator.js +1 -1
- package/lib/functional.js +7 -1
- package/lib/functions/deprecationWarnings.js +21 -0
- package/lib/functions/env.js +31 -16
- package/lib/functions/projectConfig.js +87 -8
- package/lib/functions/secrets.js +3 -0
- package/lib/gcp/cloudfunctions.js +1 -6
- package/lib/gcp/cloudfunctionsv2.js +3 -39
- package/lib/gcp/cloudscheduler.js +1 -1
- package/lib/gcp/cloudsql/cloudsqladmin.js +4 -16
- package/lib/gcp/cloudsql/connect.js +4 -3
- package/lib/gcp/cloudsql/permissionsSetup.js +23 -16
- package/lib/gcp/k8s.js +32 -0
- package/lib/gcp/runv2.js +181 -0
- package/lib/gemini/fdcExperience.js +5 -3
- package/lib/init/features/aitools/claude.js +43 -0
- package/lib/init/features/aitools/cursor.js +61 -0
- package/lib/init/features/aitools/gemini.js +58 -0
- package/lib/init/features/aitools/index.js +28 -0
- package/lib/init/features/aitools/promptUpdater.js +111 -0
- package/lib/init/features/aitools/studio.js +17 -0
- package/lib/init/features/aitools/types.js +2 -0
- package/lib/init/features/aitools.js +83 -0
- package/lib/init/features/apptesting/index.js +34 -0
- package/lib/init/features/dataconnect/create_app.js +53 -0
- package/lib/init/features/dataconnect/index.js +280 -186
- package/lib/init/features/dataconnect/sdk.js +232 -144
- package/lib/init/features/index.js +8 -3
- package/lib/init/features/project.js +4 -0
- package/lib/init/index.js +18 -2
- package/lib/management/apps.js +3 -3
- package/lib/management/studio.js +120 -0
- package/lib/mcp/errors.js +5 -7
- package/lib/mcp/index.js +179 -61
- package/lib/mcp/logging-transport.js +23 -0
- package/lib/mcp/prompt.js +10 -0
- package/lib/mcp/prompts/core/deploy.js +101 -0
- package/lib/mcp/prompts/core/index.js +5 -0
- package/lib/mcp/prompts/crashlytics/connect.js +114 -0
- package/lib/mcp/prompts/crashlytics/index.js +5 -0
- package/lib/mcp/prompts/dataconnect/index.js +9 -0
- package/lib/mcp/prompts/dataconnect/schema.js +67 -0
- package/lib/mcp/prompts/index.js +47 -0
- package/lib/mcp/tools/apphosting/fetch_logs.js +22 -22
- package/lib/mcp/tools/apphosting/list_backends.js +10 -10
- package/lib/mcp/tools/auth/disable_user.js +7 -7
- package/lib/mcp/tools/auth/get_user.js +13 -6
- package/lib/mcp/tools/auth/index.js +10 -10
- package/lib/mcp/tools/auth/list_users.js +6 -6
- package/lib/mcp/tools/auth/set_claims.js +7 -7
- package/lib/mcp/tools/auth/set_sms_region_policy.js +6 -6
- package/lib/mcp/tools/core/consult_assistant.js +13 -8
- package/lib/mcp/tools/core/create_android_sha.js +9 -9
- package/lib/mcp/tools/core/create_app.js +7 -7
- package/lib/mcp/tools/core/create_project.js +13 -13
- package/lib/mcp/tools/core/get_admin_sdk_config.js +7 -7
- package/lib/mcp/tools/core/get_environment.js +8 -8
- package/lib/mcp/tools/core/get_project.js +5 -5
- package/lib/mcp/tools/core/get_sdk_config.js +19 -9
- package/lib/mcp/tools/core/index.js +28 -24
- package/lib/mcp/tools/core/init.js +39 -16
- package/lib/mcp/tools/core/list_apps.js +6 -6
- package/lib/mcp/tools/core/list_projects.js +6 -6
- package/lib/mcp/tools/core/login.js +46 -0
- package/lib/mcp/tools/core/logout.js +62 -0
- package/lib/mcp/tools/core/update_environment.js +10 -10
- package/lib/mcp/tools/crashlytics/add_note.js +32 -0
- package/lib/mcp/tools/crashlytics/constants.js +11 -0
- package/lib/mcp/tools/crashlytics/delete_note.js +35 -0
- package/lib/mcp/tools/crashlytics/get_issue_details.js +31 -0
- package/lib/mcp/tools/crashlytics/get_sample_crash.js +43 -0
- package/lib/mcp/tools/crashlytics/index.js +22 -2
- package/lib/mcp/tools/crashlytics/list_notes.js +37 -0
- package/lib/mcp/tools/crashlytics/list_top_devices.js +33 -0
- package/lib/mcp/tools/crashlytics/list_top_issues.js +12 -13
- package/lib/mcp/tools/crashlytics/list_top_operating_systems.js +33 -0
- package/lib/mcp/tools/crashlytics/list_top_versions.js +33 -0
- package/lib/mcp/tools/crashlytics/update_issue.js +37 -0
- package/lib/mcp/tools/database/get_data.js +49 -0
- package/lib/mcp/tools/database/get_rules.js +39 -0
- package/lib/mcp/tools/database/index.js +8 -0
- package/lib/mcp/tools/database/set_data.js +57 -0
- package/lib/mcp/tools/database/validate_rules.js +41 -0
- package/lib/mcp/tools/dataconnect/compile.js +43 -0
- package/lib/mcp/tools/dataconnect/execute.js +71 -0
- package/lib/mcp/tools/dataconnect/generate_operation.js +8 -8
- package/lib/mcp/tools/dataconnect/generate_schema.js +6 -6
- package/lib/mcp/tools/dataconnect/index.js +10 -18
- package/lib/mcp/tools/dataconnect/list_services.js +107 -11
- package/lib/mcp/tools/firestore/delete_document.js +13 -13
- package/lib/mcp/tools/firestore/get_documents.js +13 -13
- package/lib/mcp/tools/firestore/list_collections.js +7 -10
- package/lib/mcp/tools/firestore/query_collection.js +13 -13
- package/lib/mcp/tools/index.js +24 -18
- package/lib/mcp/tools/messaging/index.js +2 -2
- package/lib/mcp/tools/messaging/send_message.js +7 -7
- package/lib/mcp/tools/remoteconfig/get_template.js +5 -5
- package/lib/mcp/tools/remoteconfig/index.js +4 -4
- package/lib/mcp/tools/remoteconfig/publish_template.js +7 -7
- package/lib/mcp/tools/remoteconfig/rollback_template.js +6 -6
- package/lib/mcp/tools/rules/get_rules.js +8 -8
- package/lib/mcp/tools/rules/validate_rules.js +10 -10
- package/lib/mcp/tools/storage/get_download_url.js +8 -8
- package/lib/mcp/tools/storage/get_rules.js +8 -8
- package/lib/mcp/types.js +2 -0
- package/lib/mcp/util/dataconnect/compile.js +20 -0
- package/lib/mcp/util/dataconnect/content.js +655 -0
- package/lib/mcp/util/dataconnect/emulator.js +16 -0
- package/lib/mcp/util.js +5 -18
- package/lib/requireAuth.js +14 -4
- package/lib/rtdb.js +10 -6
- package/lib/scopes.js +2 -1
- package/lib/serve/functions.js +4 -3
- package/lib/timeout.js +21 -0
- package/lib/track.js +18 -1
- package/lib/unzip.js +13 -0
- package/lib/utils.js +76 -2
- package/package.json +6 -4
- package/prompts/FIREBASE.md +121 -0
- package/prompts/FIREBASE_FUNCTIONS.md +221 -0
- package/schema/apptesting-yaml.json +64 -0
- package/schema/firebase-config.json +163 -53
- package/templates/init/aitools/cursor-rules-header.txt +8 -0
- package/templates/init/aitools/gemini-extension.json +11 -0
- package/templates/init/apptesting/smoke_test.yaml +6 -0
- package/templates/init/dataconnect/connector.yaml +0 -16
- package/templates/init/dataconnect/dataconnect.yaml +2 -1
- package/templates/init/dataconnect/mutations.gql +29 -29
- package/templates/init/dataconnect/queries.gql +73 -73
- package/templates/init/dataconnect/schema.gql +48 -48
- package/templates/init/firestore/firestore.indexes.json +26 -1
- package/lib/dataconnect/fileUtils.js +0 -168
- package/lib/emulator/adminSdkConfig.test.js +0 -16
- package/lib/extensions/resolveSource.js +0 -23
- package/lib/firestore/api-sort.test.js +0 -74
- package/lib/firestore/backupUtils.test.js +0 -18
- package/lib/firestore/pretty-print.test.js +0 -61
- package/lib/firestore/util.test.js +0 -42
- package/lib/mcp/tools/dataconnect/emulator.js +0 -16
- package/lib/mcp/tools/dataconnect/execute_graphql.js +0 -48
- package/lib/mcp/tools/dataconnect/execute_graphql_read.js +0 -48
- package/lib/mcp/tools/dataconnect/execute_mutation.js +0 -62
- package/lib/mcp/tools/dataconnect/execute_query.js +0 -62
- package/lib/mcp/tools/dataconnect/get_connector.js +0 -31
- package/lib/mcp/tools/dataconnect/get_schema.js +0 -31
- /package/lib/mcp/{tools → util}/dataconnect/converter.js +0 -0
|
@@ -16,97 +16,120 @@ const utils_1 = require("../utils");
|
|
|
16
16
|
const cloudsqladmin_1 = require("../gcp/cloudsql/cloudsqladmin");
|
|
17
17
|
const cloudSqlAdminClient = require("../gcp/cloudsql/cloudsqladmin");
|
|
18
18
|
const errors = require("./errors");
|
|
19
|
+
const provisionCloudSql_1 = require("./provisionCloudSql");
|
|
20
|
+
const requireAuth_1 = require("../requireAuth");
|
|
19
21
|
async function setupSchemaIfNecessary(instanceId, databaseId, options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
schemaInfo.setupStatus
|
|
24
|
-
|
|
22
|
+
try {
|
|
23
|
+
await (0, connect_1.setupIAMUsers)(instanceId, options);
|
|
24
|
+
const schemaInfo = await (0, permissionsSetup_1.getSchemaMetadata)(instanceId, databaseId, permissions_1.DEFAULT_SCHEMA, options);
|
|
25
|
+
switch (schemaInfo.setupStatus) {
|
|
26
|
+
case permissionsSetup_1.SchemaSetupStatus.BrownField:
|
|
27
|
+
case permissionsSetup_1.SchemaSetupStatus.GreenField:
|
|
28
|
+
logger_1.logger.debug(`Cloud SQL Database ${instanceId}:${databaseId} is already set up in ${schemaInfo.setupStatus}`);
|
|
29
|
+
return schemaInfo.setupStatus;
|
|
30
|
+
case permissionsSetup_1.SchemaSetupStatus.NotSetup:
|
|
31
|
+
case permissionsSetup_1.SchemaSetupStatus.NotFound:
|
|
32
|
+
(0, utils_1.logLabeledBullet)("dataconnect", "Setting up Cloud SQL Database SQL permissions...");
|
|
33
|
+
return await (0, permissionsSetup_1.setupSQLPermissions)(instanceId, databaseId, schemaInfo, options, true);
|
|
34
|
+
default:
|
|
35
|
+
throw new error_1.FirebaseError(`Unexpected schema setup status: ${schemaInfo.setupStatus}`);
|
|
36
|
+
}
|
|
25
37
|
}
|
|
26
|
-
|
|
27
|
-
|
|
38
|
+
catch (err) {
|
|
39
|
+
throw new error_1.FirebaseError(`Cannot setup Postgres SQL permissions of Cloud SQL database ${instanceId}:${databaseId}\n${err}`);
|
|
28
40
|
}
|
|
29
|
-
return schemaInfo.setupStatus;
|
|
30
41
|
}
|
|
31
42
|
async function diffSchema(options, schema, schemaValidation) {
|
|
32
|
-
|
|
43
|
+
let validationMode = schemaValidation ?? "STRICT";
|
|
44
|
+
setSchemaValidationMode(schema, validationMode);
|
|
45
|
+
displayStartSchemaDiff(validationMode);
|
|
33
46
|
const { serviceName, instanceName, databaseId, instanceId } = getIdentifiers(schema);
|
|
34
47
|
await ensureServiceIsConnectedToCloudSql(serviceName, instanceName, databaseId, false);
|
|
35
|
-
let
|
|
36
|
-
await setupSchemaIfNecessary(instanceId, databaseId, options);
|
|
37
|
-
let validationMode = schemaValidation ?? "COMPATIBLE";
|
|
38
|
-
setSchemaValidationMode(schema, validationMode);
|
|
48
|
+
let incompatible = undefined;
|
|
39
49
|
try {
|
|
40
50
|
await (0, client_1.upsertSchema)(schema, true);
|
|
41
|
-
|
|
42
|
-
(0, utils_1.logLabeledSuccess)("dataconnect", `database schema of ${instanceId}:${databaseId} is up to date.`);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
(0, utils_1.logLabeledSuccess)("dataconnect", `database schema of ${instanceId}:${databaseId} is compatible.`);
|
|
46
|
-
}
|
|
51
|
+
displayNoSchemaDiff(instanceId, databaseId, validationMode);
|
|
47
52
|
}
|
|
48
53
|
catch (err) {
|
|
49
54
|
if (err?.status !== 400) {
|
|
50
55
|
throw err;
|
|
51
56
|
}
|
|
57
|
+
incompatible = errors.getIncompatibleSchemaError(err);
|
|
52
58
|
const invalidConnectors = errors.getInvalidConnectors(err);
|
|
53
|
-
const incompatible = errors.getIncompatibleSchemaError(err);
|
|
54
59
|
if (!incompatible && !invalidConnectors.length) {
|
|
60
|
+
const gqlErrs = errors.getGQLErrors(err);
|
|
61
|
+
if (gqlErrs) {
|
|
62
|
+
throw new error_1.FirebaseError(`There are errors in your schema files:\n${gqlErrs}`);
|
|
63
|
+
}
|
|
55
64
|
throw err;
|
|
56
65
|
}
|
|
57
66
|
if (invalidConnectors.length) {
|
|
58
67
|
displayInvalidConnectors(invalidConnectors);
|
|
59
68
|
}
|
|
60
|
-
if (incompatible) {
|
|
61
|
-
displaySchemaChanges(incompatible, validationMode, instanceName, databaseId);
|
|
62
|
-
diffs = incompatible.diffs;
|
|
63
|
-
}
|
|
64
69
|
}
|
|
65
|
-
if (!
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
displaySchemaChanges(incompatible, validationMode, instanceName, databaseId);
|
|
85
|
-
}
|
|
86
|
-
diffs = incompatible.diffs;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
(0, utils_1.logLabeledSuccess)("dataconnect", `no additional optional changes`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
70
|
+
if (!incompatible) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
if (schemaValidation) {
|
|
74
|
+
displaySchemaChanges(incompatible, validationMode);
|
|
75
|
+
return incompatible.diffs;
|
|
76
|
+
}
|
|
77
|
+
const strictIncompatible = incompatible;
|
|
78
|
+
let compatibleIncompatible = undefined;
|
|
79
|
+
validationMode = "COMPATIBLE";
|
|
80
|
+
setSchemaValidationMode(schema, validationMode);
|
|
81
|
+
try {
|
|
82
|
+
displayStartSchemaDiff(validationMode);
|
|
83
|
+
await (0, client_1.upsertSchema)(schema, true);
|
|
84
|
+
displayNoSchemaDiff(instanceId, databaseId, validationMode);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
if (err?.status !== 400) {
|
|
88
|
+
throw err;
|
|
92
89
|
}
|
|
90
|
+
compatibleIncompatible = errors.getIncompatibleSchemaError(err);
|
|
93
91
|
}
|
|
94
|
-
|
|
92
|
+
if (!compatibleIncompatible) {
|
|
93
|
+
displaySchemaChanges(strictIncompatible, "STRICT");
|
|
94
|
+
}
|
|
95
|
+
else if (diffsEqual(strictIncompatible.diffs, compatibleIncompatible.diffs)) {
|
|
96
|
+
displaySchemaChanges(strictIncompatible, "STRICT");
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
displaySchemaChanges(compatibleIncompatible, "COMPATIBLE");
|
|
100
|
+
displaySchemaChanges(strictIncompatible, "STRICT_AFTER_COMPATIBLE");
|
|
101
|
+
}
|
|
102
|
+
return incompatible.diffs;
|
|
95
103
|
}
|
|
96
104
|
exports.diffSchema = diffSchema;
|
|
97
105
|
async function migrateSchema(args) {
|
|
98
|
-
(0, utils_1.logLabeledBullet)("dataconnect", `generating required schema changes...`);
|
|
99
106
|
const { options, schema, validateOnly, schemaValidation } = args;
|
|
107
|
+
let validationMode = schemaValidation ?? "COMPATIBLE";
|
|
108
|
+
setSchemaValidationMode(schema, validationMode);
|
|
109
|
+
displayStartSchemaDiff(validationMode);
|
|
110
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
100
111
|
const { serviceName, instanceId, instanceName, databaseId } = getIdentifiers(schema);
|
|
101
112
|
await ensureServiceIsConnectedToCloudSql(serviceName, instanceName, databaseId, true);
|
|
102
|
-
await (
|
|
103
|
-
|
|
113
|
+
const existingInstance = await cloudSqlAdminClient.getInstance(projectId, instanceId);
|
|
114
|
+
if (existingInstance.state === "PENDING_CREATE") {
|
|
115
|
+
const postgresql = schema.datasources.find((d) => d.postgresql)?.postgresql;
|
|
116
|
+
if (!postgresql) {
|
|
117
|
+
throw new error_1.FirebaseError(`Cannot find Postgres datasource in the schema to deploy: ${serviceName}/schemas/${types_1.SCHEMA_ID}.\nIts datasources: ${JSON.stringify(schema.datasources)}`);
|
|
118
|
+
}
|
|
119
|
+
postgresql.schemaValidation = "NONE";
|
|
120
|
+
postgresql.schemaMigration = undefined;
|
|
121
|
+
await (0, client_1.upsertSchema)(schema, validateOnly);
|
|
122
|
+
postgresql.schemaValidation = undefined;
|
|
123
|
+
postgresql.schemaMigration = "MIGRATE_COMPATIBLE";
|
|
124
|
+
await (0, client_1.upsertSchema)(schema, validateOnly, true);
|
|
125
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `Skip SQL schema migration because Cloud SQL is still being created`);
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
104
128
|
await setupSchemaIfNecessary(instanceId, databaseId, options);
|
|
105
|
-
let
|
|
106
|
-
setSchemaValidationMode(schema, validationMode);
|
|
129
|
+
let diffs = [];
|
|
107
130
|
try {
|
|
108
131
|
await (0, client_1.upsertSchema)(schema, validateOnly);
|
|
109
|
-
(
|
|
132
|
+
displayNoSchemaDiff(instanceId, databaseId, validationMode);
|
|
110
133
|
}
|
|
111
134
|
catch (err) {
|
|
112
135
|
if (err?.status !== 400) {
|
|
@@ -115,9 +138,13 @@ async function migrateSchema(args) {
|
|
|
115
138
|
const incompatible = errors.getIncompatibleSchemaError(err);
|
|
116
139
|
const invalidConnectors = errors.getInvalidConnectors(err);
|
|
117
140
|
if (!incompatible && !invalidConnectors.length) {
|
|
141
|
+
const gqlErrs = errors.getGQLErrors(err);
|
|
142
|
+
if (gqlErrs) {
|
|
143
|
+
throw new error_1.FirebaseError(`There are errors in your schema files:\n${gqlErrs}`);
|
|
144
|
+
}
|
|
118
145
|
throw err;
|
|
119
146
|
}
|
|
120
|
-
const migrationMode = await promptForSchemaMigration(options,
|
|
147
|
+
const migrationMode = await promptForSchemaMigration(options, instanceId, databaseId, incompatible, validateOnly, validationMode);
|
|
121
148
|
const shouldDeleteInvalidConnectors = await promptForInvalidConnectorError(options, serviceName, invalidConnectors, validateOnly);
|
|
122
149
|
if (incompatible) {
|
|
123
150
|
diffs = await handleIncompatibleSchemaError({
|
|
@@ -150,7 +177,7 @@ async function migrateSchema(args) {
|
|
|
150
177
|
if (!incompatible && !invalidConnectors.length) {
|
|
151
178
|
throw err;
|
|
152
179
|
}
|
|
153
|
-
const migrationMode = await promptForSchemaMigration(options,
|
|
180
|
+
const migrationMode = await promptForSchemaMigration(options, instanceId, databaseId, incompatible, validateOnly, "STRICT_AFTER_COMPATIBLE");
|
|
154
181
|
if (incompatible) {
|
|
155
182
|
const maybeDiffs = await handleIncompatibleSchemaError({
|
|
156
183
|
options,
|
|
@@ -169,22 +196,13 @@ exports.migrateSchema = migrateSchema;
|
|
|
169
196
|
async function grantRoleToUserInSchema(options, schema) {
|
|
170
197
|
const role = options.role;
|
|
171
198
|
const email = options.email;
|
|
172
|
-
const { instanceId, databaseId } = getIdentifiers(schema);
|
|
173
|
-
|
|
174
|
-
const { user, mode } = (0, connect_1.toDatabaseUser)(email);
|
|
175
|
-
const fdcSqlRole = permissionsSetup_1.fdcSqlRoleMap[role](databaseId);
|
|
176
|
-
await (0, connect_1.setupIAMUsers)(instanceId, databaseId, options);
|
|
177
|
-
const userIsCSQLAdmin = await (0, cloudsqladmin_1.iamUserIsCSQLAdmin)(options);
|
|
178
|
-
if (!userIsCSQLAdmin) {
|
|
179
|
-
throw new error_1.FirebaseError(`Only users with 'roles/cloudsql.admin' can grant SQL roles. If you do not have this role, ask your database administrator to run this command or manually grant ${fdcSqlRole} to ${user}`);
|
|
180
|
-
}
|
|
199
|
+
const { serviceName, instanceId, instanceName, databaseId } = getIdentifiers(schema);
|
|
200
|
+
await ensureServiceIsConnectedToCloudSql(serviceName, instanceName, databaseId, false);
|
|
181
201
|
const schemaSetupStatus = await setupSchemaIfNecessary(instanceId, databaseId, options);
|
|
182
|
-
if (schemaSetupStatus !== permissionsSetup_1.SchemaSetupStatus.GreenField &&
|
|
183
|
-
|
|
184
|
-
throw new error_1.FirebaseError(`Owner rule isn't available in brownfield databases. If you would like Data Connect to manage and own your database schema, run 'firebase dataconnect:sql:setup'`);
|
|
202
|
+
if (schemaSetupStatus !== permissionsSetup_1.SchemaSetupStatus.GreenField && role === "owner") {
|
|
203
|
+
throw new error_1.FirebaseError(`Owner rule isn't available in ${schemaSetupStatus} databases. If you would like Data Connect to manage and own your database schema, run 'firebase dataconnect:sql:setup'`);
|
|
185
204
|
}
|
|
186
|
-
await
|
|
187
|
-
await (0, connect_1.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, [`GRANT "${fdcSqlRole}" TO "${user}"`], false);
|
|
205
|
+
await (0, permissionsSetup_1.grantRoleTo)(options, instanceId, databaseId, role, email);
|
|
188
206
|
}
|
|
189
207
|
exports.grantRoleToUserInSchema = grantRoleToUserInSchema;
|
|
190
208
|
function diffsEqual(x, y) {
|
|
@@ -210,11 +228,11 @@ function getIdentifiers(schema) {
|
|
|
210
228
|
const postgresDatasource = schema.datasources.find((d) => d.postgresql);
|
|
211
229
|
const databaseId = postgresDatasource?.postgresql?.database;
|
|
212
230
|
if (!databaseId) {
|
|
213
|
-
throw new error_1.FirebaseError("
|
|
231
|
+
throw new error_1.FirebaseError("Data Connect schema must have a postgres datasource with a database name.");
|
|
214
232
|
}
|
|
215
|
-
const instanceName = postgresDatasource?.postgresql?.cloudSql
|
|
233
|
+
const instanceName = postgresDatasource?.postgresql?.cloudSql?.instance;
|
|
216
234
|
if (!instanceName) {
|
|
217
|
-
throw new error_1.FirebaseError("
|
|
235
|
+
throw new error_1.FirebaseError("Data Connect schema must have a postgres datasource with a CloudSQL instance.");
|
|
218
236
|
}
|
|
219
237
|
const instanceId = instanceName.split("/").pop();
|
|
220
238
|
const serviceName = schema.name.replace(`/schemas/${types_1.SCHEMA_ID}`, "");
|
|
@@ -234,11 +252,7 @@ function suggestedCommand(serviceName, invalidConnectorNames) {
|
|
|
234
252
|
}
|
|
235
253
|
async function handleIncompatibleSchemaError(args) {
|
|
236
254
|
const { incompatibleSchemaError, options, instanceId, databaseId, choice } = args;
|
|
237
|
-
|
|
238
|
-
throw new error_1.FirebaseError("This schema migration includes potentially destructive changes. If you'd like to execute it anyway, rerun this command with --force");
|
|
239
|
-
}
|
|
240
|
-
const commandsToExecute = incompatibleSchemaError.diffs
|
|
241
|
-
.filter((d) => {
|
|
255
|
+
const commandsToExecute = incompatibleSchemaError.diffs.filter((d) => {
|
|
242
256
|
switch (choice) {
|
|
243
257
|
case "all":
|
|
244
258
|
return true;
|
|
@@ -247,16 +261,15 @@ async function handleIncompatibleSchemaError(args) {
|
|
|
247
261
|
case "none":
|
|
248
262
|
return false;
|
|
249
263
|
}
|
|
250
|
-
})
|
|
251
|
-
.map((d) => d.sql);
|
|
264
|
+
});
|
|
252
265
|
if (commandsToExecute.length) {
|
|
253
|
-
const commandsToExecuteBySuperUser = commandsToExecute.filter(
|
|
254
|
-
const commandsToExecuteByOwner = commandsToExecute.filter((sql) => !
|
|
266
|
+
const commandsToExecuteBySuperUser = commandsToExecute.filter(requireSuperUser);
|
|
267
|
+
const commandsToExecuteByOwner = commandsToExecute.filter((sql) => !requireSuperUser(sql));
|
|
255
268
|
const userIsCSQLAdmin = await (0, cloudsqladmin_1.iamUserIsCSQLAdmin)(options);
|
|
256
269
|
if (!userIsCSQLAdmin && commandsToExecuteBySuperUser.length) {
|
|
257
270
|
throw new error_1.FirebaseError(`Some SQL commands required for this migration require Admin permissions.\n
|
|
258
271
|
Please ask a user with 'roles/cloudsql.admin' to apply the following commands.\n
|
|
259
|
-
${commandsToExecuteBySuperUser
|
|
272
|
+
${diffsToString(commandsToExecuteBySuperUser)}`);
|
|
260
273
|
}
|
|
261
274
|
const schemaInfo = await (0, permissionsSetup_1.getSchemaMetadata)(instanceId, databaseId, permissions_1.DEFAULT_SCHEMA, options);
|
|
262
275
|
if (schemaInfo.setupStatus !== permissionsSetup_1.SchemaSetupStatus.GreenField) {
|
|
@@ -265,56 +278,67 @@ async function handleIncompatibleSchemaError(args) {
|
|
|
265
278
|
`If you would like Data Connect to manage your database schema, run 'firebase dataconnect:sql:setup'`);
|
|
266
279
|
}
|
|
267
280
|
if (!(await (0, permissionsSetup_1.checkSQLRoleIsGranted)(options, instanceId, databaseId, (0, permissions_1.firebaseowner)(databaseId), (await (0, connect_1.getIAMUser)(options)).user))) {
|
|
268
|
-
|
|
281
|
+
if (!userIsCSQLAdmin) {
|
|
282
|
+
throw new error_1.FirebaseError(`Command aborted. Only users granted firebaseowner SQL role can run migrations.`);
|
|
283
|
+
}
|
|
284
|
+
const account = (await (0, requireAuth_1.requireAuth)(options));
|
|
285
|
+
(0, utils_1.logLabeledBullet)("dataconnect", `Granting firebaseowner role to myself ${account}...`);
|
|
286
|
+
await (0, permissionsSetup_1.grantRoleTo)(options, instanceId, databaseId, "owner", account);
|
|
269
287
|
}
|
|
270
288
|
if (commandsToExecuteBySuperUser.length) {
|
|
271
|
-
|
|
272
|
-
await (0, connect_1.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, commandsToExecuteBySuperUser, false);
|
|
289
|
+
(0, utils_1.logLabeledBullet)("dataconnect", `Executing admin SQL commands as superuser...`);
|
|
290
|
+
await (0, connect_1.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, commandsToExecuteBySuperUser.map((d) => d.sql), false);
|
|
273
291
|
}
|
|
274
292
|
if (commandsToExecuteByOwner.length) {
|
|
275
|
-
await (0, connect_1.executeSqlCmdsAsIamUser)(options, instanceId, databaseId, [`SET ROLE "${(0, permissions_1.firebaseowner)(databaseId)}"`, ...commandsToExecuteByOwner], false);
|
|
293
|
+
await (0, connect_1.executeSqlCmdsAsIamUser)(options, instanceId, databaseId, [`SET ROLE "${(0, permissions_1.firebaseowner)(databaseId)}"`, ...commandsToExecuteByOwner.map((d) => d.sql)], false);
|
|
276
294
|
return incompatibleSchemaError.diffs;
|
|
277
295
|
}
|
|
278
296
|
}
|
|
279
297
|
return [];
|
|
280
298
|
}
|
|
281
|
-
async function promptForSchemaMigration(options,
|
|
299
|
+
async function promptForSchemaMigration(options, instanceId, databaseId, err, validateOnly, validationMode) {
|
|
282
300
|
if (!err) {
|
|
283
301
|
return "none";
|
|
284
302
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
displaySchemaChanges(err, validationMode, instanceName, databaseId);
|
|
303
|
+
const defaultChoice = validationMode === "STRICT_AFTER_COMPATIBLE" ? "none" : "all";
|
|
304
|
+
displaySchemaChanges(err, validationMode);
|
|
289
305
|
if (!options.nonInteractive) {
|
|
290
306
|
if (validateOnly && options.force) {
|
|
291
|
-
return
|
|
307
|
+
return defaultChoice;
|
|
308
|
+
}
|
|
309
|
+
let choices = [
|
|
310
|
+
{ name: "Execute all", value: "all" },
|
|
311
|
+
];
|
|
312
|
+
if (err.destructive) {
|
|
313
|
+
choices = [{ name: `Execute all ${clc.red("(including destructive)")}`, value: "all" }];
|
|
314
|
+
if (err.diffs.some((d) => !d.destructive)) {
|
|
315
|
+
choices.push({ name: "Execute safe only", value: "safe" });
|
|
316
|
+
}
|
|
292
317
|
}
|
|
293
|
-
const message = validationMode === "STRICT_AFTER_COMPATIBLE"
|
|
294
|
-
? `Would you like to execute these optional changes against ${databaseId} in your CloudSQL instance ${instanceName}?`
|
|
295
|
-
: `Would you like to execute these changes against ${databaseId} in your CloudSQL instance ${instanceName}?`;
|
|
296
|
-
let executeChangePrompt = "Execute changes";
|
|
297
318
|
if (validationMode === "STRICT_AFTER_COMPATIBLE") {
|
|
298
|
-
|
|
319
|
+
choices.push({ name: "Skip them", value: "none" });
|
|
299
320
|
}
|
|
300
|
-
|
|
301
|
-
|
|
321
|
+
else {
|
|
322
|
+
choices.push({ name: "Abort", value: "abort" });
|
|
302
323
|
}
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
324
|
+
const ans = await (0, prompt_1.select)({
|
|
325
|
+
message: `Do you want to execute these SQL against ${instanceId}:${databaseId}?`,
|
|
326
|
+
choices: choices,
|
|
327
|
+
default: defaultChoice,
|
|
328
|
+
});
|
|
329
|
+
if (ans === "abort") {
|
|
330
|
+
throw new error_1.FirebaseError("Command aborted.");
|
|
331
|
+
}
|
|
332
|
+
return ans;
|
|
309
333
|
}
|
|
310
334
|
if (!validateOnly) {
|
|
311
335
|
throw new error_1.FirebaseError("Command aborted. Your database schema is incompatible with your Data Connect schema. Run `firebase dataconnect:sql:migrate` to migrate your database schema");
|
|
312
336
|
}
|
|
313
337
|
else if (options.force) {
|
|
314
|
-
return
|
|
338
|
+
return defaultChoice;
|
|
315
339
|
}
|
|
316
340
|
else if (!err.destructive) {
|
|
317
|
-
return
|
|
341
|
+
return defaultChoice;
|
|
318
342
|
}
|
|
319
343
|
else {
|
|
320
344
|
throw new error_1.FirebaseError("Command aborted. This schema migration includes potentially destructive changes. If you'd like to execute it anyway, rerun this command with --force");
|
|
@@ -346,17 +370,26 @@ async function deleteInvalidConnectors(invalidConnectors) {
|
|
|
346
370
|
}
|
|
347
371
|
function displayInvalidConnectors(invalidConnectors) {
|
|
348
372
|
const connectorIds = invalidConnectors.map((i) => i.split("/").pop()).join(", ");
|
|
349
|
-
(0, utils_1.logLabeledWarning)("dataconnect", `The schema you are deploying is incompatible with the following existing connectors: ${connectorIds}.`);
|
|
373
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `The schema you are deploying is incompatible with the following existing connectors: ${clc.bold(connectorIds)}.`);
|
|
350
374
|
(0, utils_1.logLabeledWarning)("dataconnect", `This is a ${clc.red("breaking")} change and may break existing apps.`);
|
|
351
375
|
}
|
|
352
|
-
async function ensureServiceIsConnectedToCloudSql(serviceName,
|
|
376
|
+
async function ensureServiceIsConnectedToCloudSql(serviceName, instanceName, databaseId, linkIfNotConnected) {
|
|
353
377
|
let currentSchema = await (0, client_1.getSchema)(serviceName);
|
|
354
|
-
|
|
378
|
+
let postgresql = currentSchema?.datasources?.find((d) => d.postgresql)?.postgresql;
|
|
379
|
+
if (currentSchema?.reconciling &&
|
|
380
|
+
postgresql?.ephemeral &&
|
|
381
|
+
postgresql?.cloudSql?.instance &&
|
|
382
|
+
postgresql?.schemaValidation === "NONE") {
|
|
383
|
+
const [, , , , , serviceId] = serviceName.split("/");
|
|
384
|
+
const [, projectId, , , , instanceId] = postgresql.cloudSql.instance.split("/");
|
|
385
|
+
throw new error_1.FirebaseError(`While checking the service ${serviceId}, ` + (0, provisionCloudSql_1.cloudSQLBeingCreated)(projectId, instanceId));
|
|
386
|
+
}
|
|
387
|
+
if (!currentSchema || !postgresql) {
|
|
355
388
|
if (!linkIfNotConnected) {
|
|
356
389
|
(0, utils_1.logLabeledWarning)("dataconnect", `Not yet linked to the Cloud SQL instance.`);
|
|
357
390
|
return;
|
|
358
391
|
}
|
|
359
|
-
(0, utils_1.logLabeledBullet)("dataconnect", `
|
|
392
|
+
(0, utils_1.logLabeledBullet)("dataconnect", `Linking the Cloud SQL instance...`);
|
|
360
393
|
currentSchema = {
|
|
361
394
|
name: `${serviceName}/schemas/${types_1.SCHEMA_ID}`,
|
|
362
395
|
source: {
|
|
@@ -364,84 +397,95 @@ async function ensureServiceIsConnectedToCloudSql(serviceName, instanceId, datab
|
|
|
364
397
|
},
|
|
365
398
|
datasources: [
|
|
366
399
|
{
|
|
367
|
-
postgresql: {
|
|
368
|
-
database: databaseId,
|
|
369
|
-
schemaValidation: "NONE",
|
|
370
|
-
cloudSql: {
|
|
371
|
-
instance: instanceId,
|
|
372
|
-
},
|
|
373
|
-
},
|
|
400
|
+
postgresql: { ephemeral: true },
|
|
374
401
|
},
|
|
375
402
|
],
|
|
376
403
|
};
|
|
377
404
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
405
|
+
if (!postgresql) {
|
|
406
|
+
postgresql = currentSchema.datasources[0].postgresql;
|
|
407
|
+
}
|
|
408
|
+
let alreadyConnected = !postgresql.ephemeral || false;
|
|
409
|
+
if (postgresql.cloudSql?.instance && postgresql.cloudSql.instance !== instanceName) {
|
|
410
|
+
alreadyConnected = false;
|
|
411
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `Switching connected Cloud SQL instance\n From ${postgresql.cloudSql.instance}\n To ${instanceName}`);
|
|
382
412
|
}
|
|
383
|
-
if (postgresql
|
|
384
|
-
|
|
413
|
+
if (postgresql.database && postgresql.database !== databaseId) {
|
|
414
|
+
alreadyConnected = false;
|
|
415
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `Switching connected Postgres database from ${postgresql.database} to ${databaseId}`);
|
|
385
416
|
}
|
|
386
|
-
if (
|
|
417
|
+
if (alreadyConnected) {
|
|
387
418
|
return;
|
|
388
419
|
}
|
|
389
|
-
postgresql.schemaValidation = "STRICT";
|
|
390
420
|
try {
|
|
421
|
+
postgresql.schemaValidation = "STRICT";
|
|
422
|
+
postgresql.database = databaseId;
|
|
423
|
+
postgresql.cloudSql = { instance: instanceName };
|
|
391
424
|
await (0, client_1.upsertSchema)(currentSchema, false);
|
|
392
425
|
}
|
|
393
426
|
catch (err) {
|
|
394
427
|
if (err?.status >= 500) {
|
|
395
428
|
throw err;
|
|
396
429
|
}
|
|
397
|
-
logger_1.logger.debug(err);
|
|
430
|
+
logger_1.logger.debug(`Failed to ensure service is connected to Cloud SQL: ${err.message}`);
|
|
398
431
|
}
|
|
399
432
|
}
|
|
400
433
|
exports.ensureServiceIsConnectedToCloudSql = ensureServiceIsConnectedToCloudSql;
|
|
401
|
-
function
|
|
434
|
+
function displayStartSchemaDiff(validationMode) {
|
|
435
|
+
switch (validationMode) {
|
|
436
|
+
case "COMPATIBLE":
|
|
437
|
+
(0, utils_1.logLabeledBullet)("dataconnect", `Generating SQL schema migrations to be compatible...`);
|
|
438
|
+
break;
|
|
439
|
+
case "STRICT":
|
|
440
|
+
(0, utils_1.logLabeledBullet)("dataconnect", `Generating SQL schema migrations to match exactly...`);
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
function displayNoSchemaDiff(instanceId, databaseId, validationMode) {
|
|
445
|
+
switch (validationMode) {
|
|
446
|
+
case "COMPATIBLE":
|
|
447
|
+
(0, utils_1.logLabeledSuccess)("dataconnect", `Database schema of ${instanceId}:${databaseId} is compatible with Data Connect Schema.`);
|
|
448
|
+
break;
|
|
449
|
+
case "STRICT":
|
|
450
|
+
(0, utils_1.logLabeledSuccess)("dataconnect", `Database schema of ${instanceId}:${databaseId} matches Data Connect Schema exactly.`);
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function displaySchemaChanges(error, validationMode) {
|
|
402
455
|
switch (error.violationType) {
|
|
403
456
|
case "INCOMPATIBLE_SCHEMA":
|
|
404
457
|
{
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
message =
|
|
428
|
-
"Your PostgreSQL database " +
|
|
429
|
-
databaseId +
|
|
430
|
-
" in your CloudSQL instance " +
|
|
431
|
-
instanceName +
|
|
432
|
-
" must be migrated in order to match your application schema. " +
|
|
433
|
-
"The following SQL statements will migrate your database schema to match your new Data Connect schema.\n" +
|
|
434
|
-
error.diffs.map(toString).join("\n");
|
|
458
|
+
switch (validationMode) {
|
|
459
|
+
case "COMPATIBLE":
|
|
460
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `PostgreSQL schema is incompatible with the Data Connect Schema.
|
|
461
|
+
Those SQL statements will migrate it to be compatible:
|
|
462
|
+
|
|
463
|
+
${diffsToString(error.diffs)}
|
|
464
|
+
`);
|
|
465
|
+
break;
|
|
466
|
+
case "STRICT_AFTER_COMPATIBLE":
|
|
467
|
+
(0, utils_1.logLabeledBullet)("dataconnect", `PostgreSQL schema contains unused SQL objects not part of the Data Connect Schema.
|
|
468
|
+
Those SQL statements will migrate it to match exactly:
|
|
469
|
+
|
|
470
|
+
${diffsToString(error.diffs)}
|
|
471
|
+
`);
|
|
472
|
+
break;
|
|
473
|
+
case "STRICT":
|
|
474
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `PostgreSQL schema does not match the Data Connect Schema.
|
|
475
|
+
Those SQL statements will migrate it to match exactly:
|
|
476
|
+
|
|
477
|
+
${diffsToString(error.diffs)}
|
|
478
|
+
`);
|
|
479
|
+
break;
|
|
435
480
|
}
|
|
436
|
-
(0, utils_1.logLabeledWarning)("dataconnect", message);
|
|
437
481
|
}
|
|
438
482
|
break;
|
|
439
483
|
case "INACCESSIBLE_SCHEMA":
|
|
440
484
|
{
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
485
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `Cannot access CloudSQL database to validate schema.
|
|
486
|
+
Here is the complete expected SQL schema:
|
|
487
|
+
${diffsToString(error.diffs)}
|
|
488
|
+
`);
|
|
445
489
|
(0, utils_1.logLabeledWarning)("dataconnect", "Some SQL resources may already exist.");
|
|
446
490
|
}
|
|
447
491
|
break;
|
|
@@ -449,6 +493,12 @@ function displaySchemaChanges(error, validationMode, instanceName, databaseId) {
|
|
|
449
493
|
throw new error_1.FirebaseError(`Unknown schema violation type: ${error.violationType}, IncompatibleSqlSchemaError: ${error}`);
|
|
450
494
|
}
|
|
451
495
|
}
|
|
452
|
-
function
|
|
496
|
+
function requireSuperUser(diff) {
|
|
497
|
+
return diff.sql.startsWith("CREATE EXTENSION") || diff.sql.startsWith("CREATE SCHEMA");
|
|
498
|
+
}
|
|
499
|
+
function diffsToString(diffs) {
|
|
500
|
+
return diffs.map(diffToString).join("\n\n");
|
|
501
|
+
}
|
|
502
|
+
function diffToString(diff) {
|
|
453
503
|
return `\/** ${diff.destructive ? clc.red("Destructive: ") : ""}${diff.description}*\/\n${(0, sql_formatter_1.format)(diff.sql, { language: "postgresql" })}`;
|
|
454
504
|
}
|
|
@@ -33,12 +33,12 @@ async function default_1(context, options) {
|
|
|
33
33
|
utils.logLabeledSuccess("dataconnect", `Created service ${s.serviceName}`);
|
|
34
34
|
}));
|
|
35
35
|
if (servicesToDelete.length) {
|
|
36
|
+
const serviceToDeleteList = servicesToDelete.map((s) => " - " + s.name).join("\n");
|
|
36
37
|
if (await (0, prompt_1.confirm)({
|
|
37
|
-
force:
|
|
38
|
+
force: false,
|
|
38
39
|
nonInteractive: options.nonInteractive,
|
|
39
|
-
message: `The following services exist on ${projectId} but are not listed in your 'firebase.json'\n${
|
|
40
|
-
|
|
41
|
-
.join("\n")}\nWould you like to delete these services?`,
|
|
40
|
+
message: `The following services exist on ${projectId} but are not listed in your 'firebase.json'\n${serviceToDeleteList}\nWould you like to delete these services?`,
|
|
41
|
+
default: false,
|
|
42
42
|
})) {
|
|
43
43
|
await Promise.all(servicesToDelete.map(async (s) => {
|
|
44
44
|
await client.deleteService(s.name);
|
|
@@ -54,19 +54,17 @@ async function default_1(context, options) {
|
|
|
54
54
|
.map(async (s) => {
|
|
55
55
|
const postgresDatasource = s.schema.datasources.find((d) => d.postgresql);
|
|
56
56
|
if (postgresDatasource) {
|
|
57
|
-
const instanceId = postgresDatasource.postgresql?.cloudSql
|
|
57
|
+
const instanceId = postgresDatasource.postgresql?.cloudSql?.instance.split("/").pop();
|
|
58
58
|
const databaseId = postgresDatasource.postgresql?.database;
|
|
59
59
|
if (!instanceId || !databaseId) {
|
|
60
60
|
return Promise.resolve();
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
return (0, provisionCloudSql_1.provisionCloudSql)({
|
|
62
|
+
return (0, provisionCloudSql_1.setupCloudSql)({
|
|
64
63
|
projectId,
|
|
65
64
|
location: (0, names_1.parseServiceName)(s.serviceName).location,
|
|
66
65
|
instanceId,
|
|
67
66
|
databaseId,
|
|
68
|
-
|
|
69
|
-
waitForCreation: true,
|
|
67
|
+
requireGoogleMlIntegration: (0, types_1.requiresVector)(s.deploymentMetadata),
|
|
70
68
|
});
|
|
71
69
|
}
|
|
72
70
|
}));
|