phenix 0.2.0 → 0.7.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.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/lib/phenix.rb +38 -13
  3. data/lib/phenix/version.rb +2 -1
  4. metadata +25 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 81c4943e9dba3f20d4235b48c51591d815cebe8c
4
- data.tar.gz: 3edbc9630ea3fff246534143f6a4f94c382339d3
2
+ SHA256:
3
+ metadata.gz: 6579c2a43b814939fee5b7be5aaa1e4ab6e316b3c4e9dc735500c033bf4d43cb
4
+ data.tar.gz: d76b5c29e32c18bec0ba0e17a6e0c3a907db937c8bbaac7dcce469c754107893
5
5
  SHA512:
6
- metadata.gz: ff6734fb4457dde177334ce4c815793769e5477795fe949eac9776742e49a759938bfe37f84d769c10da0f2a72ab6f30d98c048ddcca30d6ee900efe1a0cb515
7
- data.tar.gz: e148db5446d212736e3769da620a7bfe2ad1dae52f0c14a3201adb014c9b4247341c15343b3b1182cc24993221544efe2d8e62fbe4641b5d3c5105bfeb28d521
6
+ metadata.gz: 244b06ae752cfefdb33c15b2dd013950aed5d05c31ba651d8aba36aab319390e8f4e1853b0ee56f13a3095c2f908c00f3433f459d0945fd9ca4e4fddfe829fae
7
+ data.tar.gz: 1032af97f7da4fd21c98b1fb8dbd50f8a9b85597dbe23f5c973394b0f41f5c01dc30ed3af2e8e68d6fd83bdac79de34027abf436832460dbd6b0674773be096f
@@ -1,7 +1,15 @@
1
+ # frozen_string_literal: true
1
2
  require 'phenix/version'
2
3
  require 'erb'
3
4
 
4
5
  module Phenix
6
+ CONFIG_TO_MYSQL_MAPPING = {
7
+ 'username' => 'user',
8
+ 'password' => 'password',
9
+ 'port' => 'port',
10
+ 'host' => 'host'
11
+ }.freeze
12
+
5
13
  class << self
6
14
  attr_accessor :database_config_path, :schema_path, :skip_database
7
15
  attr_accessor :current_configuration
@@ -35,15 +43,18 @@ module Phenix
35
43
 
36
44
  def create_databases(with_schema)
37
45
  for_each_database do |name, conf|
38
- run_mysql_command(conf, "CREATE DATABASE #{conf['database']}")
46
+ run_mysql_command(conf, "CREATE DATABASE IF NOT EXISTS #{conf['database']}")
39
47
  ActiveRecord::Base.establish_connection(name.to_sym)
40
48
  populate_database if with_schema
41
49
  end
42
50
  end
43
51
 
44
52
  def populate_database
53
+ old = ActiveRecord::Migration.verbose
45
54
  ActiveRecord::Migration.verbose = false
46
55
  load(Phenix.schema_path)
56
+ ensure
57
+ ActiveRecord::Migration.verbose = old
47
58
  end
48
59
 
49
60
  def drop_databases
@@ -53,25 +64,39 @@ module Phenix
53
64
  end
54
65
 
55
66
  def for_each_database
56
- ActiveRecord::Base.configurations.each do |name, conf|
67
+ configuration_hashes = if ActiveRecord::VERSION::STRING < '6.1'
68
+ ActiveRecord::Base.configurations.to_h
69
+ else
70
+ # We need to get all the configurations and put them back into a hash
71
+ # indexed by the env_name and with configuration_hash as the value.
72
+ ActiveRecord::Base.configurations
73
+ .configurations
74
+ .map { |c| [c.env_name, c.configuration_hash.with_indifferent_access] }
75
+ .to_h
76
+ end
77
+
78
+ configuration_hashes.each do |name, conf|
57
79
  next if conf['database'].nil?
58
80
  next if Phenix.skip_database.call(name, conf)
59
81
  yield(name, conf)
60
82
  end
61
83
  end
62
84
 
63
- def run_mysql_command(conf, command)
64
- @mysql_command ||= begin
65
- commands = [
66
- 'mysql',
67
- "--user=#{conf['username']}"
68
- ]
69
- commands << "--host=#{conf['host']}" if conf['host'].present?
70
- commands << "--port=#{conf['port']}" if conf['port'].present?
71
- commands << " --password=#{conf['password']} 2> /dev/null" if conf['password'].present?
72
- commands.join(' ')
85
+ def run_mysql_command(config, execute)
86
+ command = ['mysql']
87
+ CONFIG_TO_MYSQL_MAPPING.each do |c, m|
88
+ if config.key?(c)
89
+ command << "--#{m}=#{config.fetch(c)}"
90
+ end
73
91
  end
74
- `echo "#{command}" | #{@mysql_command}`
92
+ command << "--execute"
93
+ command << execute
94
+
95
+ pio = IO.popen(command, err: '/dev/null')
96
+ result = pio.read
97
+ pio.close
98
+ raise "Failed to execute #{execute}" unless $?.success?
99
+ result
75
100
  end
76
101
 
77
102
  extend self
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Phenix
2
- VERSION = '0.2.0'
3
+ VERSION = '0.7.0'
3
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.2.0
4
+ version: 0.7.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: 2016-01-25 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,34 +30,34 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '3.2'
33
+ version: '4.2'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '5.1'
36
+ version: '6.1'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: '3.2'
43
+ version: '4.2'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '5.1'
46
+ version: '6.1'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '10.5'
53
+ version: 12.3.3
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - "~>"
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: '10.5'
60
+ version: 12.3.3
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -141,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
155
  - !ruby/object:Gem::Version
142
156
  version: '0'
143
157
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.4.5.1
158
+ rubygems_version: 3.1.2
146
159
  signing_key:
147
160
  specification_version: 4
148
161
  summary: Read a dynamic database.yml file and allow you to drop/create the database