Skip to content

Commit

Permalink
Alter Candlestick views
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsereda committed Oct 27, 2023
1 parent 316cad5 commit a5159b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/demo_uniswap/sql/on_reindex/00_prepare_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;

ALTER TABLE swap DROP CONSTRAINT swap_pkey;
ALTER TABLE swap ADD PRIMARY KEY (id, timestamp);
SELECT create_hypertable('swap', 'timestamp', chunk_time_interval => 7776000);
SELECT create_hypertable('swap', 'timestamp', chunk_time_interval => '30 days');
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
CREATE MATERIALIZED VIEW
candlestick_1m
candlestick_30d
WITH (timescaledb.continuous) AS

SELECT
time_bucket('1 minute'::INTERVAL, timestamp) AS bucket,
time_bucket('30 days'::INTERVAL, timestamp) AS bucket,
token0_id as token_id,
candlestick_agg(
timestamp,
Expand All @@ -24,13 +24,13 @@ ORDER BY
token0_id
WITH NO DATA;

CREATE INDEX candlestick_1m_bucket ON candlestick_1m(bucket);
CREATE INDEX candlestick_1m_token_id ON candlestick_1m(token_id);
CREATE INDEX candlestick_30d_bucket ON candlestick_30d(bucket);
CREATE INDEX candlestick_30d_token_id ON candlestick_30d(token_id);

SELECT add_continuous_aggregate_policy(
'candlestick_1m',
start_offset => INTERVAL '1 hour',
'candlestick_30d',
start_offset => INTERVAL '30 days',
end_offset => INTERVAL '0 minutes',
schedule_interval => INTERVAL '1 minute',
schedule_interval => INTERVAL '1 day',
initial_start := '2018-07-01'
);
);
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
CREATE MATERIALIZED VIEW
candlestick_1h
candlestick_7d
WITH (timescaledb.continuous) AS

SELECT
time_bucket('1 hour'::INTERVAL, timestamp) AS bucket,
time_bucket('7 days'::INTERVAL, timestamp) AS bucket,
token0_id as token_id,
candlestick_agg(
timestamp,
Expand All @@ -24,13 +24,13 @@ ORDER BY
token0_id
WITH NO DATA;

CREATE INDEX candlestick_1h_bucket ON candlestick_1h(bucket);
CREATE INDEX candlestick_1h_token_id ON candlestick_1h(token_id);
CREATE INDEX candlestick_7d_bucket ON candlestick_7d(bucket);
CREATE INDEX candlestick_7d_token_id ON candlestick_7d(token_id);

SELECT add_continuous_aggregate_policy(
'candlestick_1h',
start_offset => INTERVAL '2 hour',
'candlestick_7d',
start_offset => INTERVAL '7 days',
end_offset => INTERVAL '0 minutes',
schedule_interval => INTERVAL '1 hour',
schedule_interval => INTERVAL '1 day',
initial_start := '2018-07-01'
);
);

0 comments on commit a5159b5

Please sign in to comment.