effective_developer 0.4.13 → 0.4.14

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
  SHA256:
3
- metadata.gz: 3bbf2522e6c0ce4583209da6b79522d6e5a453d02411b014873c59f9e06538b7
4
- data.tar.gz: 86c2bcde53f3f2ea854494beb9ec934e51040ca47ced6b77db9425b852feab48
3
+ metadata.gz: 33e92fc9bd9a51a447bd0128b11463ac1e06c854389e1e996872c5f012b02e47
4
+ data.tar.gz: 87049e6643aaa2235639729e97d93d48f642827a53a9cefe8aab34b1d206ea1e
5
5
  SHA512:
6
- metadata.gz: 239a57f7af43e539817e3e39084db5ad86ca137471bcbecd670202afdb817f110b992dc5f92de3f57cc0a09092403a6d88a2f47b225a624f5c3aedbff2538145
7
- data.tar.gz: ec433b9bd5e2fd1efb7476620b6e08d9d27906f2bdb16eaa81cad9dffe43b877e842080f1c8b60a03e081a15a73ff52ef08e73f59db0c0b8bd3118d750211bc7
6
+ metadata.gz: 67119ab7a04b64551565dacc737a8bf95eb06793c0bab5fbd6bf26b3e8f2afc7a62e4c2e686b4b48f55db477f86e70147a1ab3d30f9c7b13b21b36a403a60bf8
7
+ data.tar.gz: 6908000780ca6d53f58dd21ca7a6cf15f757113db5e27e8b2aaa6ef4ae09c15efb60a5965b50c03801c28e4fb9751074dea193c1445d6880df2499820304bcb4
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.4.13'.freeze
2
+ VERSION = '0.4.14'.freeze
3
3
  end
@@ -97,4 +97,58 @@ namespace :pg do
97
97
  puts 'Cloning database complete'
98
98
  end
99
99
 
100
+ desc 'Copies a local database table to production (--remote heroku by default) database'
101
+ task :push_table, [:table, :remote] => :environment do |t, args|
102
+ args.with_defaults(:remote => 'heroku')
103
+
104
+ if args.table.blank?
105
+ puts "Error, no table name specified. Expected usage: rake pg:push_table[prices]"; exit
106
+ end
107
+
108
+ # Find and parse my heroku database info
109
+ regex = Regexp.new(/postgres:\/\/(\w+):(\w+)@(.+):(\d+)\/(\w+)/)
110
+ url = `heroku config --remote #{args.remote} | grep DATABASE_URL`
111
+ info = url.match(regex)
112
+
113
+ if info.blank? || info.length != 6
114
+ puts "Unable to find heroku DATABASE_URL"
115
+ puts "Expected \"heroku config --remote #{args.remote} | grep DATABASE_URL\" to be present"
116
+ exit
117
+ end
118
+
119
+ heroku = { username: info[1], password: info[2], host: info[3], port: info[4], database: info[5] }
120
+
121
+ # Confirm destructive operation
122
+ puts "WARNING: this task will overwrite the #{args.table} database table on #{args.remote}. Proceed? (y/n)"
123
+ (puts 'Aborted' and exit) unless STDIN.gets.chomp.downcase == 'y'
124
+
125
+ puts "=== Cloning local table '#{args.table}' to remote #{args.remote} database"
126
+
127
+ # Dump my local database table
128
+ db = ActiveRecord::Base.configurations[Rails.env]
129
+ tmpfile = "tmp/#{args.table}.sql"
130
+
131
+ unless system("pg_dump --data-only --table=#{args.table} -h localhost -U '#{db['username']}' '#{db['database']}' > #{tmpfile}")
132
+ puts "Error dumping local database table"; exit
133
+ end
134
+
135
+ # Now restore it to heroku
136
+ psql = "export PGPASSWORD=#{heroku[:password]}; psql -h #{heroku[:host]} -p #{heroku[:port]} -U #{heroku[:username]} #{heroku[:database]}"
137
+ delete = args.table.split(',').map { |table| "DELETE FROM #{table}" }.join(';')
138
+
139
+ unless system("#{psql} -c \"#{delete}\"")
140
+ puts "Error deleting remote table data"; exit
141
+ end
142
+
143
+ unless system("#{psql} < #{tmpfile}")
144
+ puts "Error pushing table to remote database"; exit
145
+ end
146
+
147
+ # Delete tmpfile
148
+ File.delete(tmpfile)
149
+
150
+ # Finished
151
+ puts "Pushing #{args.table} database table complete"
152
+ end
153
+
100
154
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_developer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.13
4
+ version: 0.4.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-24 00:00:00.000000000 Z
11
+ date: 2020-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails