feat(db): removed requirement to have EnvVar for database location
By default the database directory is `/volumes/database`, but can be changed by setting `DATABASE_DIR` env var
This commit is contained in:
parent
fbbc6d8f39
commit
af13395f2f
2 changed files with 9 additions and 15 deletions
|
|
@ -60,7 +60,6 @@ services:
|
||||||
- ./src/auth/config:/config
|
- ./src/auth/config:/config
|
||||||
environment:
|
environment:
|
||||||
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
||||||
- DATABASE_DIR=/volumes/database
|
|
||||||
logging:
|
logging:
|
||||||
driver: gelf
|
driver: gelf
|
||||||
options:
|
options:
|
||||||
|
|
@ -84,7 +83,6 @@ services:
|
||||||
- static-volume:/volumes/static
|
- static-volume:/volumes/static
|
||||||
environment:
|
environment:
|
||||||
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
||||||
- DATABASE_DIR=/volumes/database
|
|
||||||
logging:
|
logging:
|
||||||
driver: gelf
|
driver: gelf
|
||||||
options:
|
options:
|
||||||
|
|
@ -108,7 +106,6 @@ services:
|
||||||
- static-volume:/volumes/static
|
- static-volume:/volumes/static
|
||||||
environment:
|
environment:
|
||||||
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
||||||
- DATABASE_DIR=/volumes/database
|
|
||||||
- PROVIDER_FILE=/extra/providers.toml
|
- PROVIDER_FILE=/extra/providers.toml
|
||||||
- SESSION_MANAGER=${SESSION_MANAGER}
|
- SESSION_MANAGER=${SESSION_MANAGER}
|
||||||
logging:
|
logging:
|
||||||
|
|
@ -131,7 +128,6 @@ services:
|
||||||
- static-volume:/volumes/static
|
- static-volume:/volumes/static
|
||||||
environment:
|
environment:
|
||||||
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
- JWT_SECRET=KRUGKIDROVUWG2ZAMJZG653OEBTG66BANJ2W24DTEBXXMZLSEB2GQZJANRQXU6JA
|
||||||
- DATABASE_DIR=/volumes/database
|
|
||||||
logging:
|
logging:
|
||||||
driver: gelf
|
driver: gelf
|
||||||
options:
|
options:
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
import fp from 'fastify-plugin';
|
import fp from 'fastify-plugin';
|
||||||
import { FastifyInstance, FastifyPluginAsync } from 'fastify';
|
import { FastifyInstance, FastifyPluginAsync } from 'fastify';
|
||||||
|
|
||||||
import { isNullish } from '@shared/utils';
|
|
||||||
import { Database as DbImpl } from './mixin/_base';
|
import { Database as DbImpl } from './mixin/_base';
|
||||||
import { IUserDb, UserImpl } from './mixin/user';
|
import { IUserDb, UserImpl } from './mixin/user';
|
||||||
import { IBlockedDb, BlockedImpl } from './mixin/blocked';
|
import { IBlockedDb, BlockedImpl } from './mixin/blocked';
|
||||||
|
|
||||||
|
|
||||||
Object.assign(DbImpl.prototype, UserImpl);
|
Object.assign(DbImpl.prototype, UserImpl);
|
||||||
Object.assign(DbImpl.prototype, BlockedImpl);
|
Object.assign(DbImpl.prototype, BlockedImpl);
|
||||||
|
|
||||||
|
|
@ -23,18 +21,18 @@ let dbAdded = false;
|
||||||
|
|
||||||
export const useDatabase = fp<FastifyPluginAsync>(async function(
|
export const useDatabase = fp<FastifyPluginAsync>(async function(
|
||||||
f: FastifyInstance,
|
f: FastifyInstance,
|
||||||
_options: object) {
|
_options: object,
|
||||||
|
) {
|
||||||
void _options;
|
void _options;
|
||||||
if (dbAdded) { return; }
|
if (dbAdded) {
|
||||||
dbAdded = true;
|
return;
|
||||||
const path = process.env.DATABASE_DIR;
|
|
||||||
if (isNullish(path)) {
|
|
||||||
f.log.fatal('env `DATABASE_DIR` not defined');
|
|
||||||
throw 'env `DATABASE_DIR` not defined';
|
|
||||||
}
|
}
|
||||||
|
dbAdded = true;
|
||||||
|
const path = process.env.DATABASE_DIR ?? '/volumes/database';
|
||||||
const db: Database = new DbImpl(`${path}/database.db`) as Database;
|
const db: Database = new DbImpl(`${path}/database.db`) as Database;
|
||||||
if (!f.hasDecorator('db')) { f.decorate('db', db); }
|
if (!f.hasDecorator('db')) {
|
||||||
|
f.decorate('db', db);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default useDatabase;
|
export default useDatabase;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue