diff --git a/package-lock.json b/package-lock.json index 41c03b0eb..6c0a33cde 100644 Binary files a/package-lock.json and b/package-lock.json differ diff --git a/package.json b/package.json index 33a7975e0..14b4c5fd4 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,6 @@ "picocolors": "^1.1.1", "probe-image-size": "^7.2.3", "reflect-metadata": "^0.2.2", - "sqlite3": "^5.1.7", "tslib": "^2.8.1", "typeorm": "^0.3.28", "wretch": "^2.11.1", @@ -132,5 +131,10 @@ "mailgun.js": "^12.4.0", "node-mailjet": "^6.0.11", "nodemailer": "^7.0.11" + }, + "overrides": { + "typeorm": { + "sqlite3": "../_EXCLUDED_" + } } } diff --git a/src/util/util/Database.ts b/src/util/util/Database.ts index 647fba015..7a0d084f0 100644 --- a/src/util/util/Database.ts +++ b/src/util/util/Database.ts @@ -39,6 +39,18 @@ const dbConnectionString = process.env.DATABASE || path.join(process.cwd(), "dat export const DatabaseType = dbConnectionString.includes("://") ? dbConnectionString.split(":")[0]?.replace("+srv", "") : "sqlite"; const isSqlite = DatabaseType.includes("sqlite"); +let hasWarnedSqlite = false; +if (isSqlite && !hasWarnedSqlite) { + hasWarnedSqlite = true; + console.log(`[Database] ${red(`You are running sqlite! Please keep in mind that we recommend setting up a dedicated database!`)}`); + try { + const _ = require("sqlite3"); + } catch (e) { + console.log(`[Database] ${red(`Failed to load sqlite3 package. Please install it with 'npm install --no-save sqlite3', or switch to a real database like Postgres.`)}`); + process.exit(1); + } +} + export const DataSourceOptions = new DataSource({ // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore type 'string' is not 'sqlite' | 'postgres' | etc etc @@ -66,10 +78,6 @@ export function getDatabase(): DataSource | null { export async function initDatabase(): Promise { if (dbConnection) return dbConnection; - if (isSqlite) { - console.log(`[Database] ${red(`You are running sqlite! Please keep in mind that we recommend setting up a dedicated database!`)}`); - } - if (!process.env.DB_SYNC) { const supported = ["postgres", "sqlite"]; if (!supported.includes(DatabaseType)) { @@ -80,7 +88,7 @@ export async function initDatabase(): Promise { ` To ignore, set DB_SYNC=true in your env. https://docs.spacebar.chat/setup/server/configuration/env/`, ), ); - process.exit(); + process.exit(1); } }