voomify_tasks 0.1.3 → 0.1.5
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.
- data/lib/run_psql.rb +10 -2
- data/lib/tasks/databases.rake +15 -6
- metadata +4 -4
data/lib/run_psql.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
module RunPSQL
|
2
|
+
def db_file_path(filename)
|
3
|
+
"#{Rails.root}/db/sql/#{filename}"
|
4
|
+
end
|
2
5
|
def run_psql_file(config, filename)
|
3
|
-
file_with_path =
|
6
|
+
file_with_path = db_file_path(filename)
|
4
7
|
puts "Executing sql file: #{file_with_path}"
|
8
|
+
run_pg_command(config, "psql -f #{file_with_path}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def run_pg_command(config, command, output_file=nil)
|
5
12
|
database = config["database"]
|
6
13
|
username = config["username"]
|
7
14
|
host = config["host"]
|
8
15
|
port = config["port"]
|
9
16
|
password = config["password"]
|
10
|
-
|
17
|
+
pipe_to_file = output_file ? "> #{output_file}" : ""
|
18
|
+
`export PGPASSWORD="#{password}";#{command} -U #{username} -h #{host} -p #{port} #{database} #{pipe_to_file};export PGPASSWORD=""`
|
11
19
|
end
|
12
20
|
end
|
data/lib/tasks/databases.rake
CHANGED
@@ -1,20 +1,25 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
#
|
1
|
+
TASKS_ROOT = File.expand_path(File.dirname(__FILE__))
|
2
|
+
require "#{TASKS_ROOT}/../replace_rake_tasks"
|
3
|
+
require "#{TASKS_ROOT}/../run_psql"
|
4
|
+
require 'fileutils'
|
5
|
+
# we override these tasks to use ddl file instead of ruby
|
4
6
|
|
5
7
|
namespace :db do
|
6
8
|
namespace :schema do
|
7
9
|
override_task :load => :environment do
|
8
|
-
run_psql_file(
|
10
|
+
run_psql_file(current_env, "schema.sql")
|
9
11
|
end
|
10
12
|
|
11
13
|
override_task :dump => :environment do
|
12
|
-
|
14
|
+
output_file = db_file_path("schema.sql")
|
15
|
+
FileUtils.mv(output_file, "#{output_file}.last") if FileTest.exists?(output_file)
|
16
|
+
run_pg_command(current_env, "pg_dump -c -o -O -x -s", output_file)
|
17
|
+
puts "Schema has been updated from the database. Last schema backed up to #{output_file}.last"
|
13
18
|
end
|
14
19
|
end
|
15
20
|
|
16
21
|
override_task :seed => :environment do
|
17
|
-
run_psql_file(
|
22
|
+
run_psql_file(current_env, "seed.sql")
|
18
23
|
end
|
19
24
|
|
20
25
|
namespace :test do
|
@@ -31,4 +36,8 @@ private
|
|
31
36
|
|
32
37
|
include RunPSQL
|
33
38
|
|
39
|
+
def current_env
|
40
|
+
ActiveRecord::Base.configurations[Rails.env]
|
41
|
+
end
|
42
|
+
|
34
43
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voomify_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Russell Edens
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-07 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|