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',
'server',
'pages',
'config',
'api',
'hooks',
'components',

View file

@ -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'

View file

@ -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

View file

@ -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..');

View file

@ -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 => {

View file

@ -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));

View file

@ -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 });

View file

@ -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'),

View file

@ -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),

View file

@ -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;
}

View file

@ -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({

2
zip-env.d.ts vendored
View file

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