11import { Client } from 'pg' ;
22import fs from 'fs' ;
33import config from './config' ;
4+ import path from 'path' ;
45
56export default async function ( ) {
67 if ( ! config . pgsql . host || ! config . pgsql . database ) {
@@ -31,7 +32,8 @@ export default async function () {
3132 console . log ( "[init] Tables created, skip installation." ) ;
3233 } else {
3334 console . log ( "[init] Tables not exists, installing..." ) ;
34- const sqlCreate = fs . readFileSync ( "./scripts/create.sql" , "utf8" ) ;
35+ const sqlPath = path . join ( __dirname , "./scripts/create.sql" ) ;
36+ const sqlCreate = fs . readFileSync ( sqlPath , "utf8" ) ;
3537 await client . query ( sqlCreate ) ;
3638 console . log ( "[init] Created successfully." ) ;
3739 }
@@ -46,7 +48,8 @@ export default async function () {
4648 console . log ( "[v0.0.5] Tables created, skip installation." ) ;
4749 } else {
4850 console . log ( "[v0.0.5] Tables not exists, installing..." ) ;
49- const sqlCreate_0_0_5 = fs . readFileSync ( "./scripts/patch-0.0.5.sql" , "utf8" ) ;
51+ const sqlPath = path . join ( __dirname , "./scripts/patch-0.0.5.sql" ) ;
52+ const sqlCreate_0_0_5 = fs . readFileSync ( sqlPath , "utf8" ) ;
5053 await client . query ( sqlCreate_0_0_5 ) ;
5154 console . log ( "[v0.0.5] Created successfully." ) ;
5255 }
@@ -60,7 +63,8 @@ export default async function () {
6063 console . log ( "[v0.0.12] Tables created, skip installation." ) ;
6164 } else {
6265 console . log ( "[v0.0.12] Tables not exists, installing..." ) ;
63- const sqlCreate_0_0_12 = fs . readFileSync ( "./scripts/patch-0.0.12.sql" , "utf8" ) ;
66+ const sqlPath = path . join ( __dirname , "./scripts/patch-0.0.12.sql" ) ;
67+ const sqlCreate_0_0_12 = fs . readFileSync ( sqlPath , "utf8" ) ;
6468 await client . query ( sqlCreate_0_0_12 ) ;
6569 console . log ( "[v0.0.12] Created successfully." ) ;
6670 }
0 commit comments