2021-08-25 11:58:48 -05:00
const { readdir } = require ( 'fs/promises' ) ;
const { extname } = require ( 'path' ) ;
2021-06-23 13:20:20 -05:00
const validateConfig = require ( '../server/validateConfig' ) ;
const Logger = require ( '../src/lib/logger' ) ;
2021-06-23 13:47:05 -05:00
const readConfig = require ( '../src/lib/readConfig' ) ;
2021-06-23 13:20:20 -05:00
const mimes = require ( './mimes' ) ;
const { PrismaClient } = require ( '@prisma/client' ) ;
( async ( ) => {
2021-06-23 13:47:05 -05:00
const config = readConfig ( ) ;
2021-06-23 13:20:20 -05:00
await validateConfig ( config ) ;
2021-08-28 13:32:09 -05:00
process . env . DATABASE _URL = config . core . database _url ;
2021-06-23 13:20:20 -05:00
const files = await readdir ( process . argv [ 2 ] ) ;
const data = files . map ( x => {
const mime = mimes [ extname ( x ) ] ? ? 'application/octet-stream' ;
return {
file : x ,
mimetype : mime ,
userId : 1
} ;
} ) ;
const prisma = new PrismaClient ( ) ;
Logger . get ( 'migrator' ) . info ( 'starting migrations...' ) ;
await prisma . image . createMany ( {
data
} ) ;
Logger . get ( 'migrator' ) . info ( 'finished migrations! It is recomended to move your old uploads folder (' + process . argv [ 2 ] + ') to the current one which is ' + config . uploader . directory ) ;
process . exit ( ) ;
} ) ( ) ;