hairtrigger 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d99ce209cb3572d2bcc2987758e5887b203f3fdf50ef295b18169a9f030d0d3a
4
- data.tar.gz: 8e79c7bf238ebb1339bdefce635eb47050d509faad270c4af88d39a7ba89a8a3
3
+ metadata.gz: adffb212907d4617f9ed63b3bbed32f0f4c8e7113e50284eb560a2e9ac0f24cb
4
+ data.tar.gz: a437870c199e11d4264e496ac45ff6d6f61593e80b9082bc8bf320de33bd0b84
5
5
  SHA512:
6
- metadata.gz: ffee9a6cac525abb8d0d7e49ec3f78877b54cdbfcaa77a2e2c5b6ac86d4b87401e02f0b54da8a62ebd8029d35ad7d0e798cdbcae34c9db429a4dea5d05aa8e51
7
- data.tar.gz: d0c6a189591d1e0722fcbd72b51392efacd222734ae7da513f2f8da651f9c9ed5cf035174d6af04cb1206913873329cf3d8ec645d722810df86889030586ab96
6
+ metadata.gz: cf089ae92b9427a39243f6c096c44eab7ea4d41e7e6bec757781ba2d9b5ebef09683b2528e8ce39c2c28b15919149b82461bd2edcef4d662161a28a52c24671f
7
+ data.tar.gz: 83c64e0d188cfc45a6ffb701e6f5ee56350d4b636eaaa106405d545731563cc3751e792eecd6eefc1f4d534fdfd31369099e8a9875cec63082ce91d6d753118a
data/README.md CHANGED
@@ -202,6 +202,15 @@ you need to actually implement `up`/`down` methods in your migration
202
202
  (rather than `change`) so that it does the right thing when
203
203
  rolling back.
204
204
 
205
+ The `drop_trigger` currently only supports the `drop_trigger(name, table, options = {})`
206
+ format. You will need to determine what the resulting trigger name is (e.g. `SHOW TRIGGERS`
207
+ query) and use that name in the `drop_triggers` call. Your `down` migration method
208
+ might contain something like:
209
+
210
+ ```ruby
211
+ drop_trigger(:users_after_insert_row_tr, :transactions)
212
+ ```
213
+
205
214
  #### Manual triggers and :compatibility
206
215
 
207
216
  As bugs are fixed and features are implemented in HairTrigger, it's possible
@@ -31,7 +31,7 @@ module HairTrigger
31
31
  select_rows("SELECT name, sql FROM sqlite_master WHERE type = 'trigger' #{name_clause ? " AND name " + name_clause : ""}").each do |(name, definition)|
32
32
  triggers[name] = quote_table_name_in_trigger(definition) + ";\n"
33
33
  end
34
- when :mysql
34
+ when :mysql, :trilogy
35
35
  select_rows("SHOW TRIGGERS").each do |(name, event, table, actions, timing, created, sql_mode, definer)|
36
36
  definer = normalize_mysql_definer(definer)
37
37
  next if options[:only] && !options[:only].include?(name)
@@ -48,7 +48,7 @@ FOR EACH ROW
48
48
  SELECT tgfoid
49
49
  FROM pg_trigger
50
50
  WHERE NOT tgisinternal AND tgconstrrelid = 0 AND tgrelid IN (
51
- SELECT oid FROM pg_class WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'public')
51
+ SELECT oid FROM pg_class WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = '#{HairTrigger.pg_schema}')
52
52
  )
53
53
  )
54
54
  SQL
@@ -57,9 +57,9 @@ FOR EACH ROW
57
57
  SELECT tgname::varchar, pg_get_triggerdef(oid, true)
58
58
  FROM pg_trigger
59
59
  WHERE NOT tgisinternal AND tgconstrrelid = 0 AND tgrelid IN (
60
- SELECT oid FROM pg_class WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'public')
60
+ SELECT oid FROM pg_class WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = '#{HairTrigger.pg_schema}')
61
61
  )
62
-
62
+
63
63
  #{name_clause ? " AND tgname::varchar " + name_clause : ""}
64
64
  UNION
65
65
  SELECT proname || '()', pg_get_functiondef(oid)
@@ -162,7 +162,7 @@ module HairTrigger
162
162
  chainable_methods :name, :on, :for_each, :before, :after, :where, :security, :timing, :events, :all, :nowrap, :of, :declare
