Skip to content

Commit

Permalink
Updated fieldnames in the mongo db to reflect recent changes to the a…
Browse files Browse the repository at this point in the history
…pi (#18)
  • Loading branch information
zachsa committed Nov 21, 2022
1 parent ab7f63b commit 1353f3e
Show file tree
Hide file tree
Showing 7 changed files with 2,601 additions and 11 deletions.
5 changes: 2 additions & 3 deletions mongo-scripts/config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { config } from 'dotenv'
config()
import 'dotenv/config'

/**
* MongoDB
*/
export const MONGO_DB = process.env.MONGO_DB || 'catalogue'
export const MONGO_DB = process.env.MONGO_DB || 'sdp_stable'
export const MONGO_DB_ADDRESS = process.env.MONGO_DB_ADDRESS || 'mongodb://localhost:27017'
export const MONGO_DB_USERNAME = process.env.MONGO_DB_USERNAME || 'admin'
export const MONGO_DB_PASSWORD = process.env.MONGO_DB_PASSWORD || 'password'
10 changes: 10 additions & 0 deletions mongo-scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join, normalize, dirname, sep } from 'path'
import { readdir, stat } from 'fs/promises'
import { fileURLToPath } from 'url'

const __dirname = dirname(fileURLToPath(import.meta.url))
Expand All @@ -7,6 +8,15 @@ const _script = process.argv[2]
/**
* Import the requested script
*/
const dir = normalize(join(__dirname, `.${sep}scripts${sep}`))
const availableScripts = await readdir(dir)

if (!availableScripts.includes(_script)) {
throw new Error(
`Unkown scripts "${_script}". Available scripts are "${availableScripts.join('", "')}"`
)
}

const scriptPath = normalize(join(__dirname, `.${sep}scripts${sep}${_script}${sep}index.js`))
const script = await import(scriptPath)
.then(({ default: fn }) => fn)
Expand Down
Loading

0 comments on commit 1353f3e

Please sign in to comment.