saseo 0.4.0 → 0.4.1

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
  SHA1:
3
- metadata.gz: 8d3227155157a0d8e3df890b3e066aea67e73d68
4
- data.tar.gz: 6673eb5e80dca1a684f97708e9f40bfced88b188
3
+ metadata.gz: dd8922670e32782ea4fb6f13bf50d9c2b9ef22e7
4
+ data.tar.gz: 6bde66f4b1505a25cb04809816203bf885ea4258
5
5
  SHA512:
6
- metadata.gz: 1f86a332905806cee8e96e3f00104a87fa48de5b1c391e7f9dcaeceaf9d17260e968da2ae1675f31d3fb59e0e5b14418937d55f80d5c1752875c4bd080503a2f
7
- data.tar.gz: 68206c9fa409dbdb4430ea92dab8824b7f7d3b9929b89d257506b20ec8f3783bc9317c31fa4ef082b3e21d807dc11f98fa5f951fb5b1cf04c835c2b1391b1b9e
6
+ metadata.gz: e188da5e002b2247c09f0a7708008141b92cf211f332511d58d9887bde0b8b35980af1dabad9ee776f3dd071f0006bcec455b5921d01994747a85f93f614556d
7
+ data.tar.gz: 5ef4b0ccc05fafbc654c845f4fcd03a6b8d336980f6ec1b412a57198800a796fa7ba64c03cff7f67f55b9fdb5899e44f2c61cb91484b557b1c731a3f65c21e4e
@@ -1,14 +1,16 @@
1
- class AddSaseoTriggerTo<%= @table_name.camelcase %> < ActiveRecord::Migration
1
+ class <%= @target_migration_name.camelcase %> < ActiveRecord::Migration
2
2
  def up
3
3
  # originally copied from:
4
4
  # https://wiki.postgresql.org/wiki/Audit_trigger
5
- trigger_definition = <<SQL
6
- CREATE TRIGGER <%= @table_name %>_saseo_trigger AFTER INSERT OR UPDATE OR DELETE ON <%= @table_name %> FOR EACH ROW EXECUTE PROCEDURE saseo.audit_func();
7
- SQL
8
- execute(trigger_definition)
5
+ <% @table_names.each do |table_name| %>
6
+ execute('DROP TRIGGER IF EXISTS <%= table_name %>_saseo_trigger ON <%= table_name %> CASCADE')
7
+ execute('CREATE TRIGGER <%= table_name %>_saseo_trigger AFTER INSERT OR UPDATE OR DELETE ON <%= table_name %> FOR EACH ROW EXECUTE PROCEDURE saseo.audit_func()')
8
+ <% end %>
9
9
  end
10
10
 
11
11
  def down
12
- execute('DROP TRIGGER <%= @table_name %>_saseo_trigger ON <%= @table_name %> CASCADE;')
12
+ <% @table_names.each do |table_name| %>
13
+ execute('DROP TRIGGER IF EXISTS <%= table_name %>_saseo_trigger ON <%= table_name %> CASCADE')
14
+ <% end %>
13
15
  end
14
16
  end
@@ -17,10 +17,8 @@ module Saseo
17
17
  tables = Saseo::Models::Source::Base.connection.tables if tables.include? 'all'
18
18
  tables -= [Saseo.config.source_table_name, Saseo.config.table_name]
19
19
 
20
- tables.each do |table_name|
21
- @table_name = table_name
22
- add_saseo_migration("add_saseo_trigger")
23
- end
20
+ @table_names = tables
21
+ add_saseo_migration("add_saseo_trigger")
24
22
  end
25
23
 
26
24
  def self.next_migration_number(dirname)
@@ -30,9 +28,14 @@ module Saseo
30
28
  protected
31
29
  def add_saseo_migration(template)
32
30
  migration_dir = File.expand_path('db/migrate')
31
+ if @table_names.count > 1
32
+ @target_migration_name = "#{template}_to_#{@table_names.first}_and_#{@table_names.count - 1}_others"
33
+ else
34
+ @target_migration_name = "#{template}_to_#{@table_names.first}"
35
+ end
33
36
 
34
- unless self.class.migration_exists?(migration_dir, template)
35
- migration_template "#{template}.rb.erb", "db/migrate/#{template}_to_#{@table_name}.rb"
37
+ unless self.class.migration_exists?(migration_dir, @target_migration_name)
38
+ migration_template "#{template}.rb.erb", "db/migrate/#{@target_migration_name}.rb"
36
39
  else
37
40
  warn("ALERT: Migration already exists named '#{template}'." +
38
41
  " Please check your migrations directory before re-running")
data/lib/saseo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Saseo
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saseo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Keyes