From 14432ded5954a9cf46dc3c40faa62857dfef63db Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Tue, 4 Apr 2023 11:09:45 -0700 Subject: [PATCH] Ensure methods with kwargs are invertible --- .../active_record/command_recorder.rb | 71 ++++++------------- .../active_record/schema_statements.rb | 4 +- 2 files changed, 23 insertions(+), 52 deletions(-) diff --git a/lib/timescaledb/rails/extensions/active_record/command_recorder.rb b/lib/timescaledb/rails/extensions/active_record/command_recorder.rb index 207acc7..eba764c 100644 --- a/lib/timescaledb/rails/extensions/active_record/command_recorder.rb +++ b/lib/timescaledb/rails/extensions/active_record/command_recorder.rb @@ -5,56 +5,27 @@ module Rails module ActiveRecord # :nodoc: module CommandRecorder - def create_hypertable(*args, &block) - record(:create_hypertable, args, &block) - end - - def enable_hypertable_compression(*args, &block) - record(:enable_hypertable_compression, args, &block) - end - - def disable_hypertable_compression(*args, &block) - record(:disable_hypertable_compression, args, &block) - end - - def add_hypertable_compression_policy(*args, &block) - record(:add_hypertable_compression_policy, args, &block) - end - - def remove_hypertable_compression_policy(*args, &block) - record(:remove_hypertable_compression_policy, args, &block) - end - - def add_hypertable_reorder_policy(*args, &block) - record(:add_hypertable_reorder_policy, args, &block) - end - - def remove_hypertable_reorder_policy(*args, &block) - record(:remove_hypertable_reorder_policy, args, &block) - end - - def add_hypertable_retention_policy(*args, &block) - record(:add_hypertable_retention_policy, args, &block) - end - - def remove_hypertable_retention_policy(*args, &block) - record(:remove_hypertable_retention_policy, args, &block) - end - - def create_continuous_aggregate(*args, &block) - record(:create_continuous_aggregate, args, &block) - end - - def drop_continuous_aggregate(*args, &block) - record(:drop_continuous_aggregate, args, &block) - end - - def add_continuous_aggregate_policy(*args, &block) - record(:add_continuous_aggregate_policy, args, &block) - end - - def remove_continuous_aggregate_policy(*args, &block) - record(:remove_continuous_aggregate_policy, args, &block) + %w[ + create_hypertable + enable_hypertable_compression + disable_hypertable_compression + add_hypertable_compression_policy + remove_hypertable_compression_policy + add_hypertable_reorder_policy + remove_hypertable_reorder_policy + add_hypertable_retention_policy + remove_hypertable_retention_policy + create_continuous_aggregate + drop_continuous_aggregate + add_continuous_aggregate_policy + remove_continuous_aggregate_policy + ].each do |method| + module_eval <<-METHOD, __FILE__, __LINE__ + 1 + def #{method}(*args, &block) # def create_table(*args, &block) + record(:"#{method}", args, &block) # record(:create_table, args, &block) + end # end + METHOD + ruby2_keywords(method) end def invert_create_hypertable(args, &block) diff --git a/lib/timescaledb/rails/extensions/active_record/schema_statements.rb b/lib/timescaledb/rails/extensions/active_record/schema_statements.rb index 196e2ca..4b79296 100644 --- a/lib/timescaledb/rails/extensions/active_record/schema_statements.rb +++ b/lib/timescaledb/rails/extensions/active_record/schema_statements.rb @@ -56,7 +56,7 @@ def enable_hypertable_compression(table_name, segment_by: nil, order_by: nil) # # disable_hypertable_compression('events') # - def disable_hypertable_compression(table_name, _segment_by: nil, _order_by: nil) + def disable_hypertable_compression(table_name, segment_by: nil, order_by: nil) # rubocop:disable Lint/UnusedMethodArgument execute "ALTER TABLE #{table_name} SET (timescaledb.compress = false);" end @@ -131,7 +131,7 @@ def create_continuous_aggregate(view_name, view_query, force: false) # # drop_continuous_aggregate('temperature_events') # - def drop_continuous_aggregate(view_name, _view_query = nil) + def drop_continuous_aggregate(view_name, _view_query = nil, force: false) # rubocop:disable Lint/UnusedMethodArgument execute "DROP MATERIALIZED VIEW #{view_name};" end