Skip to content

Commit

Permalink
update migrations to be reversible
Browse files Browse the repository at this point in the history
  • Loading branch information
yuenmichelle1 committed Oct 8, 2024
1 parent 862dd9b commit 3bc6875
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3bc6875

Please sign in to comment.