diff --git a/commitlint.config.js b/commitlint.config.js index db2b310..fdcc7f7 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -40,6 +40,7 @@ module.exports = { 'scripts', 'server', 'pages', + 'config', 'api', 'hooks', 'components', diff --git a/config.example.toml b/config.example.toml index a4b4d41..c6dec4d 100644 --- a/config.example.toml +++ b/config.example.toml @@ -3,10 +3,7 @@ secure = true secret = 'some secret' host = '0.0.0.0' port = 3000 - -[database] -type = 'psql' -url = 'postgres://postgres:postgres@postgres/postgres' +database_url = 'postgres://postgres:postgres@postgres/postgres' [uploader] route = '/u' diff --git a/docker-compose.yml b/docker-compose.yml index c1059ac..2502506 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,6 @@ services: - SECRET=changethis - HOST=0.0.0.0 - PORT=3000 - - DATABASE_TYPE=psql - DATABASE_URL=postgresql://postgres:postgres@postgres/postgres/ - UPLOADER_ROUTE=/u - UPLOADER_EMBED_ROUTE=/a diff --git a/scripts/deploy-db.js b/scripts/deploy-db.js index da31b55..e2b01eb 100644 --- a/scripts/deploy-db.js +++ b/scripts/deploy-db.js @@ -3,8 +3,8 @@ const prismaRun = require('./prisma-run'); module.exports = async (config) => { try { - await prismaRun(config.database.url, ['migrate', 'deploy']); - await prismaRun(config.database.url, ['generate']); + await prismaRun(config.core.database_url, ['migrate', 'deploy']); + await prismaRun(config.core.database_url, ['generate'], true); } catch (e) { console.log(e); Logger.get('db').error('there was an error.. exiting..'); diff --git a/scripts/migrate-v2-v3.js b/scripts/migrate-v2-v3.js index ff8c66b..dd1f29a 100644 --- a/scripts/migrate-v2-v3.js +++ b/scripts/migrate-v2-v3.js @@ -11,7 +11,7 @@ const { PrismaClient } = require('@prisma/client'); await validateConfig(config); - process.env.DATABASE_URL = config.database.url; + process.env.DATABASE_URL = config.core.database_url; const files = await readdir(process.argv[2]); const data = files.map(x => { diff --git a/scripts/prisma-run.js b/scripts/prisma-run.js index bb184b1..f9305c8 100644 --- a/scripts/prisma-run.js +++ b/scripts/prisma-run.js @@ -1,7 +1,7 @@ const { spawn } = require('child_process'); const { join } = require('path'); -module.exports = (url, args) => { +module.exports = (url, args, nostdout = false) => { return new Promise((res, rej) => { const proc = spawn(join(process.cwd(), 'node_modules', '.bin', 'prisma'), args, { env: { @@ -13,11 +13,11 @@ module.exports = (url, args) => { let a = ''; proc.stdout.on('data', d => { - console.log(d.toString()); + if (!nostdout) console.log(d.toString()); a += d.toString(); }); proc.stderr.on('data', d => { - console.log(d.toString()); + if (!nostdout) console.log(d.toString()); rej(d.toString()); }); proc.stdout.on('end', () => res(a)); diff --git a/server/index.js b/server/index.js index e83c240..4c28096 100644 --- a/server/index.js +++ b/server/index.js @@ -37,13 +37,13 @@ function shouldUseYarn() { const config = readConfig(); await validateConfig(config); - const data = await prismaRun(config.database.url, ['migrate', 'status']); + const data = await prismaRun(config.core.database_url, ['migrate', 'status'], true); if (data.includes('Following migration have not yet been applied:')) { Logger.get('database').info('some migrations are not applied, applying them now...'); await deployDb(config); Logger.get('database').info('finished applying migrations'); } - process.env.DATABASE_URL = config.database.url; + process.env.DATABASE_URL = config.core.database_url; await stat('./.next'); await mkdir(config.uploader.directory, { recursive: true }); diff --git a/server/validateConfig.js b/server/validateConfig.js index cc3101c..df35cab 100644 --- a/server/validateConfig.js +++ b/server/validateConfig.js @@ -12,8 +12,7 @@ module.exports = async config => { path('core.secret', 'string'), path('core.host', 'string'), path('core.port', 'number'), - path('database.type', 'string'), - path('database.url', 'string'), + path('core.database_url', 'string'), path('uploader.route', 'string'), path('uploader.embed_route', 'string'), path('uploader.length', 'number'), diff --git a/src/lib/readConfig.js b/src/lib/readConfig.js index c43fc09..8229d36 100644 --- a/src/lib/readConfig.js +++ b/src/lib/readConfig.js @@ -9,8 +9,7 @@ const envValues = [ e('SECRET', 'string', (c, v) => c.core.secret = v), e('HOST', 'string', (c, v) => c.core.host = v), e('PORT', 'number', (c, v) => c.core.port = v), - e('DATABASE_TYPE', 'string', (c, v) => c.database.type = v), - e('DATABASE_URL', 'string', (c, v) => c.database.url = v), + e('DATABASE_URL', 'string', (c, v) => c.core.database_url = v), e('UPLOADER_ROUTE', 'string', (c, v) => c.uploader.route = v), e('UPLOADER_EMBED_ROUTE', 'string', (c, v) => c.uploader.embed_route = v), e('UPLOADER_LENGTH', 'number', (c, v) => c.uploader.length = v), diff --git a/src/lib/types.ts b/src/lib/types.ts index e41f341..7ab993d 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -10,11 +10,9 @@ export interface ConfigCore { // The port Zipline will run on port: number; -} -export interface ConfigDatabase { - type: 'psql'; - url: string; + // The PostgreSQL database url + database_url: string } export interface ConfigUploader { @@ -33,6 +31,5 @@ export interface ConfigUploader { export interface Config { core: ConfigCore; - database: ConfigDatabase; uploader: ConfigUploader; } \ No newline at end of file diff --git a/src/pages/api/auth/login.ts b/src/pages/api/auth/login.ts index 8ae7e3c..4fba241 100644 --- a/src/pages/api/auth/login.ts +++ b/src/pages/api/auth/login.ts @@ -11,7 +11,7 @@ async function handler(req: NextApiReq, res: NextApiRes) { const users = await prisma.user.findMany(); if (users.length === 0) { - await prismaRun(config.database.url, ['db', 'seed', '--preview-feature']); + await prismaRun(config.core.database_url, ['db', 'seed', '--preview-feature']); } const user = await prisma.user.findFirst({ diff --git a/zip-env.d.ts b/zip-env.d.ts index e495777..59c1da8 100644 --- a/zip-env.d.ts +++ b/zip-env.d.ts @@ -5,7 +5,7 @@ declare global { namespace NodeJS { interface Global { prisma: PrismaClient; - config: Config + config: Config; } } } \ No newline at end of file