stuzo-recipes 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.1
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'yaml'
3
3
  require 'rake'
4
+ require 'ERB'
4
5
 
5
6
 
6
7
  namespace :stuzo do
@@ -13,7 +14,7 @@ namespace :stuzo do
13
14
  remote_domain = config_yml['remote_domain']
14
15
  local_domain = config_yml['local_domain']
15
16
  user = config_yml['user']
16
- cmd = "ssh -nNT -R #{remote_port}:#{local_domain}:#{local_port} #{user}@#{remote_domain}"
17
+ cmd = "ssh -nNTf -R #{remote_port}:#{local_domain}:#{local_port} #{user}@#{remote_domain}"
17
18
  exec cmd
18
19
  end
19
20
 
@@ -21,7 +22,7 @@ namespace :stuzo do
21
22
  task :status do
22
23
  config_yml = YAML.load_file(File.join(BASE_PATH, 'config/tunnel.yml'))
23
24
 
24
- if `ssh #{config_yml['remote_domain']} netstat -an |
25
+ if `ssh #{config_yml['user']}@#{config_yml['remote_domain']} netstat -an |
25
26
  egrep "tcp.*:#{config_yml['remote_port']}.*LISTEN" | wc`.to_i > 0
26
27
  puts "Seems ok"
27
28
  else
@@ -29,4 +30,86 @@ namespace :stuzo do
29
30
  end
30
31
  end
31
32
  end
33
+
34
+
35
+
36
+ namespace :db do
37
+ namespace :mysql do
38
+ desc "Dump schema and data to an SQL file (/db/backup_YYYY_MM_DD.sql)"
39
+ task :backup do
40
+ current_date = Time.now.strftime("%Y_%m_%d")
41
+ archive = "#{@base_path}/system/app/db/backup_#{current_date}.sql"
42
+ database, user, password = retrieve_db_info
43
+
44
+ cmd = "/usr/bin/env mysqldump --opt --skip-add-locks -u#{user} "
45
+ puts cmd + "... [password filtered]"
46
+ cmd += " -p'#{password}' " unless password.nil?
47
+ cmd += " #{database} > \"#{archive}\""
48
+ result = system(cmd)
49
+ end
50
+
51
+ desc "Load schema and data from an SQL file (/db/restore.sql)"
52
+ task :restore do
53
+ archive = "#{BASE_PATH}/restore.sql"
54
+ puts "archive: #{archive}"
55
+ database, user, password = retrieve_db_info
56
+
57
+ cmd = "/usr/bin/env mysql -u #{user} #{database} < #{archive.gsub(/\s{1}/, "\\ ")}"
58
+ puts cmd + "... [password filtered]"
59
+ cmd += " -p'#{password}'"
60
+ result = system(cmd)
61
+ end
62
+
63
+ desc "Create database (using database.yml config)"
64
+ task :create do
65
+ database, user, password = retrieve_db_info
66
+
67
+ sql = "CREATE DATABASE #{database};"
68
+ sql += "GRANT ALL PRIVILEGES ON #{database}.* TO #{user}@localhost IDENTIFIED BY '#{password}';"
69
+ mysql_execute(user, password, sql)
70
+ end
71
+
72
+ desc "Destroy database (using database.yml config)"
73
+ task :destroy do
74
+ database, user, password = retrieve_db_info
75
+ sql = "DROP DATABASE #{database};"
76
+ mysql_execute(user, password, sql)
77
+ end
78
+ end
79
+ namespace :schema do
80
+ desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
81
+ task :dump do
82
+ require 'active_record'
83
+ require 'active_record/schema_dumper'
84
+ database, user, password = retrieve_db_info
85
+ ActiveRecord::Base.establish_connection(
86
+ :adapter => "mysql",
87
+ :host => "localhost",
88
+ :usermame => user,
89
+ :password => password,
90
+ :database => database
91
+ );
92
+
93
+ File.open(ENV['SCHEMA'] || "#{@base_path}/system/app/db/schema.rb", "w") do |file|
94
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
95
+ end
96
+ end
97
+ end
98
+
99
+ end
100
+ end
101
+
102
+ def retrieve_db_info
103
+ result = File.read "#{BASE_PATH}/config/database.yml"
104
+ result.strip!
105
+ config_file = YAML::load(ERB.new(result).result)['development']
106
+ return [
107
+ config_file['database'],
108
+ config_file['user'],
109
+ config_file['password']
110
+ ]
111
+ end
112
+
113
+ def mysql_execute(username, password, sql)
114
+ system("/usr/bin/env mysql5 -u #{username} -p'#{password}' --execute=\"#{sql}\"")
32
115
  end
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{stuzo-recipes}
8
+ s.version = "0.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jesse McPherson"]
12
+ s.date = %q{2009-11-24}
13
+ s.description = %q{Tasty Capistrano and Rake recipes for use in php projects at Stuzo Group}
14
+ s.email = %q{jesse@stuzo.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/stuzo-recipes/cap/tasks.rb",
29
+ "lib/stuzo-recipes/git-deployment/README",
30
+ "lib/stuzo-recipes/git-deployment/VERSION",
31
+ "lib/stuzo-recipes/git-deployment/gitflow.rb",
32
+ "lib/stuzo-recipes/git-deployment/natcmp.rb",
33
+ "lib/stuzo-recipes/rake/tasks.rb",
34
+ "spec/spec.opts",
35
+ "spec/spec_helper.rb",
36
+ "spec/stuzo-recipes_spec.rb",
37
+ "stuzo-recipes.gemspec"
38
+ ]
39
+ s.homepage = %q{http://github.com/stuzo/stuzo-recipes}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.5}
43
+ s.summary = %q{Tasty Capistrano and Rake recipes for use in php projects at Stuzo Group}
44
+ s.test_files = [
45
+ "spec/spec_helper.rb",
46
+ "spec/stuzo-recipes_spec.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
55
+ else
56
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
+ end
61
+ end
62
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stuzo-recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse McPherson
@@ -49,6 +49,7 @@ files:
49
49
  - spec/spec.opts
50
50
  - spec/spec_helper.rb
51
51
  - spec/stuzo-recipes_spec.rb
52
+ - stuzo-recipes.gemspec
52
53
  has_rdoc: true
53
54
  homepage: http://github.com/stuzo/stuzo-recipes
54
55
  licenses: []