-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from nightly-labs/events-table
Events table
- Loading branch information
Showing
57 changed files
with
1,104 additions
and
698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
|
||
export type EventType = "AppConnect" | "AppDisconnect" | "ClientConnectInit" | "ClientConnectResolve" | "ClientDisconnect" | "SignMessage" | "SignTransaction" | "SignAndSendTransaction" | "ChangeWallet" | "ChangeNetwork"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE events( | ||
event_id SERIAL PRIMARY KEY, | ||
app_id TEXT NOT NULL, | ||
event_type event_type_enum NOT NULL, | ||
creation_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
CREATE TABLE event_app_connect( | ||
event_id BIGINT PRIMARY KEY REFERENCES events(event_id), | ||
session_id TEXT NOT NULL, | ||
device_metadata TEXT NOT NULL, | ||
lang TEXT NOT NULL, | ||
timezone TEXT NOT NULL, | ||
new_session BOOLEAN NOT NULL | ||
); | ||
|
||
CREATE TABLE event_app_disconnect( | ||
event_id BIGINT PRIMARY KEY REFERENCES events(event_id), | ||
session_id TEXT NOT NULL | ||
); | ||
|
||
CREATE TABLE event_client_connect( | ||
event_id BIGINT PRIMARY KEY REFERENCES events(event_id), | ||
client_id TEXT NOT NULL, | ||
session_id TEXT NOT NULL, | ||
addresses TEXT[], | ||
wallet_name TEXT NOT NULL, | ||
wallet_type TEXT NOT NULL, | ||
session_type session_type_enum NOT NULL, | ||
success BOOLEAN NOT NULL | ||
); | ||
|
||
CREATE TABLE event_client_disconnect( | ||
event_id BIGINT PRIMARY KEY REFERENCES events(event_id), | ||
disconnected_session_id TEXT NOT NULL | ||
); | ||
|
||
CREATE TABLE event_sign_message( | ||
event_id BIGINT PRIMARY KEY REFERENCES events(event_id), | ||
session_id TEXT NOT NULL, | ||
request_id TEXT NOT NULL, | ||
request_status request_status_enum NOT NULL, | ||
network TEXT NOT NULL | ||
); | ||
|
||
CREATE TABLE event_sign_transaction( | ||
event_id BIGINT PRIMARY KEY REFERENCES events(event_id), | ||
session_id TEXT NOT NULL, | ||
request_id TEXT NOT NULL, | ||
request_status request_status_enum NOT NULL, | ||
network TEXT NOT NULL, | ||
tx_hash TEXT | ||
); | ||
|
||
CREATE TABLE event_sign_and_send_transaction( | ||
event_id BIGINT PRIMARY KEY REFERENCES events(event_id), | ||
session_id TEXT NOT NULL, | ||
request_id TEXT NOT NULL, | ||
request_status request_status_enum NOT NULL, | ||
network TEXT NOT NULL, | ||
tx_hash TEXT | ||
); | ||
|
||
CREATE TABLE event_change_wallet( | ||
event_id BIGINT PRIMARY KEY REFERENCES events(event_id), | ||
session_id TEXT NOT NULL, | ||
request_id TEXT NOT NULL, | ||
request_status request_status_enum NOT NULL, | ||
network TEXT NOT NULL, | ||
wallet_name TEXT NOT NULL, | ||
wallet_type TEXT NOT NULL, | ||
old_wallet_address TEXT NOT NULL, | ||
new_wallet_address TEXT NOT NULL | ||
); | ||
|
||
CREATE TABLE event_change_network( | ||
event_id BIGINT PRIMARY KEY REFERENCES events(event_id), | ||
session_id TEXT NOT NULL, | ||
request_id TEXT NOT NULL, | ||
request_status request_status_enum NOT NULL, | ||
old_network TEXT NOT NULL, | ||
new_network TEXT NOT NULL | ||
); |
4 changes: 2 additions & 2 deletions
4
...se/migrations/0012_create_hypertables.sql → ...se/migrations/0013_create_hypertables.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
-- ----------------- Hourly requests stats per app ----------------- | ||
-- --- View | ||
-- CREATE MATERIALIZED VIEW hourly_requests_stats_per_app WITH (timescaledb.continuous) AS | ||
-- SELECT | ||
-- app_id, | ||
-- time_bucket('1 hour' :: interval, creation_timestamp) AS hourly_bucket, | ||
-- COUNT(*) AS hourly_request_count, | ||
-- COUNT(*) FILTER ( | ||
-- WHERE | ||
-- request_status = 'Completed' | ||
-- ) :: FLOAT / NULLIF( | ||
-- COUNT(*) FILTER ( | ||
-- WHERE | ||
-- request_status IN ('Completed', 'Rejected', 'TimedOut') | ||
-- ), | ||
-- 0 | ||
-- ) AS hourly_success_rate | ||
-- FROM | ||
-- requests | ||
-- GROUP BY | ||
-- app_id, | ||
-- hourly_bucket WITH NO DATA; | ||
|
||
-- --- Refresh policy | ||
-- SELECT | ||
-- add_continuous_aggregate_policy( | ||
-- 'hourly_requests_stats_per_app', | ||
-- start_offset => INTERVAL '3 h', | ||
-- end_offset => INTERVAL '1 h', | ||
-- schedule_interval => INTERVAL '1 h' | ||
-- ); | ||
|
||
-- --- Real time aggregation | ||
-- ALTER MATERIALIZED VIEW hourly_requests_stats_per_app | ||
-- set | ||
-- (timescaledb.materialized_only = false); | ||
|
||
|
||
|
||
-- ----------------- Daily requests stats per app ----------------- | ||
-- --- View | ||
-- CREATE MATERIALIZED VIEW daily_requests_stats_per_app WITH (timescaledb.continuous) AS | ||
-- SELECT | ||
-- app_id, | ||
-- time_bucket('1 day' :: interval, hourly_bucket) AS daily_bucket, | ||
-- SUM(hourly_request_count) :: BIGINT AS daily_request_count, | ||
-- SUM(hourly_request_count * hourly_success_rate) :: FLOAT / SUM(hourly_request_count) AS daily_success_rate | ||
-- FROM | ||
-- hourly_requests_stats_per_app | ||
-- GROUP BY | ||
-- app_id, | ||
-- daily_bucket WITH NO DATA; | ||
|
||
-- --- Refresh policy | ||
-- SELECT | ||
-- add_continuous_aggregate_policy( | ||
-- 'daily_requests_stats_per_app', | ||
-- start_offset => INTERVAL '3 d', | ||
-- end_offset => INTERVAL '1 h', | ||
-- schedule_interval => INTERVAL '12 h' | ||
-- ); | ||
|
||
-- --- Real time aggregation | ||
-- ALTER MATERIALIZED VIEW daily_requests_stats_per_app | ||
-- set | ||
-- (timescaledb.materialized_only = false); | ||
|
||
|
||
|
||
-- ----------------- Monthly requests per app ----------------- | ||
-- --- View | ||
-- CREATE MATERIALIZED VIEW monthly_requests_stats_per_app WITH (timescaledb.continuous) AS | ||
-- SELECT | ||
-- app_id, | ||
-- time_bucket('1 month' :: interval, daily_bucket) AS monthly_bucket, | ||
-- SUM(daily_request_count) :: BIGINT AS monthly_request_count, | ||
-- SUM(daily_request_count * daily_success_rate) :: FLOAT / SUM(daily_request_count) AS monthly_success_rate | ||
-- FROM | ||
-- daily_requests_stats_per_app | ||
-- GROUP BY | ||
-- app_id, | ||
-- monthly_bucket WITH NO DATA; | ||
|
||
-- --- Refresh policy | ||
-- SELECT | ||
-- add_continuous_aggregate_policy( | ||
-- 'monthly_requests_stats_per_app', | ||
-- start_offset => INTERVAL '3 month', | ||
-- end_offset => INTERVAL '1 h', | ||
-- schedule_interval => INTERVAL '1 month' | ||
-- ); | ||
|
||
-- --- Real time aggregation | ||
-- ALTER MATERIALIZED VIEW monthly_requests_stats_per_app | ||
-- set | ||
-- (timescaledb.materialized_only = false); |
File renamed without changes.
Oops, something went wrong.