db_stager 0.1.1 → 0.2.0

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: b61c5b179445a96bd7fffc53b1bfbbe37e7cbd70
4
- data.tar.gz: 236e74f0283dcfdbdacb4c548d463c7b353c1afc
3
+ metadata.gz: 5596cc698905e2cb5c03fbcebee2a272403360f4
4
+ data.tar.gz: 2e27f20781268cc10f257c000cec3307d8b043cf
5
5
  SHA512:
6
- metadata.gz: a6cc24928a5f0f331e406e50d7edb2d22b07c1d1f518e7a7167662010f4048ff69856ce0d2a4781602e7c0677ce3ee389635751f4166cdccd44bf2ebc0b3f3ec
7
- data.tar.gz: 2604bfb89e98d8c897a3651e41afb4ae281186184dc5bb2e0dd57034071c9e928774b23ba1438b1e4829f3436b416964ae959977056f5034fd01935df48c107f
6
+ metadata.gz: ecd312cb600acc15779f8336443da10cd65997fd80a18a08744a5d3f0d7a88fde9aa99c253d972b128ab7779633b44b29654d2ca1830eefb44d69865cd9c3226
7
+ data.tar.gz: 9acec0d9ffaf4eaff6dcbd7b034b00828a93c0c31e2c2a1a8b53f3b24cd629dcf213b0e8af4efad56c93c0dc2ea65d015d52a932e07a46627bc6ae4601e668a6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- db_stager (0.1.1)
4
+ db_stager (0.2.0)
5
5
  dotenv (~> 2.2)
6
6
  sequel (~> 4.41.0)
7
7
  thor (~> 0.19)
data/lib/db_stager/cli.rb CHANGED
@@ -23,14 +23,10 @@ module DbStager
23
23
  def capture(dir=".")
24
24
  Dir.chdir(dir)
25
25
 
26
- environment = options[:environment] || ENV['RAILS_ENV'] || ENV['RACK_ENV']
27
- # Get connection info
28
-
29
- db = Sequel.connect(YAML.load(ERB.new(File.read(File.join(Dir.pwd, 'config', 'database.yml'))).result)[environment])
26
+ sh 'rake db:structure:dump'
30
27
 
31
28
  capture_file = options[:file] || File.join(Dir.pwd, "db", "#{environment}_capture.sql")
32
29
  File.open(capture_file, "w") do |file|
33
-
34
30
  db.tables.each do |table_name|
35
31
  items = db[table_name]
36
32
  items.each do |item|
@@ -45,17 +41,25 @@ module DbStager
45
41
  desc "upload", "upload your most recent capture to S3"
46
42
  desc "download", "download your most recent capture from S3"
47
43
 
44
+ method_option :environment, type: :string, aliases: '-e'
45
+ method_option :structure_file, type: :string, aliases: '-s'
46
+ method_option :file, type: :string, aliases: '-f'
48
47
  desc "load", "overwrite the current db with the most recently downloaded stager db"
49
48
  def load(dir=".")
50
49
  Dir.chdir(dir)
51
-
52
- environment = options[:environment] || ENV['RAILS_ENV'] || ENV['RACK_ENV']
53
- # Get connection info
54
-
55
- db = Sequel.connect(YAML.load(ERB.new(File.read(File.join(Dir.pwd, 'config', 'database.yml'))).result)[environment])
56
-
50
+ structure_file = options[:structure_file] || File.join(Dir.pwd, "db", "structure.sql")
51
+ db.run File.read(struture_file)
57
52
  capture_file = options[:file] || File.join(Dir.pwd, "db", "#{environment}_capture.sql")
58
53
  db.run File.read(capture_file)
59
54
  end
60
55
  end
56
+
57
+ protected
58
+ def environment
59
+ @environment ||= options[:environment] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development"
60
+ end
61
+
62
+ def db
63
+ @db ||= Sequel.connect(YAML.load(ERB.new(File.read(File.join(Dir.pwd, 'config', 'database.yml'))).result)[environment])
64
+ end
61
65
  end
@@ -1,3 +1,3 @@
1
1
  module DbStager
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_stager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Kaufman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-20 00:00:00.000000000 Z
11
+ date: 2018-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler