Skip to content

Commit

Permalink
Add a script to generate the SQL to refresh the materialized views
Browse files Browse the repository at this point in the history
  • Loading branch information
pnorman committed Mar 7, 2016
1 parent d6fe8e9 commit 99b4075
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ osmosis --rrii
```

For production purposes, you probably want to put the script into Chef or similar, and change some paths.

### Refreshing views
To generate the SQL necessary to update the views, run `node refresh.js`.
22 changes: 22 additions & 0 deletions data/refresh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Converts yaml to sql

var yaml = require('js-yaml');
var fs = require('fs');

function tname(table_name) {
return table_name;
}


// Write SQL to STDOUT
var doc = yaml.safeLoad(fs.readFileSync('generalizations.yml', 'utf8'));
console.log("SET client_min_messages TO WARNING;");
console.log("SET statement_timeout = 0;\n")
doc.forEach(function(view) {
// Regular views require no refreshing
if (view.materialized) {
console.log("REFRESH MATERIALIZED VIEW CONCURRENTLY " + tname(view.name) + ";");
}
});
console.log("\nRESET client_min_messages;");

0 comments on commit 99b4075

Please sign in to comment.