Skip to content

Commit

Permalink
Merge pull request #8 from trusted/allow-disabling-tracking-on-ignored
Browse files Browse the repository at this point in the history
Allow disabling ignored tables
  • Loading branch information
andrepiske authored Dec 9, 2024
2 parents e331153 + 5dc37e5 commit 54f2aa1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 12 additions & 0 deletions lib/iron_trail/db_functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [])

Expand Down
13 changes: 13 additions & 0 deletions lib/tasks/tracking.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
18 changes: 18 additions & 0 deletions spec/iron_trail/db_functions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54f2aa1

Please sign in to comment.