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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd8922670e32782ea4fb6f13bf50d9c2b9ef22e7
|
4
|
+
data.tar.gz: 6bde66f4b1505a25cb04809816203bf885ea4258
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e188da5e002b2247c09f0a7708008141b92cf211f332511d58d9887bde0b8b35980af1dabad9ee776f3dd071f0006bcec455b5921d01994747a85f93f614556d
|
7
|
+
data.tar.gz: 5ef4b0ccc05fafbc654c845f4fcd03a6b8d336980f6ec1b412a57198800a796fa7ba64c03cff7f67f55b9fdb5899e44f2c61cb91484b557b1c731a3f65c21e4e
|
@@ -1,14 +1,16 @@
|
|
1
|
-
class
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
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
|
-
|
21
|
-
|
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,
|
35
|
-
migration_template "#{template}.rb.erb", "db/migrate/#{
|
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