From a52fb222122f77c6b21128bf6cb7d4c00900806b Mon Sep 17 00:00:00 2001 From: devin ivy Date: Sat, 22 Apr 2023 14:26:31 -0400 Subject: [PATCH] More forgiving config for empty db schema (#871) * Add more config for pds db pool * More forgiving handling of empty db schema config --- packages/bsky/service/index.js | 2 +- packages/bsky/src/db/index.ts | 6 +++--- packages/pds/service/index.js | 2 +- packages/pds/src/db/index.ts | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/bsky/service/index.js b/packages/bsky/service/index.js index b773f500d6c..5c4edff03aa 100644 --- a/packages/bsky/service/index.js +++ b/packages/bsky/service/index.js @@ -55,7 +55,7 @@ const getEnv = () => ({ dbPostgresUrl: process.env.DB_POSTGRES_URL, dbMigratePostgresUrl: process.env.DB_MIGRATE_POSTGRES_URL || process.env.DB_POSTGRES_URL, - dbPostgresSchema: process.env.DB_POSTGRES_SCHEMA, + dbPostgresSchema: process.env.DB_POSTGRES_SCHEMA || undefined, publicUrl: process.env.PUBLIC_URL, didPlcUrl: process.env.DID_PLC_URL, imgUriSalt: process.env.IMG_URI_SALT, diff --git a/packages/bsky/src/db/index.ts b/packages/bsky/src/db/index.ts index 261fc3e0d6b..be00e2f645b 100644 --- a/packages/bsky/src/db/index.ts +++ b/packages/bsky/src/db/index.ts @@ -25,7 +25,7 @@ export class Database { pgTypes.setTypeParser(pgTypes.builtins.INT8, (n) => parseInt(n, 10)) // Setup schema usage, primarily for test parallelism (each test suite runs in its own pg schema) - if (schema !== undefined) { + if (schema) { if (!/^[a-z_]+$/i.test(schema)) { throw new Error( `Postgres schema must only contain [A-Za-z_]: ${schema}`, @@ -72,7 +72,7 @@ export class Database { } async migrateToOrThrow(migration: string) { - if (this.schema !== undefined) { + if (this.schema) { await this.db.schema.createSchema(this.schema).ifNotExists().execute() } const { error, results } = await this.migrator.migrateTo(migration) @@ -86,7 +86,7 @@ export class Database { } async migrateToLatestOrThrow() { - if (this.schema !== undefined) { + if (this.schema) { await this.db.schema.createSchema(this.schema).ifNotExists().execute() } const { error, results } = await this.migrator.migrateToLatest() diff --git a/packages/pds/service/index.js b/packages/pds/service/index.js index 50be4ffb3a2..ac0f4a891e2 100644 --- a/packages/pds/service/index.js +++ b/packages/pds/service/index.js @@ -100,7 +100,7 @@ const getEnv = () => ({ recoveryKeyId: process.env.RECOVERY_KEY_ID, dbCreds: JSON.parse(process.env.DB_CREDS_JSON), dbMigrateCreds: JSON.parse(process.env.DB_MIGRATE_CREDS_JSON), - dbSchema: process.env.DB_SCHEMA, + dbSchema: process.env.DB_SCHEMA || undefined, dbPoolSize: maybeParseInt(process.env.DB_POOL_SIZE), dbPoolMaxUses: maybeParseInt(process.env.DB_POOL_MAX_USES), dbPoolIdleTimeoutMs: maybeParseInt(process.env.DB_POOL_IDLE_TIMEOUT_MS), diff --git a/packages/pds/src/db/index.ts b/packages/pds/src/db/index.ts index 1a40a5fa356..213c20ca5fd 100644 --- a/packages/pds/src/db/index.ts +++ b/packages/pds/src/db/index.ts @@ -58,7 +58,7 @@ export class Database { pgTypes.setTypeParser(pgTypes.builtins.INT8, (n) => parseInt(n, 10)) // Setup schema usage, primarily for test parallelism (each test suite runs in its own pg schema) - if (schema !== undefined) { + if (schema) { if (!/^[a-z_]+$/i.test(schema)) { throw new Error( `Postgres schema must only contain [A-Za-z_]: ${schema}`, @@ -201,7 +201,7 @@ export class Database { } async migrateToOrThrow(migration: string) { - if (this.schema !== undefined) { + if (this.schema) { await this.db.schema.createSchema(this.schema).ifNotExists().execute() } const { error, results } = await this.migrator.migrateTo(migration) @@ -215,7 +215,7 @@ export class Database { } async migrateToLatestOrThrow() { - if (this.schema !== undefined) { + if (this.schema) { await this.db.schema.createSchema(this.schema).ifNotExists().execute() } const { error, results } = await this.migrator.migrateToLatest()