From 3bc6875cbf649130a81c124e7920f606e3dc846c Mon Sep 17 00:00:00 2001 From: yuenmichelle1 Date: Tue, 8 Oct 2024 12:24:12 -0500 Subject: [PATCH] update migrations to be reversible --- ...6225916_create_hourly_workflow_classification_count.rb | 8 +++++++- ...231010_add_refresh_policy_for_hourly_workflow_count.rb | 8 +++++++- ...ate_data_retention_policy_for_hourly_workflow_count.rb | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/db/migrate/20240926225916_create_hourly_workflow_classification_count.rb b/db/migrate/20240926225916_create_hourly_workflow_classification_count.rb index e4be895..24f9bf0 100644 --- a/db/migrate/20240926225916_create_hourly_workflow_classification_count.rb +++ b/db/migrate/20240926225916_create_hourly_workflow_classification_count.rb @@ -10,7 +10,7 @@ class CreateHourlyWorkflowClassificationCount < ActiveRecord::Migration[7.0] # - Create a subsequent realtime cagg that buckets hourly that we will create data retention policies for. The plan is for up to 72 hours worth of hourly workflow classification counts of data. # - Update workflow query to first query the daily counts first and the query the hourly counts for just the specific date of now. disable_ddl_transaction! - def change + def up execute <<~SQL create materialized view hourly_classification_count_per_workflow with ( @@ -24,4 +24,10 @@ def change group by hour, workflow_id; SQL end + + def down + execute <<~SQL + DROP materialized view hourly_classification_count_per_workflow; + SQL + end end diff --git a/db/migrate/20240926231010_add_refresh_policy_for_hourly_workflow_count.rb b/db/migrate/20240926231010_add_refresh_policy_for_hourly_workflow_count.rb index ec4364e..2996462 100644 --- a/db/migrate/20240926231010_add_refresh_policy_for_hourly_workflow_count.rb +++ b/db/migrate/20240926231010_add_refresh_policy_for_hourly_workflow_count.rb @@ -2,9 +2,15 @@ class AddRefreshPolicyForHourlyWorkflowCount < ActiveRecord::Migration[7.0] disable_ddl_transaction! - def change + def up execute <<~SQL SELECT add_continuous_aggregate_policy('hourly_classification_count_per_workflow',start_offset => INTERVAL '5 days', end_offset => INTERVAL '30 minutes', schedule_interval => INTERVAL '1 h'); SQL end + + def down + execute <<~SQL + SELECT remove_continuous_aggregate_policy('hourly_classification_count_per_workflow'); + SQL + end end diff --git a/db/migrate/20240926231325_create_data_retention_policy_for_hourly_workflow_count.rb b/db/migrate/20240926231325_create_data_retention_policy_for_hourly_workflow_count.rb index 23c7aca..592ff11 100644 --- a/db/migrate/20240926231325_create_data_retention_policy_for_hourly_workflow_count.rb +++ b/db/migrate/20240926231325_create_data_retention_policy_for_hourly_workflow_count.rb @@ -2,9 +2,15 @@ class CreateDataRetentionPolicyForHourlyWorkflowCount < ActiveRecord::Migration[7.0] disable_ddl_transaction! - def change + def up execute <<~SQL SELECT add_retention_policy('hourly_classification_count_per_workflow', drop_after => INTERVAL '3 days'); SQL end + + def down + execute <<~SQL + SELECT remove_retention_policy('hourly_classification_count_per_workflow'); + SQL + end end