Skip to content

Commit 6fadd31

Browse files
committed
fix: sql types
1 parent f78562f commit 6fadd31

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

pragma-entities/migrations/2023-10-25-134954_add_currencies_table/up.sql

+14
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,17 @@ CREATE TABLE currencies (
77
ethereum_address VARCHAR,
88
PRIMARY KEY (id)
99
);
10+
11+
-- initialize
12+
INSERT INTO public.currencies (name, decimals, abstract, ethereum_address) VALUES
13+
('BTC', 8, true, NULL),
14+
('ETH', 18, false, NULL),
15+
('USD', 8, true, NULL),
16+
('EUR', 8, true, NULL),
17+
('WBTC', 8, false, '0x2260FAC5E5542A773AA44FBCFEDF7C193BC2C599'),
18+
('USDC', 6, false, '0xA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48'),
19+
('USDT', 6, false, '0xDAC17F958D2EE523A2206206994597C13D831EC7'),
20+
('DAI', 18, false, '0x6B175474E89094C44DA98B954EEDEAC495271D0F'),
21+
('LORDS', 18, false, '0x686F2404E77AB0D9070A46CDFB0B7FECDD2318B0'),
22+
('R', 18, false, '0x183015A9BA6FF60230FDEADC3F43B3D788B13E21'),
23+
('WSTETH', 18, false, '0x7F39C581F595B53C5CB19BD0B3F8DA6C935E2CA0');

pragma-entities/migrations/2024-01-11-123510_add_continuous_aggregates/up.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ WITH (timescaledb.continuous, timescaledb.materialized_only = true)
44
AS SELECT
55
pair_id,
66
time_bucket('1 min'::interval, timestamp) as bucket,
7-
approx_percentile(0.5, percentile_agg(price)) AS median_price,
7+
approx_percentile(0.5, percentile_agg(price))::numeric AS median_price,
88
COUNT(DISTINCT source) as num_sources
99
FROM entries
1010
GROUP BY bucket, pair_id
@@ -20,7 +20,7 @@ WITH (timescaledb.continuous, timescaledb.materialized_only = true)
2020
AS SELECT
2121
pair_id,
2222
time_bucket('15 min'::interval, timestamp) as bucket,
23-
approx_percentile(0.5, percentile_agg(price)) AS median_price,
23+
approx_percentile(0.5, percentile_agg(price))::numeric AS median_price,
2424
COUNT(DISTINCT source) as num_sources
2525
FROM entries
2626
GROUP BY bucket, pair_id
@@ -36,7 +36,7 @@ WITH (timescaledb.continuous, timescaledb.materialized_only = true)
3636
AS SELECT
3737
pair_id,
3838
time_bucket('1 hour'::interval, timestamp) as bucket,
39-
approx_percentile(0.5, percentile_agg(price)) AS median_price,
39+
approx_percentile(0.5, percentile_agg(price))::numeric AS median_price,
4040
COUNT(DISTINCT source) as num_sources
4141
FROM entries
4242
GROUP BY bucket, pair_id

pragma-entities/src/schema.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,4 @@ diesel::table! {
3333
}
3434
}
3535

36-
diesel::allow_tables_to_appear_in_same_query!(
37-
currencies,
38-
entries,
39-
publishers,
40-
);
36+
diesel::allow_tables_to_appear_in_same_query!(currencies, entries, publishers,);

pragma-node/src/infra/repositories/entry_repository.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ pub async fn _get_all(
6666
pub struct MedianEntry {
6767
pub time: NaiveDateTime,
6868
pub median_price: BigDecimal,
69-
pub num_sources: i32,
69+
pub num_sources: i64,
7070
}
7171

72-
#[derive(Serialize, QueryableByName)]
72+
#[derive(Serialize, QueryableByName, Clone, Debug)]
7373
pub struct MedianEntryRaw {
74-
#[diesel(sql_type = diesel::sql_types::Timestamp)]
74+
#[diesel(sql_type = diesel::sql_types::Timestamptz)]
7575
pub time: NaiveDateTime,
7676
#[diesel(sql_type = diesel::sql_types::Numeric)]
7777
pub median_price: BigDecimal,
78-
#[diesel(sql_type = diesel::sql_types::Integer)]
79-
pub num_sources: i32,
78+
#[diesel(sql_type = diesel::sql_types::BigInt)]
79+
pub num_sources: i64,
8080
}
8181

8282
pub async fn get_median_price(

0 commit comments

Comments
 (0)