georgia_recipes 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a16213f5c7060bbd035be7076e9d42a599f2e732
4
- data.tar.gz: 8e0528af4e1c100dbf30c1ab8865cf9d67593561
3
+ metadata.gz: a7dadcca0da277b0841dd2a08fd7f75f64fa11ac
4
+ data.tar.gz: 7f7efe5507f0974ab67fc70c583b5cd58f9532fd
5
5
  SHA512:
6
- metadata.gz: 8e8c1f410092f0c794430dfbd194301a0ab30f845f2c1d5be338e180e2a59165daa41e82683aa0e59dd02444e981bf4fe8b6873a71f798f6007b0634f527480a
7
- data.tar.gz: ad2049f9cdafd734c4b6ba89de97f314b6779dff19889341b2e87aa3ee6844c9d67ecdd9c91835e600eed03e711ef518582c7fe482457814af639d7491dcd171
6
+ metadata.gz: 3cf1d5c8acb4a4da341e0f7b8436f4a427ce189ea828b884c7cbb88dd43adb11bdbddc3a12a2cb33e6b80cff95fad59c63fcb815c092b313081227adb71ff338
7
+ data.tar.gz: eee2a29383b01d2345b18db9b7588cf69ca03d037267ce74808c40c6e37462ffcc416ead8f27cf289d4346fdf6eac6b7e9c7eed55ee7391e425d4237953653eb
@@ -1,5 +1,4 @@
1
1
  require "georgia_recipes/version"
2
- require "georgia_recipes/helper_methods"
3
2
 
4
3
  module GeorgiaRecipes
5
4
  end
@@ -1,15 +1,10 @@
1
1
  require 'capistrano'
2
2
  require 'capistrano/cli'
3
+ require 'georgia_recipes/helper_methods'
3
4
 
4
5
  Capistrano::Configuration.instance.load do
5
6
 
6
7
  set_default(:host) { ask("What is the fully qualified domain name?") }
7
- set_default(:remote_db_user) { db_config_file["#{rails_env}"]["username"] rescue ask("Remote database user: ") }
8
- set_default(:remote_db_user) { db_config_file["#{rails_env}"]["database"] rescue ask("Remote database name: ") }
9
- set_default(:remote_db_user) { db_config_file["#{rails_env}"]["password"] rescue ask("Remote database password: ") }
10
- set_default(:local_db_user) { db_config_file["development"]["username"] rescue ask("Local database user: ") }
11
- set_default(:local_db_user) { db_config_file["development"]["database"] rescue ask("Local database name: ") }
12
- set_default(:local_db_user) { db_config_file["development"]["password"] rescue ask("Local database password: ") }
13
8
 
14
9
  namespace :deploy do
15
10
 
@@ -83,8 +83,4 @@ end
83
83
  def close_sessions
84
84
  sessions.values.each { |session| session.close }
85
85
  sessions.clear
86
- end
87
-
88
- def db_config_file
89
- @db_config_file ||= YAML.load(File.read('config/database.yml'))
90
86
  end
@@ -1,9 +1,5 @@
1
1
  Capistrano::Configuration.instance.load do
2
2
 
3
- set_default(:db_host, "localhost")
4
- set_default(:db_user) { (app_var rescue application) }
5
- set_default(:db_password) { Capistrano::CLI.password_prompt "PostgreSQL Password: " }
6
- set_default(:db_database) { "#{db_user}_production" }
7
3
  set_default(:postgresql_pid) { "/var/run/postgresql/9.1-main.pid" }
8
4
 
9
5
  namespace :pg do
@@ -42,20 +38,20 @@ Capistrano::Configuration.instance.load do
42
38
  desc "Pull database from remote server"
43
39
  task :pull, roles: :db do
44
40
  run "mkdir -p #{shared_path}/backups"
