Skip to content

Commit 52c0a09

Browse files
committed
fix: update /:id/event-aggregates db queries
1 parent 83c16f1 commit 52c0a09

File tree

12 files changed

+163
-86
lines changed

12 files changed

+163
-86
lines changed

Cargo.lock

Lines changed: 34 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

primitives/src/util/tests/prep_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ lazy_static! {
2020
ids.insert("user".into(), ValidatorId::try_from("0x20754168c00a6e58116ccfd0a5f7d1bb66c5de9d").expect("failed to parse id"));
2121
ids.insert("publisher".into(), ValidatorId::try_from("0xb7d3f81e857692d13e9d63b232a90f4a1793189e").expect("failed to parse id"));
2222
ids.insert("publisher2".into(), ValidatorId::try_from("0x2054b0c1339309597ad04ba47f4590f8cdb4e305").expect("failed to parse id"));
23-
ids.insert("creator".into(), ValidatorId::try_from("0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359").expect("failed to parse id"));
23+
ids.insert("creator".into(), ValidatorId::try_from("0x033ed90e0fec3f3ea1c9b005c724d704501e0196").expect("failed to parse id"));
2424
ids.insert("tester".into(), ValidatorId::try_from("0x2892f6C41E0718eeeDd49D98D648C789668cA67d").expect("failed to parse id"));
2525

2626
ids
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DELETE FROM channels;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
INSERT INTO
2+
channels
3+
VALUES
4+
(
5+
'0x061d5e2a67d0a9a10f1c732bca12a676d83f79663a396f7d87b3e30b9b411088',
6+
'0x033ed90e0fec3f3ea1c9b005c724d704501e0196',
7+
'0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359',
8+
'1000',
9+
to_timestamp(4102444800000),
10+
'{"minPerImpression":"1","maxPerImpression":"10","pricingBounds":{"CLICK":{"min":"0","max":"0"}},"withdrawPeriodStart":4073414400000,"validators":[{"id":"0xce07CbB7e054514D590a0262C93070D838bFBA2e","url":"http://localhost:8005","fee":"100"},{"id":"0xC91763D7F14ac5c5dDfBCD012e0D2A61ab9bDED3","url":"http://localhost:8006","fee":"100"}]}'
11+
);

sentry/migrations/20190806011140_initial-tables/up.sql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ CREATE TABLE event_aggregates
3030
channel_id VARCHAR(66) NOT NULL REFERENCES channels (id) ON DELETE RESTRICT,
3131
created TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
3232
event_type VARCHAR(255) NOT NULL,
33-
earner VARCHAR(255) ,
33+
earner VARCHAR(255),
3434
event_counts VARCHAR NOT NULL,
35-
event_payouts VARCHAR NOT NULL,
35+
event_payouts VARCHAR NOT NULL
3636
);
3737

3838
CREATE INDEX idx_event_aggregates_created ON event_aggregates (created);
39-
CREATE INDEX idx_event_aggregates_channel ON event_aggregates (created);
39+
CREATE INDEX idx_event_aggregates_channel ON event_aggregates (channel_id);
40+
CREATE INDEX idx_event_aggregates_event_type ON event_aggregates (event_type);
41+
42+
CREATE AGGREGATE jsonb_object_agg(jsonb) (
43+
SFUNC = 'jsonb_concat',
44+
STYPE = jsonb,
45+
INITCOND = '{}'
46+
);

sentry/src/access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub async fn check_access(
8484
.as_ref()
8585
.map(|ev_sub| ev_sub.allow.as_slice())
8686
.unwrap_or_else(|| &default_rules);
87-
87+
8888
// first, find an applicable access rule
8989
let rules = allow_rules
9090
.iter()

sentry/src/db.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub async fn postgres_connection() -> Result<DbPool, bb8_postgres::tokio_postgre
5555
Pool::builder().build(pg_mgr).await
5656
}
5757

58-
pub async fn setup_migrations() {
58+
pub async fn setup_migrations(environment: &str) {
5959
use migrant_lib::{Config, Direction, Migrator, Settings};
6060

6161
let settings = Settings::configure_postgres()
@@ -82,9 +82,18 @@ pub async fn setup_migrations() {
8282
};
8383
}
8484

85+
let mut migrations = vec![
86+
make_migration!("20190806011140_initial-tables")
87+
];
88+
89+
if environment == "development" {
90+
// seeds database tables for testing
91+
migrations.push(make_migration!("20190806011140_initial-tables/seed"))
92+
}
93+
8594
// Define Migrations
8695
config
87-
.use_migrations(&[make_migration!("20190806011140_initial-tables")])
96+
.use_migrations(&migrations.as_slice())
8897
.expect("Loading migrations failed");
8998

9099
// Reload config, ping the database for applied migrations

0 commit comments

Comments
 (0)