Add a materialized view to capture the first time a type has been seen for export
This will make it easier to create an interface which allows exporting events as they've come up.
This commit is contained in:
parent
a01c698485
commit
b989ec888d
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.sequelize.query('CREATE MATERIALIZED VIEW first_type AS SELECT DISTINCT(type), MIN("createdAt") FROM events GROUP BY type');
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.sequelize.query('DROP MATERIALIZED VIEW first_type');
|
||||
}
|
||||
};
|
|
@ -35,4 +35,15 @@ Object.keys(db).forEach(modelName => {
|
|||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
|
||||
|
||||
/*
|
||||
* Periodically refresh the materialized view for holding the first types
|
||||
*/
|
||||
setInterval(() => {
|
||||
logger.info('Refreshing the `first_type` materialized view');
|
||||
sequelize.query('REFRESH MATERIALIZED VIEW first_type');
|
||||
}, ((60 * 1000) * 60));
|
||||
|
||||
|
||||
|
||||
export default db;
|
||||
|
|
Loading…
Reference in New Issue