phenix 0.3.0 → 0.8.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 +5 -5
- data/lib/phenix.rb +37 -13
- data/lib/phenix/version.rb +1 -1
- metadata +18 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 58a44d30d1fa3381afa8430a76cd2b17800c7fecdbe78a21a1af6a23e9a7d0fb
|
4
|
+
data.tar.gz: 5497fc3d6e5735a320177c95d2b55784c8399be847b8471bf2fed0a28a45e750
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd3abcc151bcaed345375ab9c6baf11543f1c06afe36df21911c6adc820e959d92ca09b3de37ac08fde562f7d65059717876afac17981fee0224ee78b97060d3
|
7
|
+
data.tar.gz: d3f550a2f0fae38458cdfbdc604707fa8bf24961525c1b1a20e1024588168123962fa4c8e96d6c17c34570518215628c8a2f0e704d1a6d4e282535bd9b8cf821
|
data/lib/phenix.rb
CHANGED
@@ -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
|
@@ -54,25 +64,39 @@ module Phenix
|
|
54
64
|
end
|
55
65
|
|
56
66
|
def for_each_database
|
57
|
-
ActiveRecord::
|
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|
|
58
79
|
next if conf['database'].nil?
|
59
80
|
next if Phenix.skip_database.call(name, conf)
|
60
81
|
yield(name, conf)
|
61
82
|
end
|
62
83
|
end
|
63
84
|
|
64
|
-
def run_mysql_command(
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
"
|
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(' ')
|
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
|
74
91
|
end
|
75
|
-
|
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
|
76
100
|
end
|
77
101
|
|
78
102
|
extend self
|
data/lib/phenix/version.rb
CHANGED
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.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre Schambacher
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-12 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: '
|
33
|
+
version: '4.2'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
36
|
+
version: '6.2'
|
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: '
|
43
|
+
version: '4.2'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '6.2'
|
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:
|
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:
|
60
|
+
version: 12.3.3
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rspec
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '3.4'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: bump
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
90
|
+
name: mysql2
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - ">="
|
@@ -101,7 +101,7 @@ dependencies:
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
104
|
+
name: single_cov
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - ">="
|
@@ -114,7 +114,7 @@ dependencies:
|
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
|
-
description:
|
117
|
+
description:
|
118
118
|
email:
|
119
119
|
- pschambacher@zendesk.com
|
120
120
|
executables: []
|
@@ -126,7 +126,7 @@ files:
|
|
126
126
|
homepage: https://github.com/zendesk/phenix
|
127
127
|
licenses: []
|
128
128
|
metadata: {}
|
129
|
-
post_install_message:
|
129
|
+
post_install_message:
|
130
130
|
rdoc_options: []
|
131
131
|
require_paths:
|
132
132
|
- lib
|
@@ -141,9 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
|
-
|
145
|
-
|
146
|
-
signing_key:
|
144
|
+
rubygems_version: 3.2.2
|
145
|
+
signing_key:
|
147
146
|
specification_version: 4
|
148
147
|
summary: Read a dynamic database.yml file and allow you to drop/create the database
|
149
148
|
on demand.
|