2017-03-17 19:35:06 +00:00
|
|
|
|
2017-03-17 20:59:03 +00:00
|
|
|
drop table if exists usage_metrics;
|
2017-03-17 19:35:06 +00:00
|
|
|
CREATE TABLE usage_metrics (
|
|
|
|
registered_users int,
|
|
|
|
users_with_address int,
|
|
|
|
change_timestamp timestamp without time zone
|
|
|
|
DEFAULT timezone('utc'::text, now()));
|
|
|
|
|
2017-03-17 20:59:03 +00:00
|
|
|
drop function if exists store_usage_metrics() cascade;
|
2017-03-17 19:35:06 +00:00
|
|
|
CREATE OR REPLACE FUNCTION store_usage_metrics() RETURNS TRIGGER AS $usage_metrics$
|
|
|
|
BEGIN
|
|
|
|
insert into usage_metrics (registered_users, users_with_address)
|
|
|
|
values ((select count(*) from users),
|
|
|
|
(select count(*) from users
|
|
|
|
where address is not null));
|
|
|
|
|
|
|
|
return null;
|
|
|
|
END;
|
|
|
|
$usage_metrics$ LANGUAGE plpgsql;
|
|
|
|
|
|
|
|
CREATE TRIGGER usage_metrics
|
|
|
|
AFTER INSERT OR UPDATE OR DELETE ON users
|
|
|
|
execute PROCEDURE store_usage_metrics();
|