163
163
 
164
164
  def create_grouped_trigger?
165
- adapter_name == :mysql
165
+ adapter_name == :mysql || adapter_name == :trilogy
166
166
  end
167
167
 
168
168
  def prepare!
@@ -224,7 +224,7 @@ module HairTrigger
224
224
  [case adapter_name
225
225
  when :sqlite
226
226
  generate_trigger_sqlite
227
- when :mysql
227
+ when :mysql, :trilogy
228
228
  generate_trigger_mysql
229
229
  when :postgresql, :postgis
230
230
  generate_trigger_postgresql
@@ -407,7 +407,7 @@ module HairTrigger
407
407
 
408
408
  def generate_drop_trigger
409
409
  case adapter_name
410
- when :sqlite, :mysql
410
+ when :sqlite, :mysql, :trilogy
411
411
  "DROP TRIGGER IF EXISTS #{prepared_name};\n"
412
412
  when :postgresql, :postgis
413
413
  "DROP TRIGGER IF EXISTS #{prepared_name} ON #{adapter.quote_table_name(options[:table])};\nDROP FUNCTION IF EXISTS #{adapter.quote_table_name(prepared_name)}();\n"
@@ -1,5 +1,5 @@
1
1
  module HairTrigger
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.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
@@ -13,7 +13,7 @@ module HairTrigger
13
13
  autoload :MigrationReader, 'hair_trigger/migration_reader'
14
14
 
15
15
  class << self
16
- attr_writer :model_path, :schema_rb_path, :migration_path
16
+ attr_writer :model_path, :schema_rb_path, :migration_path, :pg_schema
17
17
 
18
18
  def current_triggers
19
19
  # see what the models say there should be
@@ -223,6 +223,10 @@ end
223
223
  @migration_path ||= 'db/migrate'
224
224
  end
225
225
 
226
+ def pg_schema
227
+ @pg_schema ||= 'public'
228
+ end
229
+
226
230
  def adapter_name_for(adapter)
227
231
  adapter.adapter_name.downcase.sub(/\d$/, '').to_sym
228
232
  end
@@ -11,13 +11,46 @@ namespace :db do
11
11
  namespace :schema do
12
12
  desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
13
13
  task :dump => :environment do
14
+ next unless ActiveRecord::Base.schema_format == :ruby
15
+
14
16
  require 'active_record/schema_dumper'
15
- filename = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
16
- ActiveRecord::SchemaDumper.previous_schema = File.exist?(filename) ? File.read(filename) : nil
17
- File.open(filename, "w") do |file|
18
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
17
+
18
+ databases = ActiveRecord::Tasks::DatabaseTasks.setup_initial_database_yaml
19
+
20
+ ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
21
+ db_config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: name)
22
+ connection_pool = ActiveRecord::Base.establish_connection(db_config)
23
+
24
+ filename = dump_filename(db_config.name)
25
+ ActiveRecord::SchemaDumper.previous_schema = File.exist?(filename) ? File.read(filename) : nil
26
+
27
+ File.open(filename, "w") do |file|
28
+ ActiveRecord::SchemaDumper.dump(connection_pool.connection, file)
29
+ end
19
30
  end
31
+
20
32
  Rake::Task["db:schema:dump"].reenable
21
33
  end
34
+
35
+ def schema_file_type(format)
36
+ case format
37
+ when :ruby
38
+ "schema.rb"
39
+ when :sql
40
+ "structure.sql"
41
+ end
42
+ end
43
+
44
+ # code adopted from activerecord/lib/active_record/tasks/database_tasks.rb#L441
45
+ def dump_filename(db_config_name)
46
+ format = ActiveRecord::Base.schema_format
47
+ filename = if ActiveRecord::Base.configurations.primary?(db_config_name)
48
+ schema_file_type(format)
49
+ else
50
+ "#{db_config_name}_#{schema_file_type(format)}"
51
+ end
52
+
53
+ ENV["SCHEMA"] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, filename)
54
+ end
22
55
  end
23
56
  end
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: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-13 00:00:00.000000000 Z
11
+ date: 2024-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -91,14 +91,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
- version: 2.5.0
94
+ version: '3.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
- rubygems_version: 3.3.3
101
+ rubygems_version: 3.5.3
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: easy database triggers for active record