import {SQLite} from 'minidb';
import Migrations from './migrations';
import path from 'path';

let instance = null;

let options = {
  file: path.join('.', 'data', 'fulcrumapp.db'),
  wal: true,
  autoVacuum: true,
  synchronous: 'off'
};

export default async function database() {
  if (instance) {
    return instance;
  }

  instance = new SQLite(options);

  const migrations = new Migrations(instance);

  await instance.open();

  await migrations.migrate();

  return instance;
}

@@ -92,28 +92,109 @@
 h';%0A
-%0Alet instance = null
+import mkdirp from 'mkdirp';%0A%0Alet instance = null;%0A%0Alet dir = path.join('.', 'data')%0Amkdirp.sync(dir)
 ;%0A%0Al
@@ -226,27 +226,19 @@
 th.join(
-'.', 'data'
+dir
 , 'fulcr

Make db dir if it's not already there.