Skip to content

Commit

Permalink
Merge branch 'fz/pool' into fz/migrate-force
Browse files Browse the repository at this point in the history
  • Loading branch information
fredzqm committed May 21, 2024
2 parents ba6f445 + 391686b commit 7d82217
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/gcp/cloudsql/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function execute(
);
}
let connector: Connector;
let client: pg.Client;
let pool: pg.Pool;
switch (user.type) {
case "CLOUD_IAM_USER": {
connector = new Connector({
Expand All @@ -43,7 +43,7 @@ export async function execute(
ipType: IpAddressTypes.PUBLIC,
authType: AuthTypes.IAM,
});
client = new pg.Client({
pool = new pg.Pool({
...clientOpts,
user: opts.username,
database: opts.databaseId,
Expand All @@ -60,7 +60,7 @@ export async function execute(
ipType: IpAddressTypes.PUBLIC,
authType: AuthTypes.IAM,
});
client = new pg.Client({
pool = new pg.Pool({
...clientOpts,
user: opts.username,
database: opts.databaseId,
Expand All @@ -79,7 +79,7 @@ export async function execute(
instanceConnectionName: connectionName,
ipType: IpAddressTypes.PUBLIC,
});
client = new pg.Client({
pool = new pg.Pool({
...clientOpts,
user: opts.username,
password: opts.password,
Expand All @@ -89,17 +89,19 @@ export async function execute(
}
}

const conn = await pool.connect();
logFn(`Logged in as ${opts.username}`);
for (const s of sqlStatements) {
logFn(`Executing: '${s}'`);
try {
await client.query(s);
await conn.query(s);
} catch (err) {
throw new FirebaseError(`Error executing ${err}`);
}
}

await client.end();
conn.release();
await pool.end();
connector.close();
}

Expand Down

0 comments on commit 7d82217

Please sign in to comment.