{"record":{"id":"ea3c62cbfb896add","repo":"cube-js/cube","slug":"the-keybydatasource-cubejs-database-datasourc","errorCode":null,"errorMessage":"The ${keyByDataSource('CUBEJS_DATABASE', dataSource)} is required and missing.","messagePattern":"The (.+?) is required and missing\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-shared/src/env.ts","lineNumber":640,"sourceCode":"  dbDatabase: ({\n    required,\n    dataSource,\n    preAggregations,\n  }: {\n    dataSource: string,\n    required?: boolean,\n    preAggregations?: boolean,\n  }) => {\n    console.warn(\n      `The ${\n        keyByDataSource('CUBEJS_DATABASE', dataSource)\n      } is deprecated. Please, use the ${\n        keyByDataSource('CUBEJS_DB_NAME', dataSource)\n      } instead.`\n    );\n    const val = get(keyByDataSource('CUBEJS_DATABASE', dataSource, preAggregations)).asString();\n    if (required && !val) {\n      throw new Error(\n        `The ${\n          keyByDataSource('CUBEJS_DATABASE', dataSource)\n        } is required and missing.`\n      );\n    }\n    return val;\n  },\n\n  /**\n   * Database max pool size.\n   */\n  dbMaxPoolSize: ({\n    dataSource,\n    preAggregations,\n  }: DataSourceOpts) => (\n    get(keyByDataSource('CUBEJS_DB_MAX_POOL', dataSource, preAggregations)).asInt()\n  ),\n","sourceCodeStart":622,"sourceCodeEnd":658,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-shared/src/env.ts#L622-L658","documentation":"cubejsDatabase reads CUBEJS_DATABASE (per data source) and throws when required: true is passed and the variable is unset or empty. CUBEJS_DATABASE is deprecated in favor of CUBEJS_DB_NAME, so this error typically appears with legacy database configuration.","triggerScenarios":"Calling the database accessor with required: true while neither CUBEJS_DATABASE nor CUBEJS_DS_<DATASOURCE>_DATABASE is set in the environment.","commonSituations":"Old BigQuery/Postgres setups using CUBEJS_DATABASE before the rename to CUBEJS_DB_NAME; partial env migrations where some data sources got new names and others didn't; forgotten DS-prefixed override.","solutions":["Set CUBEJS_DB_NAME (or CUBEJS_DS_<DATASOURCE>_DB_NAME) — the modern replacement for CUBEJS_DATABASE.","Alternatively set the legacy CUBEJS_DATABASE (or CUBEJS_DS_<DATASOURCE>_DATABASE) variable.","Audit all dataSource values in cube.js config to ensure each has a matching env prefix.","Remove required: true if the caller resolves the database through other means."],"exampleFix":"// before\nCUBEJS_DATABASE=my_db   # deprecated\n// after\nCUBEJS_DB_NAME=my_db","handlingStrategy":"try-catch","validationCode":"const dsKey = `CUBEJS_DS_${dataSource.toUpperCase()}_DATABASE`;\nif (!process.env[dsKey] && !process.env.CUBEJS_DATABASE && !process.env.CUBEJS_DB_NAME)\n  throw new Error(`Set CUBEJS_DB_NAME for data source ${dataSource}`);","typeGuard":null,"tryCatchPattern":"try {\n  const database = getEnv('database', { dataSource, required: true });\n} catch (e) {\n  if (String(e.message).includes('CUBEJS_DATABASE') && e.message.includes('required and missing')) {\n    console.error('Set CUBEJS_DB_NAME (modern replacement for CUBEJS_DATABASE)');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Replace CUBEJS_DATABASE with CUBEJS_DB_NAME across all environments.","Keep an env-var inventory per data source and validate at boot.","Grep CI/CD configs for legacy CUBEJS_DATABASE usages after each Cube upgrade."],"tags":["configuration","environment-variables","deprecated","missing-var"],"backgroundTag":"missing-env-var","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}