{"record":{"id":"91f2cbc791ec3485","repo":"remix-run/remix","slug":"postgres-database-method-requires-config-b","errorCode":null,"errorMessage":"Postgres database  + method + () requires config-based construction","messagePattern":"Postgres database  \\+ method \\+ \\(\\) requires config-based construction","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/data-table-postgres/src/lib/driver.ts","lineNumber":438,"sourceCode":"      }\n    } finally {\n      releaseQueue()\n    }\n  }\n\n  async #closePool(): Promise<void> {\n    this.#transactions.clear()\n    // pg pools reject end() when called twice, so ending must be tracked to\n    // keep close() idempotent.\n    if (isPostgresPool(this.#client) && !this.#poolClosed) {\n      this.#poolClosed = true\n      await this.#client.end()\n    }\n  }\n\n  #configOrThrow(method: string): PostgresPoolConfig {\n    if (!this.#config) {\n      throw new Error('Postgres database ' + method + '() requires config-based construction')\n    }\n\n    return this.#config\n  }\n\n  #assertNoOpenTransactions(method: string): void {\n    if (this.#transactions.size > 0) {\n      throw new Error('Postgres database cannot ' + method + ' while transactions are open')\n    }\n  }\n\n  #maintenanceConfig(targetDatabase: string): PostgresClientConfig {\n    let maintenanceDatabase = this.#maintenanceDatabase\n\n    if (maintenanceDatabase === targetDatabase) {\n      maintenanceDatabase = targetDatabase === 'postgres' ? 'template1' : 'postgres'\n    }\n","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/data-table-postgres/src/lib/driver.ts#L420-L456","documentation":"Some Postgres driver methods (those needing a database name from config, like maintenance/wipe operations) only work when the driver was constructed with a config object. If the driver was constructed from a pool or client instance instead, this internal config is absent and #configOrThrow throws.","triggerScenarios":"Creating PostgresDatabase from an existing pg Pool/client (dependency injection for tests) and then calling a config-requiring method such as wipe()/dropDatabase-related helpers named in the message.","commonSituations":"Test suites injecting a mock or shared pool, then calling wipe() between tests; reusing a connected client for convenience and later needing destructive/admin operations.","solutions":["Construct the driver with a PostgresPoolConfig object (location/database/credentials) for the operations that need it","Pass an explicit database name via config so the method can proceed","For tests, create a config-based driver against a disposable database instead of injecting a pool"],"exampleFix":"// before\nlet db = new PostgresDatabase({ pool: sharedPool })\nawait db.wipe() // throws\n\n// after\nlet db = new PostgresDatabase({ config: { host: 'localhost', database: 'test' } })\nawait db.wipe()","handlingStrategy":"validation","validationCode":"let needsConfig = !db.hasConfig // or track construction mode yourself\nif (needsConfig) throw new Error('Create a config-based driver before calling wipe')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct with a config when you'll need admin operations","Keep a config-based driver for destructive/test operations","Don't inject shared pools into drivers used for wipe/reset"],"tags":["postgres","driver","config","construction"],"backgroundTag":"driver-requires-config","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}