Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions src/dataconnect/schemaMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
import { Options } from "../options";
import { FirebaseError } from "../error";
import { logLabeledBullet, logLabeledWarning, logLabeledSuccess } from "../utils";
import * as experiments from "../experiments";
import * as errors from "./errors";

export async function diffSchema(

Check warning on line 29 in src/dataconnect/schemaMigration.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
schema: Schema,
schemaValidation?: SchemaValidation,
): Promise<Diff[]> {
Expand All @@ -41,13 +40,11 @@
let diffs: Diff[] = [];

// If the schema validation mode is unset, we surface both STRICT and COMPATIBLE mode diffs, starting with COMPATIBLE.
let validationMode: SchemaValidation = experiments.isEnabled("fdccompatiblemode")
? schemaValidation ?? "COMPATIBLE"
: "STRICT";
let validationMode: SchemaValidation = schemaValidation ?? "COMPATIBLE";
setSchemaValidationMode(schema, validationMode);

try {
if (!schemaValidation && experiments.isEnabled("fdccompatiblemode")) {
if (!schemaValidation) {
logLabeledBullet("dataconnect", `generating required schema changes...`);
}
await upsertSchema(schema, /** validateOnly=*/ true);
Expand All @@ -56,8 +53,8 @@
} else {
logLabeledSuccess("dataconnect", `Database schema is compatible.`);
}
} catch (err: any) {

Check warning on line 56 in src/dataconnect/schemaMigration.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err?.status !== 400) {

Check warning on line 57 in src/dataconnect/schemaMigration.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .status on an `any` value
throw err;
}
const invalidConnectors = errors.getInvalidConnectors(err);
Expand All @@ -78,15 +75,15 @@
}

// If the validation mode is unset, then we also surface any additional optional STRICT diffs.
if (experiments.isEnabled("fdccompatiblemode") && !schemaValidation) {
if (!schemaValidation) {
validationMode = "STRICT";
setSchemaValidationMode(schema, validationMode);
try {
logLabeledBullet("dataconnect", `generating schema changes, including optional changes...`);
await upsertSchema(schema, /** validateOnly=*/ true);
logLabeledSuccess("dataconnect", `no additional optional changes`);
} catch (err: any) {

Check warning on line 85 in src/dataconnect/schemaMigration.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err?.status !== 400) {

Check warning on line 86 in src/dataconnect/schemaMigration.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .status on an `any` value
throw err;
}
const incompatible = errors.getIncompatibleSchemaError(err);
Expand All @@ -108,7 +105,7 @@
return diffs;
}

export async function migrateSchema(args: {

Check warning on line 108 in src/dataconnect/schemaMigration.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
options: Options;
schema: Schema;
/** true for `dataconnect:sql:migrate`, false for `deploy` */
Expand All @@ -127,16 +124,14 @@
let diffs: Diff[] = [];

// If the schema validation mode is unset, we surface both STRICT and COMPATIBLE mode diffs, starting with COMPATIBLE.
let validationMode: SchemaValidation = experiments.isEnabled("fdccompatiblemode")
? schemaValidation ?? "COMPATIBLE"
: "STRICT";
let validationMode: SchemaValidation = schemaValidation ?? "COMPATIBLE";
setSchemaValidationMode(schema, validationMode);

try {
await upsertSchema(schema, validateOnly);
logger.debug(`Database schema was up to date for ${instanceId}:${databaseId}`);
} catch (err: any) {

Check warning on line 133 in src/dataconnect/schemaMigration.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err?.status !== 400) {

Check warning on line 134 in src/dataconnect/schemaMigration.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .status on an `any` value
throw err;
}
// Parse and handle failed precondition errors, then retry.
Expand Down Expand Up @@ -183,13 +178,13 @@
}

// If the validation mode is unset, then we also surface any additional optional STRICT diffs.
if (experiments.isEnabled("fdccompatiblemode") && !schemaValidation) {
if (!schemaValidation) {
validationMode = "STRICT";
setSchemaValidationMode(schema, validationMode);
try {
await upsertSchema(schema, validateOnly);
} catch (err: any) {

Check warning on line 186 in src/dataconnect/schemaMigration.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err.status !== 400) {

Check warning on line 187 in src/dataconnect/schemaMigration.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .status on an `any` value
throw err;
}
// Parse and handle failed precondition errors, then retry.
Expand Down Expand Up @@ -274,11 +269,9 @@
}

function setSchemaValidationMode(schema: Schema, schemaValidation: SchemaValidation) {
if (experiments.isEnabled("fdccompatiblemode")) {
const postgresDatasource = schema.datasources.find((d) => d.postgresql);
if (postgresDatasource?.postgresql) {
postgresDatasource.postgresql.schemaValidation = schemaValidation;
}
const postgresDatasource = schema.datasources.find((d) => d.postgresql);
if (postgresDatasource?.postgresql) {
postgresDatasource.postgresql.schemaValidation = schemaValidation;
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/experiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,6 @@ export const ALL_EXPERIMENTS = experiments({
default: true,
public: false,
},

fdccompatiblemode: {
shortDescription: "Enable Data Connect schema migrations in Compatible Mode",
fullDescription: "Enable Data Connect schema migrations in Compatible Mode",
default: true,
public: false,
},
});

export type ExperimentName = keyof typeof ALL_EXPERIMENTS;
Expand Down
8 changes: 1 addition & 7 deletions src/init/features/dataconnect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { provisionCloudSql } from "../../../dataconnect/provisionCloudSql";
import { checkFreeTrialInstanceUsed, upgradeInstructions } from "../../../dataconnect/freeTrial";
import * as cloudsql from "../../../gcp/cloudsql/cloudsqladmin";
import { ensureApis, ensureSparkApis } from "../../../dataconnect/ensureApis";
import * as experiments from "../../../experiments";
import {
listLocations,
listAllServices,
Expand All @@ -25,9 +24,6 @@ import * as sdk from "./sdk";
import { getPlatformFromFolder } from "../../../dataconnect/fileUtils";

const DATACONNECT_YAML_TEMPLATE = readTemplateSync("init/dataconnect/dataconnect.yaml");
const DATACONNECT_YAML_COMPAT_EXPERIMENT_TEMPLATE = readTemplateSync(
"init/dataconnect/dataconnect-fdccompatiblemode.yaml",
);
const CONNECTOR_YAML_TEMPLATE = readTemplateSync("init/dataconnect/connector.yaml");
const SCHEMA_TEMPLATE = readTemplateSync("init/dataconnect/schema.gql");
const QUERIES_TEMPLATE = readTemplateSync("init/dataconnect/queries.gql");
Expand Down Expand Up @@ -239,9 +235,7 @@ function subDataconnectYamlValues(replacementValues: {
connectorDirs: "__connectorDirs__",
locationId: "__location__",
};
let replaced = experiments.isEnabled("fdccompatiblemode")
? DATACONNECT_YAML_COMPAT_EXPERIMENT_TEMPLATE
: DATACONNECT_YAML_TEMPLATE;
let replaced = DATACONNECT_YAML_TEMPLATE;
for (const [k, v] of Object.entries(replacementValues)) {
replaced = replaced.replace(replacements[k], JSON.stringify(v));
}
Expand Down
12 changes: 0 additions & 12 deletions templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml

This file was deleted.

1 change: 1 addition & 0 deletions templates/init/dataconnect/dataconnect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ schema:
database: __cloudSqlDatabase__
cloudSql:
instanceId: __cloudSqlInstanceId__
# schemaValidation: "COMPATIBLE"
connectorDirs: __connectorDirs__
Loading