diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..de0ceeb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +- Added means to disable tracking ignored tables + +## 0.0.1 - 2024-11-26 + +Initial release. diff --git a/lib/iron_trail/db_functions.rb b/lib/iron_trail/db_functions.rb index ee41e0f..6c7bc5e 100644 --- a/lib/iron_trail/db_functions.rb +++ b/lib/iron_trail/db_functions.rb @@ -83,6 +83,18 @@ def enable_for_all_missing_tables end end + def disable_for_all_ignored_tables + affected_tables = collect_tracked_table_names & ( + OWN_TABLES + (IronTrail.config.ignored_tables || []) + ) + + affected_tables.each do |table_name| + disable_tracking_for_table(table_name) + end + + affected_tables + end + def collect_tables_tracking_status ignored_tables = OWN_TABLES + (IronTrail.config.ignored_tables || []) diff --git a/lib/tasks/tracking.rake b/lib/tasks/tracking.rake index 508d721..7ad08d4 100644 --- a/lib/tasks/tracking.rake +++ b/lib/tasks/tracking.rake @@ -35,6 +35,19 @@ namespace :iron_trail do end end + desc 'Disabled tracking for any ignored table that might still have the trigger enabled.' + task disable_on_ignored: :environment do + affected_tables = IronTrail::RakeHelper.db_functions.disable_for_all_ignored_tables + + unless affected_tables.empty? + puts "Removed tracking from #{affected_tables.length} tables:" + + affected_tables.each do |table_name| + puts "\t#{table_name}" + end + end + end + desc 'Disables tracking all tables. Dangerous!' task disable: :environment do IronTrail::RakeHelper.abort_when_unsafe! diff --git a/spec/iron_trail/db_functions_spec.rb b/spec/iron_trail/db_functions_spec.rb index de90211..3151fec 100644 --- a/spec/iron_trail/db_functions_spec.rb +++ b/spec/iron_trail/db_functions_spec.rb @@ -117,6 +117,24 @@ end end + describe '#disable_for_all_ignored_tables' do + subject(:disable_it!) do + instance.disable_for_all_ignored_tables + end + + context 'when no ignored tables are tracked' do + it 'returns an empty array' do + expect(disable_it!).to eq([]) + end + + it 'does not call disable_tracking_for_table' do + expect(instance).to receive(:disable_tracking_for_table).exactly(0).times + + disable_it! + end + end + end + describe 'function creation and removal' do context 'with default setup' do it 'has the function present' do