feat(config): database section removed

This commit is contained in:
diced 2021-08-28 11:32:09 -07:00
parent b5e882f07e
commit 794778dee2
No known key found for this signature in database
GPG key ID: 85AB64C74535D76E
12 changed files with 16 additions and 24 deletions

View file

@ -40,6 +40,7 @@ module.exports = {
'scripts', 'scripts',
'server', 'server',
'pages', 'pages',
'config',
'api', 'api',
'hooks', 'hooks',
'components', 'components',

View file

@ -3,10 +3,7 @@ secure = true
secret = 'some secret' secret = 'some secret'
host = '0.0.0.0' host = '0.0.0.0'
port = 3000 port = 3000
database_url = 'postgres://postgres:postgres@postgres/postgres'
[database]
type = 'psql'
url = 'postgres://postgres:postgres@postgres/postgres'
[uploader] [uploader]
route = '/u' route = '/u'

View file

@ -24,7 +24,6 @@ services:
- SECRET=changethis - SECRET=changethis
- HOST=0.0.0.0 - HOST=0.0.0.0
- PORT=3000 - PORT=3000
- DATABASE_TYPE=psql
- DATABASE_URL=postgresql://postgres:postgres@postgres/postgres/ - DATABASE_URL=postgresql://postgres:postgres@postgres/postgres/
- UPLOADER_ROUTE=/u - UPLOADER_ROUTE=/u
- UPLOADER_EMBED_ROUTE=/a - UPLOADER_EMBED_ROUTE=/a

View file

@ -3,8 +3,8 @@ const prismaRun = require('./prisma-run');
module.exports = async (config) => { module.exports = async (config) => {
try { try {
await prismaRun(config.database.url, ['migrate', 'deploy']); await prismaRun(config.core.database_url, ['migrate', 'deploy']);
await prismaRun(config.database.url, ['generate']); await prismaRun(config.core.database_url, ['generate'], true);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
Logger.get('db').error('there was an error.. exiting..'); Logger.get('db').error('there was an error.. exiting..');

View file

@ -11,7 +11,7 @@ const { PrismaClient } = require('@prisma/client');
await validateConfig(config); 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 files = await readdir(process.argv[2]);
const data = files.map(x => { const data = files.map(x => {

View file

@ -1,7 +1,7 @@
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const { join } = require('path'); const { join } = require('path');
module.exports = (url, args) => { module.exports = (url, args, nostdout = false) => {
return new Promise((res, rej) => { return new Promise((res, rej) => {
const proc = spawn(join(process.cwd(), 'node_modules', '.bin', 'prisma'), args, { const proc = spawn(join(process.cwd(), 'node_modules', '.bin', 'prisma'), args, {
env: { env: {
@ -13,11 +13,11 @@ module.exports = (url, args) => {
let a = ''; let a = '';
proc.stdout.on('data', d => { proc.stdout.on('data', d => {
console.log(d.toString()); if (!nostdout) console.log(d.toString());
a += d.toString(); a += d.toString();
}); });
proc.stderr.on('data', d => { proc.stderr.on('data', d => {
console.log(d.toString()); if (!nostdout) console.log(d.toString());
rej(d.toString()); rej(d.toString());
}); });
proc.stdout.on('end', () => res(a)); proc.stdout.on('end', () => res(a));

View file

@ -37,13 +37,13 @@ function shouldUseYarn() {
const config = readConfig(); const config = readConfig();
await validateConfig(config); 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:')) { if (data.includes('Following migration have not yet been applied:')) {
Logger.get('database').info('some migrations are not applied, applying them now...'); Logger.get('database').info('some migrations are not applied, applying them now...');
await deployDb(config); await deployDb(config);
Logger.get('database').info('finished applying migrations'); 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 stat('./.next');
await mkdir(config.uploader.directory, { recursive: true }); await mkdir(config.uploader.directory, { recursive: true });

View file

@ -12,8 +12,7 @@ module.exports = async config => {
path('core.secret', 'string'), path('core.secret', 'string'),
path('core.host', 'string'), path('core.host', 'string'),
path('core.port', 'number'), path('core.port', 'number'),
path('database.type', 'string'), path('core.database_url', 'string'),
path('database.url', 'string'),
path('uploader.route', 'string'), path('uploader.route', 'string'),
path('uploader.embed_route', 'string'), path('uploader.embed_route', 'string'),
path('uploader.length', 'number'), path('uploader.length', 'number'),

View file

@ -9,8 +9,7 @@ const envValues = [
e('SECRET', 'string', (c, v) => c.core.secret = v), e('SECRET', 'string', (c, v) => c.core.secret = v),
e('HOST', 'string', (c, v) => c.core.host = v), e('HOST', 'string', (c, v) => c.core.host = v),
e('PORT', 'number', (c, v) => c.core.port = 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.core.database_url = v),
e('DATABASE_URL', 'string', (c, v) => c.database.url = v),
e('UPLOADER_ROUTE', 'string', (c, v) => c.uploader.route = 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_EMBED_ROUTE', 'string', (c, v) => c.uploader.embed_route = v),
e('UPLOADER_LENGTH', 'number', (c, v) => c.uploader.length = v), e('UPLOADER_LENGTH', 'number', (c, v) => c.uploader.length = v),

View file

@ -10,11 +10,9 @@ export interface ConfigCore {
// The port Zipline will run on // The port Zipline will run on
port: number; port: number;
}
export interface ConfigDatabase { // The PostgreSQL database url
type: 'psql'; database_url: string
url: string;
} }
export interface ConfigUploader { export interface ConfigUploader {
@ -33,6 +31,5 @@ export interface ConfigUploader {
export interface Config { export interface Config {
core: ConfigCore; core: ConfigCore;
database: ConfigDatabase;
uploader: ConfigUploader; uploader: ConfigUploader;
} }

View file

@ -11,7 +11,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
const users = await prisma.user.findMany(); const users = await prisma.user.findMany();
if (users.length === 0) { 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({ const user = await prisma.user.findFirst({

2
zip-env.d.ts vendored
View file

@ -5,7 +5,7 @@ declare global {
namespace NodeJS { namespace NodeJS {
interface Global { interface Global {
prisma: PrismaClient; prisma: PrismaClient;
config: Config config: Config;
} }
} }
} }