2022-04-29 02:44:38 +00:00
|
|
|
#!/usr/bin/env actual-cli-runner.js
|
2022-08-31 21:46:28 +00:00
|
|
|
const { schema } = require('../src/server/aql');
|
2022-04-29 02:44:38 +00:00
|
|
|
const table = process.argv[3];
|
|
|
|
|
|
|
|
if (table == null || table === 'transactions') {
|
|
|
|
let fields = Object.keys(schema.transactions).map(fieldName => {
|
|
|
|
let desc = schema.transactions[fieldName];
|
|
|
|
let field = `t.${desc.name || fieldName}`;
|
|
|
|
|
|
|
|
if (field === 't.description') {
|
|
|
|
field = 'pm.targetId';
|
|
|
|
} else if (field === 't.category') {
|
|
|
|
field = 'cm.transferId';
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${field} AS ${fieldName}`;
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(`
|
|
|
|
DROP VIEW IF EXISTS v_transactions;
|
|
|
|
CREATE VIEW v_transactions AS
|
|
|
|
SELECT ${fields.join(', ')} FROM transactions t
|
|
|
|
LEFT JOIN category_mapping cm ON cm.id = t.category
|
|
|
|
LEFT JOIN payee_mapping pm ON pm.id = t.description
|
|
|
|
`);
|
|
|
|
}
|