database_operations 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem 'rake'
10
+ gem "minitest"
11
+ gem "yard"
12
+ gem "bundler"
13
+ gem "jeweler"
14
+ gem "rcov"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ minitest (2.10.0)
10
+ rake (0.9.2.2)
11
+ rcov (0.9.11)
12
+ yard (0.7.4)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler
19
+ jeweler
20
+ minitest
21
+ rake
22
+ rcov
23
+ yard
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Renewable Funding, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = better_newrelic_sql_obfuscator
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to better_newrelic_sql_obfuscator
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Renewable Funding, LLC. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "database_operations"
18
+ gem.homepage = "http://github.com/projectdx/database_operations"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Operate the database}
21
+ gem.description = %Q{see Summary}
22
+ gem.email = "devteam@renewfund.com"
23
+ gem.authors = ["Renewable Funding, LLC"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'yard'
46
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.5
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
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 = "database_operations"
8
+ s.version = "0.0.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Renewable Funding, LLC"]
12
+ s.date = "2012-05-15"
13
+ s.description = "see Summary"
14
+ s.email = "devteam@renewfund.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "database_operations.gemspec",
27
+ "lib/database_operations.rb",
28
+ "lib/projectdx/tasks.rb"
29
+ ]
30
+ s.homepage = "http://github.com/projectdx/database_operations"
31
+ s.licenses = ["MIT"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = "1.8.23"
34
+ s.summary = "Operate the database"
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_development_dependency(%q<rake>, [">= 0"])
41
+ s.add_development_dependency(%q<minitest>, [">= 0"])
42
+ s.add_development_dependency(%q<yard>, [">= 0"])
43
+ s.add_development_dependency(%q<bundler>, [">= 0"])
44
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
45
+ s.add_development_dependency(%q<rcov>, [">= 0"])
46
+ else
47
+ s.add_dependency(%q<rake>, [">= 0"])
48
+ s.add_dependency(%q<minitest>, [">= 0"])
49
+ s.add_dependency(%q<yard>, [">= 0"])
50
+ s.add_dependency(%q<bundler>, [">= 0"])
51
+ s.add_dependency(%q<jeweler>, [">= 0"])
52
+ s.add_dependency(%q<rcov>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rake>, [">= 0"])
56
+ s.add_dependency(%q<minitest>, [">= 0"])
57
+ s.add_dependency(%q<yard>, [">= 0"])
58
+ s.add_dependency(%q<bundler>, [">= 0"])
59
+ s.add_dependency(%q<jeweler>, [">= 0"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ end
62
+ end
63
+
@@ -0,0 +1,60 @@
1
+ require 'open3'
2
+ require 'tempfile'
3
+ class DatabaseOperations
4
+ def self.pg(cfg, cmd)
5
+ ENV['PGPASSWORD'] = cfg["password"]
6
+
7
+ args = []
8
+ args << %{-h "#{cfg["host"]}"} if cfg["host"]
9
+ args << %{-U "#{cfg["username"]}"} if cfg["username"]
10
+ args << %{-p "#{cfg["port"]}"} if cfg["port"]
11
+ args << %{-w}
12
+
13
+ %x{#{cmd} #{args.join(' ')} "#{cfg['database']}"}
14
+ ensure
15
+ ENV.delete('PGPASSWORD')
16
+ end
17
+
18
+ def self.load_database_schema!(cfg, file)
19
+ pg(cfg, 'createdb') unless pg(cfg, "psql -l") =~ /^ #{cfg['database']}\s*\|/m
20
+
21
+ Tempfile.open('initdb') do |f|
22
+ f.puts "set client_min_messages=error;"
23
+ f.flush
24
+ pg(cfg, "psql -f #{f.path}")
25
+ end
26
+
27
+ pg cfg, %{psql -f "#{file}"}
28
+ end
29
+
30
+ def self.dump_database_schema!(cfg, file)
31
+ search_path = cfg["schema_search_path"]
32
+ search_path = search_path.split(',').map{|x| "--schema=#{x}"}.join(' ') if search_path
33
+
34
+ File.open(Rails.root.join(file), "w") { |f|
35
+ f.puts "begin;"
36
+ f.write pg(cfg, %{pg_dump -s})
37
+ f.write pg(cfg, %{pg_dump -a -t schema_migrations})
38
+ f.puts "commit;"
39
+ }
40
+ end
41
+
42
+ def self.load_views_and_triggers!(env=Rails.env)
43
+ cfg = ActiveRecord::Base.configurations[env]
44
+ unless pg(cfg, "createlang -l") =~ /plpgsql/
45
+ pg(cfg, "createlang plpgsql")
46
+ end
47
+
48
+ output = nil
49
+
50
+ Tempfile.open('load_views') do |temp|
51
+
52
+ Dir.glob(Rails.root.join('lib', 'sql_erb', '[0-9]*.sql.erb')).sort_by { |f| ('0.%s' % File.split(f).last.gsub(/\D.*/,'')).to_f }.each do |fpath|
53
+ temp.puts File.open(fpath){|io| ERB.new(io.read).result }
54
+ end
55
+ temp.flush
56
+ output = pg cfg, %{psql --single-transaction -f #{temp.path} }
57
+ end
58
+ output
59
+ end
60
+ end
@@ -0,0 +1,87 @@
1
+ def copy(src,dst)
2
+ %x{if [ -e #{dst} ]; then mv #{dst} #{dst}.bak; fi; cp #{src} #{dst}}
3
+ end
4
+
5
+ require File.dirname(__FILE__) + '/../database_operations'
6
+
7
+ namespace :ci do
8
+ task :setup => 'setup:default'
9
+
10
+ namespace :setup do
11
+ task :default => [:copy_config, :clone_structure]
12
+
13
+ task :cucumber => [:copy_config, :clean_logdir, :clean_cache, :default]
14
+
15
+ task :clone_structure do
16
+ abcs = YAML.load_file('config/database.yml')
17
+ DatabaseOperations.dump_database_schema!(abcs['reference'], 'db/ci_structure.sql')
18
+ DatabaseOperations.load_database_schema!(abcs['test'], 'db/ci_structure.sql')
19
+ puts %x{env RAILS_ENV=test bundle exec rake db:migrate}
20
+ DatabaseOperations.dump_database_schema!(abcs['test'], 'db/ci_structure.sql')
21
+ end
22
+
23
+ task :copy_config do
24
+ ci = YAML.load_file('config/database.ci.yml')
25
+ ci['login']['database'] = '%s-ci-%s' % [ci['login']['application'], %x{hostname}.strip.split('.').first]
26
+ login = ci.delete('login')
27
+ ref = '%s-reference' % login['application']
28
+ environments = login.delete('environments')
29
+
30
+ ci['reference'] = login.clone
31
+ ci['reference']['database'] = ref
32
+ ci['development'] = login.clone
33
+
34
+ environments.each do |e|
35
+ ci[e] = login.clone
36
+ end
37
+
38
+ File.rename("config/database.yml", "config/database.yml.bak") if File.exists?("config/database.yml")
39
+
40
+ File.open('config/database.yml', 'w') do |f|
41
+ f.write(ci.to_yaml);
42
+ end
43
+
44
+ if File.exists?("config/cms_config.deploy.yml")
45
+ File.rename("config/cms_config.yml", "config/cms_config.yml.bak") if File.exists?("config/cms_config.yml")
46
+ copy 'config/cms_config.deploy.yml', 'config/cms_config.yml'
47
+ end
48
+ end
49
+
50
+ task :clean_cache do
51
+ `rm -f public/javascripts/cache_*.js`
52
+ end
53
+
54
+ task :clean_logdir do
55
+ `for f in log/* tmp/*; do if [ -f $f ]; then rm $f ; fi; done`
56
+ end
57
+ end
58
+ end
59
+
60
+ namespace :db do
61
+ Rake::Task['db:structure:dump'].clear_actions()
62
+ namespace :structure do
63
+ desc "Dump the database structure to a SQL file"
64
+ task :dump => :environment do
65
+ if File.exists?('db/ci_structure.sql')
66
+ STDERR.puts "CI environment detected: not dumping schema"
67
+ else
68
+ abcs = ActiveRecord::Base.configurations
69
+ DatabaseOperations.dump_database_schema!(abcs['development'], 'db/development_structure.sql')
70
+ end
71
+ end
72
+ end
73
+
74
+ Rake::Task['db:test:clone_structure'].clear_actions()
75
+ namespace :test do
76
+ desc "Recreate the test databases from the development structure"
77
+ task :clone_structure => [ "db:structure:dump", "db:test:purge"] do
78
+ abcs = ActiveRecord::Base.configurations
79
+ if File.exists?('db/ci_structure.sql')
80
+ STDERR.puts "CI environment detected"
81
+ DatabaseOperations.load_database_schema!(abcs['test'], 'db/ci_structure.sql')
82
+ else
83
+ DatabaseOperations.load_database_schema!(abcs['test'], 'db/development_structure.sql')
84
+ end
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: database_operations
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 5
10
+ version: 0.0.5
11
+ platform: ruby
12
+ authors:
13
+ - Renewable Funding, LLC
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-15 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :development
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ version_requirements: *id001
32
+ name: rake
33
+ prerelease: false
34
+ - !ruby/object:Gem::Dependency
35
+ type: :development
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ version_requirements: *id002
46
+ name: minitest
47
+ prerelease: false
48
+ - !ruby/object:Gem::Dependency
49
+ type: :development
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ version_requirements: *id003
60
+ name: yard
61
+ prerelease: false
62
+ - !ruby/object:Gem::Dependency
63
+ type: :development
64
+ requirement: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ version_requirements: *id004
74
+ name: bundler
75
+ prerelease: false
76
+ - !ruby/object:Gem::Dependency
77
+ type: :development
78
+ requirement: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ version_requirements: *id005
88
+ name: jeweler
89
+ prerelease: false
90
+ - !ruby/object:Gem::Dependency
91
+ type: :development
92
+ requirement: &id006 !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ version_requirements: *id006
102
+ name: rcov
103
+ prerelease: false
104
+ description: see Summary
105
+ email: devteam@renewfund.com
106
+ executables: []
107
+
108
+ extensions: []
109
+
110
+ extra_rdoc_files:
111
+ - LICENSE.txt
112
+ - README.rdoc
113
+ files:
114
+ - Gemfile
115
+ - Gemfile.lock
116
+ - LICENSE.txt
117
+ - README.rdoc
118
+ - Rakefile
119
+ - VERSION
120
+ - database_operations.gemspec
121
+ - lib/database_operations.rb
122
+ - lib/projectdx/tasks.rb
123
+ homepage: http://github.com/projectdx/database_operations
124
+ licenses:
125
+ - MIT
126
+ post_install_message:
127
+ rdoc_options: []
128
+
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ requirements: []
150
+
151
+ rubyforge_project:
152
+ rubygems_version: 1.8.23
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: Operate the database
156
+ test_files: []
157
+