45
- run %Q{#{sudo} -u postgres pg_dump #{db_database} --format=tar > #{shared_path}/backups/#{database_filename}}
41
+ run %Q{#{sudo} -u postgres pg_dump #{remote_db_name} --format=tar > #{shared_path}/backups/#{database_filename}}
46
42
  get "#{shared_path}/backups/#{database_filename}", "/tmp/#{database_filename}"
47
43
  run "rm #{shared_path}/backups/#{database_filename}"
48
- run_locally "#{sudo} -u postgres pg_restore /tmp/#{database_filename} --clean --format=tar --dbname=#{db_user}_development"
44
+ run_locally "#{sudo} -u postgres pg_restore /tmp/#{database_filename} --clean --format=tar --dbname=#{local_db_user}"
49
45
  run_locally "rm /tmp/#{database_filename}"
50
46
  end
51
47
 
52
48
  desc "Push database to remote server"
53
49
  task :push, roles: :db do
54
50
  if are_you_sure?
55
- run_locally %Q{#{sudo} -u postgres pg_dump #{db_user}_development --format=tar > /tmp/#{database_filename}}
51
+ run_locally %Q{#{sudo} -u postgres pg_dump #{local_db_user} --format=tar > /tmp/#{database_filename}}
56
52
  upload "/tmp/#{database_filename}", "/tmp/#{database_filename}"
57
53
  run_locally "rm /tmp/#{database_filename}"
58
- run "#{sudo} -u postgres pg_restore /tmp/#{database_filename} --clean --format=tar --dbname=#{db_database}"
54
+ run "#{sudo} -u postgres pg_restore /tmp/#{database_filename} --clean --format=tar --dbname=#{remote_db_name}"
59
55
  run "rm /tmp/#{database_filename}"
60
56
  deploy.restart
61
57
  end
@@ -69,11 +65,11 @@ Capistrano::Configuration.instance.load do
69
65
  ### Helpers
70
66
 
71
67
  def database_filename
72
- @database_filename ||= "#{db_user}_#{timestamp}.sql"
68
+ @database_filename ||= "#{application}_#{timestamp}.sql"
73
69
  end
74
70
 
75
71
  def database_table_filename
76
- @database_table_filename ||= "#{db_user}_#{table_name}_#{timestamp}.sql"
72
+ @database_table_filename ||= "#{application}_#{table_name}_#{timestamp}.sql"
77
73
  end
78
74
 
79
75
  def table_name
@@ -81,12 +77,50 @@ Capistrano::Configuration.instance.load do
81
77
  end
82
78
 
83
79
  def create_user
84
- run %Q{#{sudo} -u postgres psql -c "create user #{db_user} with password '#{db_password}';"}
80
+ run %Q{#{sudo} -u postgres psql -c "create user #{remote_db_user} with password '#{remote_db_password}';"}
85
81
  end
86
82
 
87
83
  def create_db
88
- run %Q{#{sudo} -u postgres psql -c "create database #{db_database} owner #{db_user} ENCODING = 'UTF-8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' TEMPLATE template0;"}
84
+ run %Q{#{sudo} -u postgres psql -c "create database #{remote_db_name} owner #{remote_db_user} ENCODING = 'UTF-8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' TEMPLATE template0;"}
89
85
  end
86
+
87
+ def local_db_config(key)
88
+ begin
89
+ config = File.read('config/database.yml')
90
+ YAML.load(config)["development"][key]
91
+ rescue
92
+ request_from_prompt(key)
93
+ end
94
+ end
95
+
96
+ def remote_db_config(key)
97
+ begin
98
+ config = capture("cat #{shared_path}/config/database.yml")
99
+ YAML.load(config)[rails_env][key]
100
+ rescue
101
+ request_from_prompt(key, env: rails_env)
102
+ end
103
+ end
104
+
105
+ def request_from_prompt key, env='Development'
106
+ case key
107
+ when :database
108
+ ask("#{env} database name: ")
109
+ when :password
110
+ Capistrano::CLI.password_prompt("#{env} database password: ")
111
+ else
112
+ ask("#{env} database #{key}: ")
113
+ end
114
+ end
115
+
116
+ set_default(:remote_db_user) { remote_db_config(:username) }
117
+ set_default(:remote_db_name) { remote_db_config(:database) }
118
+ set_default(:remote_db_password) { remote_db_config(:password) }
119
+
120
+ set_default(:local_db_user) { local_db_config(:username) }
121
+ set_default(:local_db_name) { local_db_config(:database) }
122
+ set_default(:local_db_password) { local_db_config(:password) }
123
+
90
124
  end
91
125
 
92
126
  end
@@ -1,8 +1,8 @@
1
1
  production:
2
2
  adapter: postgresql
3
3
  encoding: unicode
4
- database: <%= db_database %>
4
+ database: <%= remote_db_config(:database) %>
5
5
  pool: 5
6
- username: <%= db_user %>
7
- password: <%= db_password %>
8
- host: <%= db_host %>
6
+ username: <%= remote_db_config(:username) %>
7
+ password: <%= remote_db_config(:password) %>
8
+ host: localhost
@@ -1,3 +1,3 @@
1
1
  module GeorgiaRecipes
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: georgia_recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu Gagne