frolic-trackless_triggers 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG +20 -0
- data/MIT-LICENSE +22 -0
- data/README +26 -0
- data/Rakefile +15 -0
- data/VERSION +1 -0
- data/init.rb +3 -0
- data/lib/trackless_triggers.rb +52 -0
- data/trackless_triggers.gemspec +44 -0
- metadata +63 -0
data/.gitignore
ADDED
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2007 Aaron Patterson (aaronp@rubyforge.org)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= Trigger Happy
|
2
|
+
|
3
|
+
Add triggers to your active record migrations.
|
4
|
+
|
5
|
+
== INSTALL
|
6
|
+
|
7
|
+
script/plugin install svn://rubyforge.org/var/svn/artriggers/trunk/trigger_happy
|
8
|
+
|
9
|
+
== EXAMPLE
|
10
|
+
|
11
|
+
Add a trigger:
|
12
|
+
|
13
|
+
add_trigger "ai_people",
|
14
|
+
:on => 'people',
|
15
|
+
:timing => 'after',
|
16
|
+
:event => 'insert',
|
17
|
+
:statement => 'INSERT INTO log (id, timestamp) VALUES (NEW.id, NOW())'
|
18
|
+
|
19
|
+
Remove a trigger:
|
20
|
+
|
21
|
+
drop_trigger 'ai_people'
|
22
|
+
|
23
|
+
== LIMITATIONS
|
24
|
+
|
25
|
+
Only works with mysql for now.
|
26
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |gemspec|
|
6
|
+
gemspec.name = "trackless_triggers"
|
7
|
+
gemspec.summary = "Adds support for MySQL triggers in ActiveRecord"
|
8
|
+
gemspec.description = "Adds support for MySQL triggers in ActiveRecord"
|
9
|
+
gemspec.email = "christian@perpenduum.com"
|
10
|
+
gemspec.homepage = "http://github.com/frolic/trackless-trigger"
|
11
|
+
gemspec.authors = ["Aaron Patterson","Christian Eager"]
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
15
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.6
|
data/init.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class SchemaDumper
|
5
|
+
private
|
6
|
+
alias trigger_old_tables tables
|
7
|
+
def tables(stream)
|
8
|
+
trigger_old_tables(stream)
|
9
|
+
@connection.tables.sort.each do |tbl|
|
10
|
+
next if (tbl == 'schema_info' || tbl == 'schema_migrations')
|
11
|
+
triggers(tbl, stream)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def triggers(table, stream)
|
16
|
+
triggers = @connection.triggers(table)
|
17
|
+
triggers.each do |trigger|
|
18
|
+
stream.print " add_trigger \"#{trigger.name}\", :on => \"#{trigger.reference_table}\", :timing => \"#{trigger.timing}\", :event => \"#{trigger.event}\", :statement => \"#{trigger.statement}\""
|
19
|
+
stream.puts
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module ConnectionAdapters
|
25
|
+
class TriggerDefinition < Struct.new(:name, :event, :reference_table,
|
26
|
+
:statement, :timing, :created,
|
27
|
+
:sql_mode, :definer, :character_set_client, :collation_connection, :database_collation
|
28
|
+
)
|
29
|
+
end
|
30
|
+
class MysqlAdapter < AbstractAdapter
|
31
|
+
def triggers(table, name = nil)
|
32
|
+
triggers = []
|
33
|
+
execute("SHOW TRIGGERS LIKE '#{table}'", name).each do |row|
|
34
|
+
triggers << TriggerDefinition.new(*row)
|
35
|
+
end
|
36
|
+
|
37
|
+
triggers
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module SchemaStatements
|
42
|
+
def add_trigger(name, opts = {})
|
43
|
+
sql = "CREATE TRIGGER #{name} #{opts[:timing]} #{opts[:event]} ON #{opts[:on]} FOR EACH ROW #{opts[:statement]}"
|
44
|
+
execute sql
|
45
|
+
end
|
46
|
+
|
47
|
+
def drop_trigger(name)
|
48
|
+
execute("DROP TRIGGER #{name}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{trackless_triggers}
|
8
|
+
s.version = "0.0.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Aaron Patterson", "Christian Eager"]
|
12
|
+
s.date = %q{2009-08-24}
|
13
|
+
s.description = %q{Adds support for MySQL triggers in ActiveRecord}
|
14
|
+
s.email = %q{christian@perpenduum.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"CHANGELOG",
|
21
|
+
"MIT-LICENSE",
|
22
|
+
"README",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"init.rb",
|
26
|
+
"lib/trackless_triggers.rb",
|
27
|
+
"trackless_triggers.gemspec"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/frolic/trackless-trigger}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.5}
|
33
|
+
s.summary = %q{Adds support for MySQL triggers in ActiveRecord}
|
34
|
+
|
35
|
+
if s.respond_to? :specification_version then
|
36
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
37
|
+
s.specification_version = 3
|
38
|
+
|
39
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
40
|
+
else
|
41
|
+
end
|
42
|
+
else
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: frolic-trackless_triggers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Patterson
|
8
|
+
- Christian Eager
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-08-24 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Adds support for MySQL triggers in ActiveRecord
|
18
|
+
email: christian@perpenduum.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- CHANGELOG
|
28
|
+
- MIT-LICENSE
|
29
|
+
- README
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- init.rb
|
33
|
+
- lib/trackless_triggers.rb
|
34
|
+
- trackless_triggers.gemspec
|
35
|
+
has_rdoc: false
|
36
|
+
homepage: http://github.com/frolic/trackless-trigger
|
37
|
+
licenses:
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Adds support for MySQL triggers in ActiveRecord
|
62
|
+
test_files: []
|
63
|
+
|