import env from '#start/env' import app from '@adonisjs/core/services/app' import { defineConfig } from '@adonisjs/lucid' const dbConfig = defineConfig({ /** * Default connection used for all queries. */ connection: 'sqlite', connections: { /** * SQLite keeps the dashboard independent from MariaDB: the history and * the action log stay available even when MariaDB is down. */ sqlite: { client: 'better-sqlite3', connection: { filename: env.get('DB_PATH') ?? app.tmpPath('db.sqlite3'), }, /** * WAL lets the HTTP requests read while the monitors write. */ pool: { afterCreate: (connection: any, done: (error: Error | null, connection: any) => void) => { connection.pragma('journal_mode = WAL') connection.pragma('foreign_keys = ON') done(null, connection) }, }, /** * Required by Knex for SQLite defaults. */ useNullAsDefault: true, migrations: { /** * Sort migration files naturally by filename. */ naturalSort: true, /** * Paths containing migration files. */ paths: ['database/migrations'], }, schemaGeneration: { /** * Enable schema generation from Lucid models. */ enabled: true, /** * Custom schema rules file paths. */ rulesPaths: ['./database/schema_rules.js'], }, }, }, }) export default dbConfig