hairtrigger 0.2.24 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b3a4b255f8184decc442a9c455f5b8a5a5c9bd48
4
- data.tar.gz: b6c202c7328de121c67161cc4d31d83926076044
2
+ SHA256:
3
+ metadata.gz: d99ce209cb3572d2bcc2987758e5887b203f3fdf50ef295b18169a9f030d0d3a
4
+ data.tar.gz: 8e79c7bf238ebb1339bdefce635eb47050d509faad270c4af88d39a7ba89a8a3
5
5
  SHA512:
6
- metadata.gz: 5eb6f48db749f2841ee9a0b986dbaf9cf2d93f48f687822e8a6dda52c90e45165fba783510e7fb1e5ec8a490ce4a6dd58df5f2ebd04567e3d2839f87ef82815f
7
- data.tar.gz: c8eebfc8a7a45d4987f1d6ea5281a06c333a4eee929830a73a78521c442983b1743f14a4f677fb31de9d4a7ce6b144f67000f84cd7c068d08160ef260bb815cf
6
+ metadata.gz: ffee9a6cac525abb8d0d7e49ec3f78877b54cdbfcaa77a2e2c5b6ac86d4b87401e02f0b54da8a62ebd8029d35ad7d0e798cdbcae34c9db429a4dea5d05aa8e51
7
+ data.tar.gz: d0c6a189591d1e0722fcbd72b51392efacd222734ae7da513f2f8da651f9c9ed5cf035174d6af04cb1206913873329cf3d8ec645d722810df86889030586ab96
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2015 Jon Jensen
1
+ Copyright (c) 2011-2022 Jon Jensen
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # HairTrigger
2
- [<img src="https://secure.travis-ci.org/jenseng/hair_trigger.svg?branch=master" />](http://travis-ci.org/jenseng/hair_trigger)
2
+ [<img src="https://github.com/jenseng/hair_trigger/workflows/CI/badge.svg" />](https://github.com/jenseng/hair_trigger/actions?query=workflow%3ACI)
3
3
 
4
4
  HairTrigger lets you create and manage database triggers in a concise,
5
5
  db-agnostic, Rails-y way. You declare triggers right in your models in Ruby,
@@ -101,10 +101,10 @@ Only fire the update trigger if at least one of the columns is specified in the
101
101
  Permissions/role to check when calling trigger. PostgreSQL supports `:invoker` (default) and `:definer`, MySQL supports `:definer` (default) and arbitrary users (syntax: `'user'@'host'`).
102
102
 
103
103
  #### timing(timing)
104
- Required (but may be satisified by `before`/`after`). Possible values are `:before`/`:after`.
104
+ Required (but may be satisfied by `before`/`after`). Possible values are `:before`/`:after`.
105
105
 
106
106
  #### events(*events)
107
- Required (but may be satisified by `before`/`after`). Possible values are `:insert`/`:update`/`:delete`/`:truncate`. MySQL/SQLite only support one action per trigger, and don't support `:truncate`.
107
+ Required (but may be satisfied by `before`/`after`). Possible values are `:insert`/`:update`/`:delete`/`:truncate`. MySQL/SQLite only support one action per trigger, and don't support `:truncate`.
108
108
 
109
109
  #### nowrap(flag = true)
110
110
  PostgreSQL-specific option to prevent the trigger action from being wrapped in a `CREATE FUNCTION`. This is useful for executing existing triggers/functions directly, but is not compatible with the `security` setting nor can it be used with pre-9.0 PostgreSQL when supplying a `where` condition.
@@ -240,6 +240,21 @@ As long as you don't delete old migrations and schema.rb prior to running
240
240
  If you have deleted all trigger migrations, you can regenerate a new
241
241
  baseline for model triggers via `rake db:generate_trigger_migration`.
242
242
 
243
+ ### Filtering
244
+
245
+ It is possible to filter which triggers are dumped by setting any of these
246
+ configuration values:
247
+
248
+ ```ruby
249
+ HairTrigger::SchemaDumper::Configuration.ignore_triggers = 'exact_trigger_name'
250
+ HairTrigger::SchemaDumper::Configuration.ignore_tables = [/partial_/, 'exact_table_name']
251
+ HairTrigger::SchemaDumper::Configuration.allow_triggers = [/partial_/, 'exact_trigger_name']
252
+ HairTrigger::SchemaDumper::Configuration.allow_tables = 'exact_table_name'
253
+ ```
254
+
255
+ Each option can accept a single String or Regexp, or a mixed array of both.
256
+
257
+
243
258
  ## Testing
244
259
 
245
260
  To stay on top of things, it's strongly recommended that you add a test or
@@ -327,10 +342,10 @@ gem in years 😬) but am happy to take contributions. If I'm slow to respond, d
327
342
  hesitate to @ me repeatedly, sometimes those github notifications slip through
328
343
  the cracks. 😆.
329
344
 
330
- If you want to add a feature/bugfix, you can rely on Travis to run the tests, but
331
- do also run them locally (especially if you are changing supported railses/etc).
332
- HairTrigger uses [appraisal](https://github.com/thoughtbot/appraisal) to manage all
333
- that w/ automagical gemfiles. So the tl;dr when testing locally is:
345
+ If you want to add a feature/bugfix, you can rely on Github Actions to run the
346
+ tests, but do also run them locally (especially if you are changing supported
347
+ railses/etc). HairTrigger uses [appraisal](https://github.com/thoughtbot/appraisal)
348
+ to manage all that w/ automagical gemfiles. So the tl;dr when testing locally is:
334
349
 
335
350
  1. make sure you have mysql and postgres installed (homebrew or whatever)
336
351
  2. `bundle exec appraisal install` -- get all the dependencies
@@ -348,4 +363,4 @@ that w/ automagical gemfiles. So the tl;dr when testing locally is:
348
363
 
349
364
  ## Copyright
350
365
 
351
- Copyright (c) 2011-2021 Jon Jensen. See LICENSE.txt for further details.
366
+ Copyright (c) 2011-2022 Jon Jensen. See LICENSE.txt for further details.
@@ -1,5 +1,12 @@
1
1
  module HairTrigger
2
2
  module SchemaDumper
3
+ module Configuration
4
+ mattr_accessor :allow_tables
5
+ mattr_accessor :allow_triggers
6
+ mattr_accessor :ignore_tables
7
+ mattr_accessor :ignore_triggers
8
+ end
9
+
3
10
  module TrailerWithTriggersSupport
4
11
  def trailer(stream)
5
12
  orig_show_warnings = Builder.show_warnings
@@ -91,9 +98,35 @@ module HairTrigger
91
98
  end
92
99
 
93
100
  def whitelist_triggers(triggers)
94
- triggers.reject do |name, source|
101
+ triggers = triggers.reject do |name, source|
95
102
  ActiveRecord::SchemaDumper.ignore_tables.any? { |ignored_table_name| source =~ /ON\s+#{@connection.quote_table_name(ignored_table_name)}\s/ }
96
103
  end
104
+
105
+ if Configuration.allow_tables.present?
106
+ triggers = triggers.select do |name, source|
107
+ Array(Configuration.allow_tables).any? { |allowed_table_name| source =~ /ON\s+#{@connection.quote_table_name(allowed_table_name)}\s/ }
108
+ end
109
+ end
110
+
111
+ if Configuration.allow_triggers.present?
112
+ triggers = triggers.select do |name, source|
113
+ Array(Configuration.allow_triggers).any? { |allowed_trigger_name| allowed_trigger_name === name } # Triple equals to allow regexps or strings as allowed_trigger_name
114
+ end
115
+ end
116
+
117
+ if Configuration.ignore_tables.present?
118
+ triggers = triggers.reject do |name, source|
119
+ Array(Configuration.ignore_tables).any? { |allowed_table_name| source =~ /ON\s+#{@connection.quote_table_name(allowed_table_name)}\s/ }
120
+ end
121
+ end
122
+
123
+ if Configuration.ignore_triggers.present?
124
+ triggers = triggers.reject do |name, source|
125
+ Array(Configuration.ignore_triggers).any? { |allowed_trigger_name| allowed_trigger_name === name } # Triple equals to allow regexps or strings as allowed_trigger_name
126
+ end
127
+ end
128
+
129
+ triggers
97
130
  end
98
131
 
99
132
  def self.included(base)
@@ -1,5 +1,5 @@
1
1
  module HairTrigger
2
- VERSION = "0.2.24"
2
+ VERSION = "1.0.0"
3
3
 
4
4
  def VERSION.<=>(other)
5
5
  split(/\./).map(&:to_i) <=> other.split(/\./).map(&:to_i)
data/lib/hair_trigger.rb CHANGED
@@ -39,19 +39,14 @@ module HairTrigger
39
39
  end
40
40
 
41
41
  def migrator
42
- version = ActiveRecord::VERSION::STRING
43
- if version >= "6.0."
42
+ if ActiveRecord::VERSION::STRING >= "7.1."
43
+ connection = ActiveRecord::Tasks::DatabaseTasks.migration_connection
44
+ schema_migration = connection.schema_migration
45
+ migrations = ActiveRecord::MigrationContext.new(migration_path, schema_migration).migrations
46
+ ActiveRecord::Migrator.new(:up, migrations, schema_migration, ActiveRecord::InternalMetadata.new(connection))
47
+ else
44
48
  migrations = ActiveRecord::MigrationContext.new(migration_path, ActiveRecord::SchemaMigration).migrations
45
- elsif version >= "5.2."
46
- migrations = ActiveRecord::MigrationContext.new(migration_path).migrations
47
- else # version >= "4.0."
48
- migrations = ActiveRecord::Migrator.migrations(migration_path)
49
- end
50
-
51
- if version >= "6.0."
52
49
  ActiveRecord::Migrator.new(:up, migrations, ActiveRecord::SchemaMigration)
53
- else
54
- ActiveRecord::Migrator.new(:up, migrations)
55
50
  end
56
51
  end
57
52
 
@@ -62,7 +57,7 @@ module HairTrigger
62
57
  options[:skip_pending_migrations] = true
63
58
  end
64
59
 
65
- # if we're in a db:schema:dump task (explict or kicked off by db:migrate),
60
+ # if we're in a db:schema:dump task (explicit or kicked off by db:migrate),
66
61
  # we evaluate the previous schema.rb (if it exists), and then all applied
67
62
  # migrations in order (even ones older than schema.rb). this ensures we
68
63
  # handle db:migrate:down scenarios correctly
@@ -82,7 +77,7 @@ module HairTrigger
82
77
  if previous_schema = (options.has_key?(:previous_schema) ? options[:previous_schema] : File.exist?(schema_rb_path) && File.read(schema_rb_path))
83
78
  base_triggers = MigrationReader.get_triggers(previous_schema, options)
84
79
  unless base_triggers.empty?
85
- version = (previous_schema =~ /ActiveRecord::Schema\.define\(.*?(\d+)\)/) && $1.to_i
80
+ version = (previous_schema =~ /ActiveRecord::Schema(\[\d\.\d\])?\.define\(version\: (.*)\)/) && $2.to_i
86
81
  migrations.unshift [OpenStruct.new({:version => version}), base_triggers]
87
82
  end
88
83
  end
@@ -200,8 +195,16 @@ end
200
195
  "#{migration_base_name}#{name_version}"
201
196
  end
202
197
 
198
+ def timestamped_migrations
199
+ if ActiveRecord::VERSION::STRING >= "7.0."
200
+ ActiveRecord.timestamped_migrations
201
+ else
202
+ ActiveRecord::Base.timestamped_migrations
203
+ end
204
+ end
205
+
203
206
  def infer_migration_version(migration_name)
204
- ActiveRecord::Base.timestamped_migrations ?
207
+ timestamped_migrations ?
205
208
  Time.now.getutc.strftime("%Y%m%d%H%M%S") :
206
209
  Dir.glob(migration_path + '/*rb').
207
210
  map{ |f| f.gsub(/.*\/(\d+)_.*/, '\1').to_i}.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hairtrigger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.24
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-01 00:00:00.000000000 Z
11
+ date: 2022-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '6.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7'
22
+ version: '8'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '5.0'
29
+ version: '6.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7'
32
+ version: '8'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: ruby_parser
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +83,7 @@ homepage: http://github.com/jenseng/hair_trigger
83
83
  licenses:
84
84
  - MIT
85
85
  metadata: {}
86
- post_install_message:
86
+ post_install_message:
87
87
  rdoc_options: []
88
88
  require_paths:
89
89
  - lib
@@ -91,16 +91,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
- version: 2.3.0
94
+ version: 2.5.0
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
97
  - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubyforge_project:
102
- rubygems_version: 2.5.2.3
103
- signing_key:
101
+ rubygems_version: 3.3.3
102
+ signing_key:
104
103
  specification_version: 4
105
104
  summary: easy database triggers for active record
106
105
  test_files: []