dbuddy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.textile +33 -0
- data/Rakefile +2 -0
- data/bin/dbuddy +46 -0
- data/dbuddy.gemspec +21 -0
- data/lib/dbuddy/version.rb +3 -0
- data/lib/dbuddy.rb +14 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.textile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
h1. DBuddy
|
2
|
+
|
3
|
+
Have stored procedures or view definitions in your application? Wouldn't it be great if you could keep those with the rest of your code?
|
4
|
+
|
5
|
+
DBuddy is a small script that does two things to streamline this process:
|
6
|
+
|
7
|
+
# Loads all of the SQL files matching one or more globs
|
8
|
+
# Watches over those files and reloads them on changes
|
9
|
+
|
10
|
+
h2. Usage
|
11
|
+
|
12
|
+
Loading:
|
13
|
+
|
14
|
+
<pre><code>
|
15
|
+
dbuddy db/views/*.sql db/procedures/*.sql
|
16
|
+
</code></pre>
|
17
|
+
|
18
|
+
Watching:
|
19
|
+
|
20
|
+
<pre><code>
|
21
|
+
dbuddy --watch db/views/*.sql db/procedures/*.sql
|
22
|
+
dbuddy -w db/views/*.sql db/procedures/*.sql
|
23
|
+
</code></pre>
|
24
|
+
|
25
|
+
From code (e.g. rake task)
|
26
|
+
|
27
|
+
<pre><code>
|
28
|
+
DBuddy.run(ActiveRecord::Base.connection, Dir.glob("db/views/*.sql") + Dir.glob("db/procedures/*.sql"))
|
29
|
+
</code></pre>
|
30
|
+
|
31
|
+
h2. TODOs
|
32
|
+
|
33
|
+
* Right now it assumes it's being run in the root of a Rails project and loads config/environment.rb. This could be improved, but right now I don't have a use case.
|
data/Rakefile
ADDED
data/bin/dbuddy
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'watchr'
|
6
|
+
|
7
|
+
$:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
|
8
|
+
require "dbuddy"
|
9
|
+
|
10
|
+
@watch = false
|
11
|
+
|
12
|
+
opts = OptionParser.new
|
13
|
+
opts.on("-w", "--watch") { @watch = true }
|
14
|
+
@globs = opts.parse(ARGV)
|
15
|
+
|
16
|
+
# Assumes it's in a Rails environment. Eventually I could see adding some kind of config file or initializer that
|
17
|
+
# allows use with any project, but I don't need that right now.
|
18
|
+
require File.join(Dir.pwd, 'config/environment')
|
19
|
+
|
20
|
+
|
21
|
+
if @watch
|
22
|
+
script = Watchr::Script.new
|
23
|
+
|
24
|
+
@globs.each do |glob|
|
25
|
+
puts "Watching #{glob}"
|
26
|
+
|
27
|
+
script.watch(glob) do |path|
|
28
|
+
puts "Reloading #{path}"
|
29
|
+
DBuddy.run(ActiveRecord::Base.connection, path.to_s)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Watchr::Controller.new(script, Watchr.handler.new).run
|
34
|
+
else
|
35
|
+
@globs.each do |glob|
|
36
|
+
puts "Running #{glob}"
|
37
|
+
|
38
|
+
DBuddy.run(ActiveRecord::Base.connection, *Dir.glob(glob))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Signal.trap 'INT' do
|
43
|
+
# puts " Shutting down now"
|
44
|
+
# exit
|
45
|
+
# end
|
46
|
+
|
data/dbuddy.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "dbuddy/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "dbuddy"
|
7
|
+
s.version = DBuddy::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Andrew O'Brien"]
|
10
|
+
s.email = ["andrew@econify.com"]
|
11
|
+
s.homepage = "http://github.com/AndrewO/dbuddy"
|
12
|
+
s.summary = %q{Got stored procedures and views in your repo? Loading them should be simple.}
|
13
|
+
s.description = %q{A small script to watch over bunches of raw SQL files and load them on changes. Or just load a bunch at once.}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency("watchr")
|
21
|
+
end
|
data/lib/dbuddy.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module DBuddy
|
2
|
+
def self.run(connection, *paths)
|
3
|
+
paths.each do |path|
|
4
|
+
puts "Processing #{path}"
|
5
|
+
begin
|
6
|
+
connection.execute(File.read(path), "DBuddy: Reloading #{path}")
|
7
|
+
rescue => e
|
8
|
+
puts "Caught error"
|
9
|
+
puts e.message
|
10
|
+
puts e.backtrace
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dbuddy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andrew O'Brien
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-16 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: watchr
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: A small script to watch over bunches of raw SQL files and load them on changes. Or just load a bunch at once.
|
35
|
+
email:
|
36
|
+
- andrew@econify.com
|
37
|
+
executables:
|
38
|
+
- dbuddy
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- README.textile
|
47
|
+
- Rakefile
|
48
|
+
- bin/dbuddy
|
49
|
+
- dbuddy.gemspec
|
50
|
+
- lib/dbuddy.rb
|
51
|
+
- lib/dbuddy/version.rb
|
52
|
+
homepage: http://github.com/AndrewO/dbuddy
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.5
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Got stored procedures and views in your repo? Loading them should be simple.
|
85
|
+
test_files: []
|
86
|
+
|