Skip to content
Snippets Groups Projects
get-db-schema 782 B
#!/usr/bin/env ./cli-runner.js
process.env.LOOT_DATA_DIR = __dirname + '/../../../../data';
import * as sqlite from '../platform/server/sqlite';
import * as db from '../server/db';
import { getMessages } from '../server/sync';

let dbPath = process.argv[2];
let tables = [
  'spreadsheet_cells',
  'accounts',
  'transactions',
  'categories',
  'category_groups',
  'category_mapping',
  'payees',
  'payee_rules',
  'payee_mapping'
];

async function init() {
  db.setDatabase(sqlite.openDatabase(dbPath));
  let schema = {};

  for (let table of tables) {
    let fields = await db.all(`PRAGMA table_info(${table})`);
    schema[table] = {};
    for (let field of fields) {
      schema[table][field.name] = field.type.toLowerCase();
    }
  }

  console.log(schema);
}

init();