phenix 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/phenix.rb +25 -12
  3. data/lib/phenix/version.rb +1 -1
  4. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e5ee1863ab6fb76d4f2ee85d8dc37f6b1298ebe
4
- data.tar.gz: e75d5e0a0c7a582559a1e54a63affcb29e7c322c
3
+ metadata.gz: 02c40fe211c590d4f7ba84d7133271b50669088d
4
+ data.tar.gz: 25735809d7f5d851b18081a2bfd0ec2de39298a7
5
5
  SHA512:
6
- metadata.gz: 0a8a74352d9cc56ccc1043a36d231bc8a30ecc30ca7320d3697288dff8cb07364b03e5cf8738a65f18dc4fde8be5ad82fe1035ca99829bf2bdf5135628ca6fb2
7
- data.tar.gz: 0defc7e17a2a5088c7857222cbd29178ca9b04cad9c2696679d4fba3c0e9f18109c443c845826629268e5090c36e65eee0b1bd70da322624e05e3eacabf43d74
6
+ metadata.gz: 3713144e578b2a711a8f56d8be89bd2f458922dcb5ed63a0fff078c74d1243f3d77b07ee67813a1b8769ab8d30770a8fe4b395287c6a49ef68e0df2584a69946
7
+ data.tar.gz: ad56ea002acc7c2e03864779ffae8b4410b50f66d151757a64e18fc1573f7ee80697b21858ec132f30afd6273f1c0c2dd9ea6e7c308b7e3c320744aa43b44714
@@ -3,6 +3,13 @@ require 'phenix/version'
3
3
  require 'erb'
4
4
 
5
5
  module Phenix
6
+ CONFIG_TO_MYSQL_MAPPING = {
7
+ 'username' => 'user',
8
+ 'password' => 'password',
9
+ 'port' => 'port',
10
+ 'host' => 'host'
11
+ }.freeze
12
+
6
13
  class << self
7
14
  attr_accessor :database_config_path, :schema_path, :skip_database
8
15
  attr_accessor :current_configuration
@@ -36,15 +43,18 @@ module Phenix
36
43
 
37
44
  def create_databases(with_schema)
38
45
  for_each_database do |name, conf|
39
- run_mysql_command(conf, "CREATE DATABASE #{conf['database']}")
46
+ run_mysql_command(conf, "CREATE DATABASE IF NOT EXISTS #{conf['database']}")
40
47
  ActiveRecord::Base.establish_connection(name.to_sym)
41
48
  populate_database if with_schema
42
49
  end
43
50
  end
44
51
 
45
52
  def populate_database
53
+ old = ActiveRecord::Migration.verbose
46
54
  ActiveRecord::Migration.verbose = false
47
55
  load(Phenix.schema_path)
56
+ ensure
57
+ ActiveRecord::Migration.verbose = old
48
58
  end
49
59
 
50
60
  def drop_databases
@@ -61,18 +71,21 @@ module Phenix
61
71
  end
62
72
  end
63
73
 
64
- def run_mysql_command(conf, command)
65
- @mysql_command ||= begin
66
- commands = [
67
- 'mysql',
68
- "--user=#{conf['username']}"
69
- ]
70
- commands << "--host=#{conf['host']}" if conf['host'].present?
71
- commands << "--port=#{conf['port']}" if conf['port'].present?
72
- commands << " --password=#{conf['password']} 2> /dev/null" if conf['password'].present?
73
- commands.join(' ')
74
+ def run_mysql_command(config, execute)
75
+ command = ['mysql']
76
+ CONFIG_TO_MYSQL_MAPPING.each do |c, m|
77
+ if v = config[c].presence
78
+ command << "--#{m}" << v.to_s
79
+ end
74
80
  end
75
- `echo "#{command}" | #{@mysql_command}`
81
+ command << "--execute"
82
+ command << execute
83
+
84
+ pio = IO.popen(command, err: '/dev/null')
85
+ result = pio.read
86
+ pio.close
87
+ raise "Failed to execute #{execute}" unless $?.success?
88
+ result
76
89
  end
77
90
 
78
91
  extend self
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Phenix
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phenix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Schambacher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-05 00:00:00.000000000 Z
11
+ date: 2017-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,6 +114,20 @@ dependencies:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: single_cov
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
117
131
  description:
118
132
  email:
119
133
  - pschambacher@zendesk.com
@@ -142,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
156
  version: '0'
143
157
  requirements: []
144
158
  rubyforge_project:
145
- rubygems_version: 2.6.9
159
+ rubygems_version: 2.5.1
146
160
  signing_key:
147
161
  specification_version: 4
148
162
  summary: Read a dynamic database.yml file and allow you to drop/create the database