Skip to content

Commit b6a5bf0

Browse files
committed
Merge branch 'rosalyntan.webhook' into rosalyntan.download
2 parents bbb977b + 799a1c3 commit b6a5bf0

File tree

9 files changed

+61
-46
lines changed

9 files changed

+61
-46
lines changed

src/commands/dataconnect-services-list.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { logger } from "../logger";
77
import { requirePermissions } from "../requirePermissions";
88
import { ensureApis } from "../dataconnect/ensureApis";
99
import * as Table from "cli-table3";
10-
import { MAIN_SCHEMA_ID } from "../dataconnect/types";
1110

1211
// TODO: Update this command to also list secondary schema information.
1312
export const command = new Command("dataconnect:services:list")
@@ -34,7 +33,7 @@ export const command = new Command("dataconnect:services:list")
3433
});
3534
const jsonOutput: { services: Record<string, any>[] } = { services: [] };
3635
for (const service of services) {
37-
const schema = (await client.getSchema(service.name, MAIN_SCHEMA_ID)) ?? {
36+
const schema = (await client.getSchema(service.name)) ?? {
3837
name: "",
3938
datasources: [{}],
4039
source: { files: [] },

src/config.spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from "path";
22
import * as fs from "fs";
3+
import * as os from "os";
34

45
import { expect } from "chai";
56

@@ -78,17 +79,26 @@ describe("Config", () => {
7879
});
7980

8081
describe("functions.source", () => {
82+
let tmpDir: string;
83+
84+
beforeEach(() => {
85+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test"));
86+
});
87+
88+
afterEach(() => {
89+
if (tmpDir) {
90+
fs.rmSync(tmpDir, { recursive: true, force: true });
91+
}
92+
});
93+
8194
it("injects default source when default dir exists but source is missing", () => {
82-
const tmpDir = fs.mkdtempSync("firebase-test");
8395
fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE));
8496

8597
const cfg = new Config({ functions: {} }, { cwd: tmpDir, projectDir: tmpDir });
8698
expect(cfg.get("functions.source")).to.be.equal("functions");
8799
});
88100

89101
it("does not injects default source when default dir is missing", () => {
90-
const tmpDir = fs.mkdtempSync("firebase-test");
91-
92102
const cfg = new Config(
93103
{ functions: { runtime: "nodejs20" } },
94104
{ cwd: tmpDir, projectDir: tmpDir },
@@ -97,7 +107,6 @@ describe("Config", () => {
97107
});
98108

99109
it("does not inject source for remoteSource", () => {
100-
const tmpDir = fs.mkdtempSync("firebase-test");
101110
fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE));
102111

103112
const cfg = new Config(
@@ -113,7 +122,6 @@ describe("Config", () => {
113122
});
114123

115124
it("injects into the first empty entry only when default dir exists", () => {
116-
const tmpDir = fs.mkdtempSync("firebase-test");
117125
fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE));
118126

119127
const cfg = new Config(
@@ -136,7 +144,6 @@ describe("Config", () => {
136144
});
137145

138146
it("injects only one entry when multiple are empty", () => {
139-
const tmpDir = fs.mkdtempSync("firebase-test");
140147
fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE));
141148

142149
const cfg = new Config(
@@ -152,7 +159,6 @@ describe("Config", () => {
152159
});
153160

154161
it("does not inject when no entry is empty", () => {
155-
const tmpDir = fs.mkdtempSync("firebase-test");
156162
fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE));
157163

158164
const cfg = new Config(
@@ -173,8 +179,6 @@ describe("Config", () => {
173179
});
174180

175181
it("does not inject for arrays when default dir is missing", () => {
176-
const tmpDir = fs.mkdtempSync("firebase-test");
177-
178182
const cfg = new Config(
179183
{
180184
functions: [{}, { source: "something" }],

src/dataconnect/client.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,21 @@ describe("client", () => {
119119
describe("Schema methods", () => {
120120
it("getSchema", async () => {
121121
getStub.resolves({ body: { name: "schema" } });
122-
const schema = await client.getSchema("projects/p/locations/l/services/s", "main");
122+
const schema = await client.getSchema("projects/p/locations/l/services/s");
123123
expect(schema).to.deep.equal({ name: "schema" });
124124
expect(getStub).to.be.calledWith("projects/p/locations/l/services/s/schemas/main");
125125
});
126126

127+
it("getSchema with schemaId", async () => {
128+
getStub.resolves({ body: { name: "schema" } });
129+
const schema = await client.getSchema("projects/p/locations/l/services/s", "schemaId");
130+
expect(schema).to.deep.equal({ name: "schema" });
131+
expect(getStub).to.be.calledWith("projects/p/locations/l/services/s/schemas/schemaId");
132+
});
133+
127134
it("getSchema returns undefined if not found", async () => {
128135
getStub.rejects(new FirebaseError("err", { status: 404 }));
129-
const schema = await client.getSchema("projects/p/locations/l/services/s", "main");
136+
const schema = await client.getSchema("projects/p/locations/l/services/s");
130137
expect(schema).to.be.undefined;
131138
});
132139

src/dataconnect/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export async function deleteService(serviceName: string): Promise<types.Service>
8585

8686
export async function getSchema(
8787
serviceName: string,
88-
schemaId: string,
88+
schemaId: string = types.MAIN_SCHEMA_ID,
8989
): Promise<types.Schema | undefined> {
9090
try {
9191
const res = await dataconnectClient().get<types.Schema>(`${serviceName}/schemas/${schemaId}`);

src/dataconnect/schemaMigration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ export async function ensureServiceIsConnectedToCloudSql(
599599
databaseId: string,
600600
linkIfNotConnected: boolean,
601601
): Promise<void> {
602-
let currentSchema = await getSchema(serviceName, MAIN_SCHEMA_ID);
602+
let currentSchema = await getSchema(serviceName);
603603
let postgresql = currentSchema?.datasources?.find((d) => d.postgresql)?.postgresql;
604604
if (
605605
currentSchema?.reconciling && // active LRO

src/deploy/dataconnect/deploy.spec.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ describe("dataconnect deploy", () => {
4444
{
4545
serviceName: "projects/test-project/locations/l/services/s1",
4646
deploymentMetadata: {},
47-
schema: {
48-
name: "projects/test-project/locations/l/services/s1/schemas/main",
49-
datasources: [],
50-
},
47+
schemas: [
48+
{
49+
name: "projects/test-project/locations/l/services/s1/schemas/main",
50+
datasources: [],
51+
},
52+
],
5153
dataConnectYaml: { serviceId: "s1" },
5254
},
5355
];
@@ -106,17 +108,19 @@ describe("dataconnect deploy", () => {
106108
const serviceInfos = [
107109
{
108110
serviceName: "projects/test-project/locations/l/services/s1",
109-
schema: {
110-
name: "projects/test-project/locations/l/services/s1/schemas/main",
111-
datasources: [
112-
{
113-
postgresql: {
114-
cloudSql: { instance: "projects/p/locations/l/instances/i" },
115-
database: "db",
111+
schemas: [
112+
{
113+
name: "projects/test-project/locations/l/services/s1/schemas/main",
114+
datasources: [
115+
{
116+
postgresql: {
117+
cloudSql: { instance: "projects/p/locations/l/instances/i" },
118+
database: "db",
119+
},
116120
},
117-
},
118-
],
119-
},
121+
],
122+
},
123+
],
120124
deploymentMetadata: {},
121125
dataConnectYaml: { serviceId: "s1" },
122126
},

src/deploy/dataconnect/prepare.spec.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,19 @@ describe("dataconnect prepare", () => {
104104
it("should diff schema and setup cloud sql", async () => {
105105
const serviceInfos = [
106106
{
107-
schema: {
108-
name: "projects/p/locations/l/services/s/schemas/main",
109-
datasources: [
110-
{
111-
postgresql: {
112-
cloudSql: { instance: "projects/p/locations/l/instances/i" },
113-
database: "db",
107+
schemas: [
108+
{
109+
name: "projects/p/locations/l/services/s/schemas/main",
110+
datasources: [
111+
{
112+
postgresql: {
113+
cloudSql: { instance: "projects/p/locations/l/instances/i" },
114+
database: "db",
115+
},
114116
},
115-
},
116-
],
117-
},
117+
],
118+
},
119+
],
118120
serviceName: "projects/p/locations/l/services/s",
119121
deploymentMetadata: {},
120122
dataConnectYaml: {

src/deploy/dataconnect/release.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("dataconnect release", () => {
5050
serviceId: "s1",
5151
schema: { datasource: { postgresql: { schemaValidation: "STRICT" } } },
5252
},
53-
schema: { name: "projects/p/locations/l/services/s1/schemas/main" },
53+
schemas: [{ name: "projects/p/locations/l/services/s1/schemas/main" }],
5454
connectorInfo: [
5555
{
5656
connector: { name: "projects/p/locations/l/services/s1/connectors/c1" },
@@ -88,7 +88,7 @@ describe("dataconnect release", () => {
8888
serviceId: "s1",
8989
schema: { datasource: { postgresql: { schemaValidation: "STRICT" } } },
9090
},
91-
schema: { name: "projects/p/locations/l/services/s1/schemas/main" },
91+
schemas: [{ name: "projects/p/locations/l/services/s1/schemas/main" }],
9292
connectorInfo: [
9393
{
9494
connector: { name: "projects/p/locations/l/services/s1/connectors/c1" },
@@ -124,7 +124,7 @@ describe("dataconnect release", () => {
124124
serviceId: "s1",
125125
schema: { datasource: { postgresql: { schemaValidation: "STRICT" } } },
126126
},
127-
schema: { name: "projects/p/locations/l/services/s1/schemas/main" },
127+
schemas: [{ name: "projects/p/locations/l/services/s1/schemas/main" }],
128128
connectorInfo: [
129129
{
130130
connector: { name: "projects/p/locations/l/services/s1/connectors/c1" },
@@ -163,7 +163,7 @@ describe("dataconnect release", () => {
163163
serviceId: "s1",
164164
schema: { datasource: { postgresql: { schemaValidation: "STRICT" } } },
165165
},
166-
schema: { name: "projects/p/locations/l/services/s1/schemas/main" },
166+
schemas: [{ name: "projects/p/locations/l/services/s1/schemas/main" }],
167167
connectorInfo: [
168168
{
169169
connector: { name: "projects/p/locations/l/services/s1/connectors/c1" },

src/init/features/dataconnect/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,8 @@ async function downloadService(info: RequiredInfo, serviceName: string): Promise
535535
try {
536536
schemas = await listSchemas(serviceName, [
537537
"schemas.name",
538-
"schemas.datasources.postgresql.database",
539-
"schemas.datasources.postgresql.cloudSql.instance",
540-
"schemas.source.files",
538+
"schemas.datasources",
539+
"schemas.source",
541540
]);
542541
} catch (err: any) {
543542
if (err.status !== 404) {

0 commit comments

Comments
 (0)