Refactor to allow GENERATE_DB to work properly.

This commit is contained in:
BurnyLlama 2021-11-01 19:18:53 +01:00
parent 94635e510b
commit 0c234c89d9
2 changed files with 10 additions and 10 deletions

View File

@ -2,22 +2,15 @@ import express from 'express'
import dotenv from 'dotenv' import dotenv from 'dotenv'
import api from './api/api.js' import api from './api/api.js'
import { generateDB } from "./libs/database/generate.js" import { generateDB } from "./libs/database/generate.js"
import { sqlite, dbInit } from "./libs/database/init.js" import { dbInit } from "./libs/database/init.js"
import { ddnssStart } from './libs/ddnss/handler.js'
import tasks from './libs/database/tasks.js'
dotenv.config() dotenv.config()
dbInit() dbInit()
const exists = sqlite.prepare(`SELECT count(*) as a FROM sqlite_master WHERE type='table' AND name='points'`).get()
if(!exists.a)
generateDB() generateDB()
const Server = express() const Server = express()
Server.use('/api', api) Server.use('/api', api)
Server.listen(process.env.PORT, () => console.log(`Server started and listening on port ${process.env.PORT}.`)) Server.listen(process.env.PORT, () => console.log(`Server started and listening on port ${process.env.PORT}.`))
//ddnssStart()

View File

@ -13,6 +13,13 @@ export function generateDB() {
/* TODO: Clean this up as it is a mess */ /* TODO: Clean this up as it is a mess */
/* TODO: Remove useless ones */ /* TODO: Remove useless ones */
if (process.env.GENERATE_DB !== "true")
return log("Won't generate the database since 'GENERATE_DB' is not set to \"true\" in '.env'!")
const exists = sqlite.prepare(`SELECT count(*) as a FROM sqlite_master WHERE type='table' AND name='points'`).get()
if(!exists.a)
return log("Database already generated!")
log("Generating map index...") log("Generating map index...")
execMany([ execMany([
`CREATE INDEX IF NOT EXISTS "idx_maps_map" ON "maps" ("map")`, `CREATE INDEX IF NOT EXISTS "idx_maps_map" ON "maps" ("map")`,