Skip to content

Commit

Permalink
More forgiving config for empty db schema (bluesky-social#871)
Browse files Browse the repository at this point in the history
* Add more config for pds db pool

* More forgiving handling of empty db schema config
  • Loading branch information
devinivy authored Apr 22, 2023
1 parent 308adc2 commit a52fb22
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/bsky/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/bsky/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion packages/pds/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions packages/pds/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit a52fb22

Please sign in to comment.