Skip to content

Commit bfaaa52

Browse files
docs: document database.name setting and database_prefix deprecation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c034302 commit bfaaa52

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/how-to/configure-database.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Environment variables take precedence over config files.
6666
| `database.user` | `DJ_USER` || Database username |
6767
| `database.password` | `DJ_PASS` || Database password |
6868
| `database.backend` | `DJ_BACKEND` | `mysql` | Database backend: `mysql` or `postgresql` |
69+
| `database.name` | `DJ_DATABASE_NAME` | `None` | Database name (PostgreSQL only). Defaults to `"postgres"` |
6970
| `database.use_tls` | `DJ_TLS` | `True` | Use TLS encryption |
7071
| `database.reconnect` || `True` | Auto-reconnect on timeout |
7172
| `safemode` || `True` | Prompt before destructive operations |
@@ -145,13 +146,45 @@ DataJoint supports both MySQL and PostgreSQL backends. To use PostgreSQL:
145146

146147
The port defaults to `5432` when `backend` is set to `postgresql`.
147148

149+
### Database Name
150+
151+
!!! version-added "New in 2.2.1"
152+
The `database.name` setting specifies which PostgreSQL database to connect to.
153+
154+
PostgreSQL requires connecting to a specific database. By default, DataJoint connects to the `postgres` database. To use a different database:
155+
156+
```json
157+
{
158+
"database": {
159+
"host": "localhost",
160+
"backend": "postgresql",
161+
"name": "my_database"
162+
}
163+
}
164+
```
165+
166+
Or via environment variable:
167+
168+
```bash
169+
export DJ_DATABASE_NAME=my_database
170+
```
171+
172+
Or programmatically:
173+
174+
```python
175+
dj.config['database.name'] = 'my_database'
176+
```
177+
178+
This setting only applies to PostgreSQL. Setting it with the MySQL backend emits a warning.
179+
148180
### Environment Variable
149181

150182
```bash
151183
export DJ_BACKEND=postgresql
152184
export DJ_HOST=localhost
153185
export DJ_USER=postgres
154186
export DJ_PASS=password
187+
export DJ_DATABASE_NAME=my_database # optional, defaults to "postgres"
155188
```
156189

157190
### Programmatic Configuration
@@ -161,6 +194,7 @@ import datajoint as dj
161194

162195
dj.config['database.backend'] = 'postgresql'
163196
dj.config['database.host'] = 'localhost'
197+
dj.config['database.name'] = 'my_database' # optional
164198
```
165199

166200
### Docker Compose for Local Development

src/how-to/deploy-production.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ When multiple projects share a database server, use prefixes to avoid naming col
9696

9797
### Configure Database Prefix
9898

99+
!!! version-deprecated "Deprecated in 2.2.1"
100+
`database_prefix` is deprecated. For PostgreSQL, use `database.name` to select a database instead. `database_prefix` will be removed in 2.3.
101+
99102
```python
100103
import datajoint as dj
101104

src/reference/configuration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ Configuration is loaded in priority order:
2222
| `database.port` | `DJ_PORT` | `3306`/`5432` | Database server port (auto-detects from backend) |
2323
| `database.user` | `DJ_USER` || Database username (required) |
2424
| `database.password` | `DJ_PASS` || Database password (required) |
25+
| `database.name` | `DJ_DATABASE_NAME` | `None` | Database name for PostgreSQL connections. Defaults to `"postgres"` if not set. *(new in 2.2.1)* |
2526
| `database.reconnect` || `True` | Auto-reconnect on connection loss |
2627
| `database.use_tls` | `DJ_USE_TLS` | `None` | Enable TLS encryption *(env var new in 2.1)* |
27-
| `database.database_prefix` | `DJ_DATABASE_PREFIX` | `""` | Prefix for database/schema names |
28+
| `database.database_prefix` | `DJ_DATABASE_PREFIX` | `""` | *(Deprecated — use `database.name` instead)* Prefix for database/schema names |
2829
| `database.create_tables` | `DJ_CREATE_TABLES` | `True` | Default for `Schema(create_tables=)`. Set `False` for production mode |
2930

3031
## Connection Settings
@@ -241,6 +242,7 @@ echo ".secrets/" >> .gitignore
241242
export DJ_HOST=mysql.example.com
242243
export DJ_USER=analyst
243244
export DJ_PASS=secret
245+
export DJ_DATABASE_NAME=my_database # PostgreSQL only (new in 2.2.1)
244246
```
245247

246248
**Note:** Per-store credentials must be configured in `datajoint.json` or `.secrets/` — environment variable overrides are not supported for nested store configurations.

0 commit comments

Comments
 (0)