Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions internal/server/postgres/sql/migrations/00004_predictions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ CREATE TABLE pred.predicted_generation_values (
),
CONSTRAINT other_stats_valid_fractions_check
CHECK (pred.check_all_jsonb_values_are_valid_stat_fractions(other_stats_fractions)),
PRIMARY KEY (forecast_uuid, target_time_utc, horizon_mins)
PRIMARY KEY (forecast_uuid, target_time_utc)
)
PARTITION BY RANGE (target_time_utc);
PARTITION BY RANGE (forecast_uuid);

/*
* Manage partitions with pg_partman.
Expand All @@ -213,18 +213,20 @@ PARTITION BY RANGE (target_time_utc);
*/
SELECT partman.create_parent(
p_parent_table => 'pred.predicted_generation_values',
p_control => 'target_time_utc',
p_control => 'forecast_uuid',
p_type => 'range',
p_interval => '1 week',
p_automatic_maintenance => 'on',
p_jobmon => FALSE,
p_time_encoder => 'partman.uuid7_time_encoder',
p_time_decoder => 'partman.uuid7_time_decoder',
p_premake => 7
);
UPDATE partman.part_config
SET
retention = '1 month',
retention_keep_table = TRUE,
retention_keep_index = FALSE,
retention_keep_index = TRUE,
infinite_time_partitions = TRUE
WHERE parent_table = 'pred.predicted_generation_values';
SELECT partman.run_maintenance('pred.predicted_generation_values');
Expand Down
6 changes: 0 additions & 6 deletions internal/server/postgres/sql/queries/predictions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ WITH forecasts_to_delete AS (
AND f.geometry_uuid = $1
AND f.source_type_id = $2
AND f.forecaster_id = $3
),
deleted_values AS (
DELETE FROM pred.predicted_generation_values
WHERE target_time_utc >= sqlc.arg(init_timestamp)::TIMESTAMP
AND target_time_utc < sqlc.arg(init_timestamp)::TIMESTAMP + INTERVAL '3 days'
AND forecast_uuid IN (SELECT forecast_uuid FROM forecasts_to_delete)
)
DELETE FROM pred.forecasts
WHERE forecast_uuid IN (SELECT forecast_uuid FROM forecasts_to_delete);
Expand Down
Loading