Skip to content

Commit c17fc77

Browse files
committed
refactor(db): simplify DB config to only DB_TYPE and DB_URL, default to sqlite, remove MySQL support and old env vars. Update .env.example accordingly.
1 parent c190bb3 commit c17fc77

File tree

2 files changed

+25
-68
lines changed

2 files changed

+25
-68
lines changed

.env.example

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,47 +41,15 @@ LIVEKIT_API_SECRET=
4141
# Configure your database connection here.
4242
#
4343
# Supported databases:
44-
# - PostgreSQL (DB_TYPE=pg)
45-
# - MySQL (DB_TYPE=mysql2)
46-
# - SQLite (fallback - no configuration needed)
47-
#
48-
# If database environment variables are not provided,
49-
# the application will automatically fall back to SQLite.
50-
51-
# Database type - specify the database engine to use
52-
# Options: 'pg' (PostgreSQL), 'mysql2' (MySQL)
53-
DB_TYPE=pg
54-
55-
# Database connection details
56-
DB_HOST=localhost
57-
DB_PORT=5432
58-
DB_USER=your_username
59-
DB_PASSWORD=your_password
60-
DB_NAME=your_database_name
61-
DB_SCHEMA=your_database_schema
62-
63-
# ==============================================
64-
# STORAGE CONFIGURATION
65-
# ==============================================
66-
# Configure your file storage system here.
67-
#
68-
# Supported storage types:
69-
# - Local file system (default - no configuration needed)
70-
# - AWS S3 (requires S3 configuration below)
71-
#
72-
# If STORAGE_TYPE is provided, AWS S3 storage will be used.
73-
# If STORAGE_TYPE is empty or not set, local file storage will be used.
44+
# - SQLite (default - no configuration needed)
45+
# - PostgreSQL (DB_TYPE=pg with DB_URL)
7446
#
75-
# AWS credentials can be provided via environment variables below,
76-
# or through AWS CLI configuration, IAM roles, or instance profiles.
47+
# If DB_TYPE and DB_URL are not provided or empty,
48+
# the application will automatically use SQLite in the world folder.
49+
50+
# Database type - leave empty for SQLite, or 'pg' for PostgreSQL
51+
DB_TYPE=
7752

78-
# AWS S3 storage configuration (only required when using S3)
79-
# To use AWS S3 storage, set STORAGE_TYPE and other S3 variables below
80-
STORAGE_TYPE=
81-
S3_BUCKET_NAME=bucket-name
82-
AWS_ACCESS_KEY_ID=access-key-id
83-
AWS_SECRET_ACCESS_KEY=secret-key-id
84-
S3_REGION=eu-west-1
85-
S3_ASSETS_PREFIX=
86-
S3_COLLECTIONS_PREFIX=
87-
S3_STORAGE_PREFIX=
53+
# Database connection URL - leave empty for SQLite
54+
# For PostgreSQL, use format: postgres://username:password@host:port/database?schema=public
55+
DB_URL=

src/server/db.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,26 @@ import moment from 'moment'
44
let db
55

66
function getDBConfig(sqlitePath) {
7-
const { DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME, DB_TYPE, DB_SCHEMA } = process.env;
7+
const { DB_TYPE = '', DB_URL = '' } = process.env;
88

9-
const config = {
10-
client: DB_TYPE || 'better-sqlite3',
9+
if (!DB_TYPE && !DB_URL) {
10+
// Default: sqlite in world folder
11+
return {
12+
client: 'better-sqlite3',
13+
connection: { filename: sqlitePath },
14+
useNullAsDefault: true,
15+
};
1116
}
1217

13-
if (DB_TYPE === 'pg' && DB_HOST && DB_PORT && DB_USER && DB_PASSWORD && DB_NAME && DB_SCHEMA) {
14-
config.connection = {
15-
host: DB_HOST,
16-
port: parseInt(DB_PORT),
17-
user: DB_USER,
18-
database: DB_NAME,
19-
password: DB_PASSWORD,
20-
...(DB_TYPE === 'mysql2' && {
21-
charset: 'utf8mb4',
22-
timezone: 'UTC'
23-
})
24-
}
25-
config.searchPath = [DB_SCHEMA]
26-
config.pool = {
27-
min: 2,
28-
max: 10
29-
}
30-
} else {
31-
config.connection = {
32-
filename: sqlitePath,
33-
}
34-
config.useNullAsDefault = true
18+
if (DB_TYPE === 'pg' && DB_URL) {
19+
return {
20+
client: 'pg',
21+
connection: DB_URL,
22+
pool: { min: 2, max: 10 },
23+
};
3524
}
3625

37-
return config;
26+
throw new Error('Unsupported or incomplete DB configuration. Only sqlite (default) and postgres (pg) via DB_TYPE/DB_URL are supported.');
3827
}
3928

4029
export async function getDB(sqlitePath) {

0 commit comments

Comments
 (0)