mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
be37070fb6
migration from usage of config() to just an object of config. no relevant issue - Change 'loadConfig' task to 'ensureConfig' to more accurately reflect what it is actually doing. Its sole purpose is to make sure a `config.js` file exists, and as such the name now reflects that purpose. - Update config/index.js to export the ghostConfig object directly so that it can be accessed from other modules - Update all references of config(). to config. This was a blind global find all and replace, treat it as such. - Fixes to tests to support new config access method - Allow each test to still work when invoked invidually
44 lines
No EOL
1.3 KiB
JavaScript
44 lines
No EOL
1.3 KiB
JavaScript
var _ = require('lodash'),
|
|
config = require('../../../config/index'),
|
|
|
|
// private
|
|
doRawFlattenAndPluck,
|
|
|
|
// public
|
|
getTables,
|
|
getIndexes,
|
|
getColumns;
|
|
|
|
|
|
doRawFlattenAndPluck = function doRaw(query, name) {
|
|
return config.database.knex.raw(query).then(function (response) {
|
|
return _.flatten(_.pluck(response.rows, name));
|
|
});
|
|
};
|
|
|
|
getTables = function getTables() {
|
|
return doRawFlattenAndPluck(
|
|
'SELECT table_name FROM information_schema.tables WHERE table_schema = "public"', 'table_name'
|
|
);
|
|
};
|
|
|
|
getIndexes = function getIndexes(table) {
|
|
var selectIndexes = 'SELECT t.relname as table_name, i.relname as index_name, a.attname as column_name' +
|
|
' FROM pg_class t, pg_class i, pg_index ix, pg_attribute a' +
|
|
' WHERE t.oid = ix.indrelid and i.oid = ix.indexrelid and' +
|
|
' a.attrelid = t.oid and a.attnum = ANY(ix.indkey) and t.relname = "' + table + '"';
|
|
|
|
return doRawFlattenAndPluck(selectIndexes, 'index_name');
|
|
};
|
|
|
|
getColumns = function getColumns(table) {
|
|
var selectIndexes = 'SELECT column_name FROM information_schema.columns WHERE table_name = "' + table + '"';
|
|
|
|
return doRawFlattenAndPluck(selectIndexes, 'column_name');
|
|
};
|
|
|
|
module.exports = {
|
|
getTables: getTables,
|
|
getIndexes: getIndexes,
|
|
getColumns: getColumns
|
|
}; |