eac_tools 0.45.2 → 0.46.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +30 -25
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/lib/avm/data/callbacks.rb +37 -0
  5. data/sub/avm/lib/avm/data/package.rb +15 -7
  6. data/sub/avm/lib/avm/data/unit.rb +2 -23
  7. data/sub/avm/lib/avm/instances/base/auto_values/data.rb +1 -1
  8. data/sub/avm/lib/avm/instances/data/files_unit.rb +55 -0
  9. data/sub/avm/lib/avm/{data/instance → instances/data}/package.rb +2 -2
  10. data/sub/avm/lib/avm/instances/data/unit.rb +14 -0
  11. data/sub/avm/lib/avm/instances/data.rb +11 -0
  12. data/sub/avm/lib/avm/version.rb +1 -1
  13. data/sub/avm-eac_postgresql_base0/Gemfile +5 -0
  14. data/sub/avm-eac_postgresql_base0/avm-eac_postgresql_base0.gemspec +19 -0
  15. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance/assert.rb +77 -0
  16. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance/data_unit.rb +39 -0
  17. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance.rb +74 -0
  18. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/instance_with.rb +18 -0
  19. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0/version.rb +7 -0
  20. data/sub/avm-eac_postgresql_base0/lib/avm/eac_postgresql_base0.rb +9 -0
  21. data/sub/avm-eac_postgresql_base0/spec/rubocop_spec.rb +3 -0
  22. data/sub/avm-eac_postgresql_base0/spec/spec_helper.rb +4 -0
  23. data/sub/avm-eac_rails_base1/avm-eac_rails_base1.gemspec +4 -4
  24. data/sub/avm-eac_rails_base1/lib/avm/eac_rails_base1/version.rb +1 -1
  25. data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +2 -2
  26. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/files.rb +22 -0
  27. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/gitolite.rb +11 -0
  28. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base/install.rb +37 -0
  29. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/base.rb +3 -9
  30. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/data_package.rb +23 -0
  31. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/deploy.rb +1 -19
  32. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
  33. data/sub/avm-eac_redmine_plugin_base0/avm-eac_redmine_plugin_base0.gemspec +2 -2
  34. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/init.rb +27 -0
  35. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/parent.rb +31 -0
  36. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/rubocop.rb +29 -0
  37. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base/version.rb +31 -0
  38. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/base.rb +2 -36
  39. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/sources/init_file.rb +43 -0
  40. data/sub/avm-eac_redmine_plugin_base0/lib/avm/eac_redmine_plugin_base0/version.rb +1 -1
  41. data/sub/avm-eac_redmine_plugin_base0/spec/lib/avm/eac_redmine_plugin_base0/sources/init_file_spec.rb +14 -0
  42. data/sub/avm-eac_redmine_plugin_base0/spec/lib/avm/eac_redmine_plugin_base0/sources/init_file_spec_files/a_init_file.rb +12 -0
  43. data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +3 -3
  44. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/instances/base.rb +4 -4
  45. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
  46. metadata +41 -27
  47. data/sub/avm/lib/avm/data/instance/files_unit.rb +0 -41
  48. data/sub/avm/lib/avm/data/instance/unit.rb +0 -17
  49. data/sub/avm/lib/avm/data/instance.rb +0 -11
  50. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/data_unit.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5895138920c46d129b675b1e7f264baae15f265aaceac01b77ec06c519b0b92
4
- data.tar.gz: 4c1abea1083c04b96cacac8e9cf12b5bb3a688ac22bccdcf400c23b50eed7dc0
3
+ metadata.gz: 42d2af3ec5802d3d4deaef86b0e225332d92bb079767121a8601d0d7a9765418
4
+ data.tar.gz: 062b466f4a749f6094769ede0583d1bd574f73ae05ffa30e0aeaa8a167e6ea2b
5
5
  SHA512:
6
- metadata.gz: be4d60eb73a687e391c59ef23d7c0ff8845c49a6c6f5cd80f70019339f07673a8ce9597a7c8b4c79ff4e8dbb978702229eee24a13bc077268f1cf6bcb91eb316
7
- data.tar.gz: 8728eae853dc90dace706b001f144caf36885871c208f8a4f9786bc730939aff3cbf2d9838ac2fe0b4738827489a9d463c1c23c9d2b1c212e11ccaf504fcc93c
6
+ metadata.gz: ae897ed254a4902dd543c1644015ee6f4ed269bd401949594cd8c5bfc764d9abce299cdbe4a9c6a04de72ec8f0870c93e617d36b39e7c83b202058970dd5f94b
7
+ data.tar.gz: 349afc035604be730dec4bc4a1ebf9ef670dc15c27364f2abe4a752d853c8a2f4a689493f087f86598434d886900d0d81cb26409970dba895f8e7028c92d7869
data/Gemfile.lock CHANGED
@@ -1,18 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eac_tools (0.45.2)
5
- avm (~> 0.56, >= 0.56.1)
4
+ eac_tools (0.46.0)
5
+ avm (~> 0.57)
6
6
  avm-eac_asciidoctor_base0 (~> 0.12)
7
7
  avm-eac_generic_base0 (~> 0.8)
8
8
  avm-eac_latex_base0 (~> 0.3)
9
9
  avm-eac_php_base0 (~> 0.3)
10
10
  avm-eac_rails_base0 (~> 0.8, >= 0.8.1)
11
- avm-eac_rails_base1 (~> 0.7)
12
- avm-eac_redmine_base0 (~> 0.16, >= 0.16.1)
13
- avm-eac_redmine_plugin_base0 (~> 0.3)
11
+ avm-eac_rails_base1 (~> 0.7, >= 0.7.1)
12
+ avm-eac_redmine_base0 (~> 0.17)
13
+ avm-eac_redmine_plugin_base0 (~> 0.4)
14
14
  avm-eac_ruby_base1 (~> 0.27, >= 0.27.1)
15
- avm-eac_webapp_base0 (~> 0.12, >= 0.12.2)
15
+ avm-eac_webapp_base0 (~> 0.12, >= 0.12.3)
16
16
  avm-eac_wordpress_base0 (~> 0.2, >= 0.2.1)
17
17
  avm-tools (~> 0.142, >= 0.142.6)
18
18
  eac_ruby_utils (~> 0.107, >= 0.107.1)
@@ -62,6 +62,13 @@ PATH
62
62
  avm-eac_generic_base0 (~> 0.7)
63
63
  eac_ruby_utils (~> 0.106)
64
64
 
65
+ PATH
66
+ remote: sub/avm-eac_postgresql_base0
67
+ specs:
68
+ avm-eac_postgresql_base0 (0.2.1)
69
+ avm (~> 0.56, >= 0.56.1)
70
+ eac_ruby_utils (~> 0.107, >= 0.107.1)
71
+
65
72
  PATH
66
73
  remote: sub/avm-eac_python_base0
67
74
  specs:
@@ -79,19 +86,19 @@ PATH
79
86
  PATH
80
87
  remote: sub/avm-eac_rails_base1
81
88
  specs:
82
- avm-eac_rails_base1 (0.7.0)
83
- avm (~> 0.45)
84
- avm-eac_ruby_base1 (~> 0.21)
85
- avm-eac_webapp_base0 (~> 0.9)
86
- eac_ruby_utils (~> 0.104)
89
+ avm-eac_rails_base1 (0.7.1)
90
+ avm (~> 0.57)
91
+ avm-eac_ruby_base1 (~> 0.27, >= 0.27.1)
92
+ avm-eac_webapp_base0 (~> 0.12, >= 0.12.3)
93
+ eac_ruby_utils (~> 0.107, >= 0.107.1)
87
94
 
88
95
  PATH
89
96
  remote: sub/avm-eac_redmine_base0
90
97
  specs:
91
- avm-eac_redmine_base0 (0.16.1)
92
- avm (~> 0.56, >= 0.56.1)
98
+ avm-eac_redmine_base0 (0.17.0)
99
+ avm (~> 0.57)
93
100
  avm-eac_generic_base0 (~> 0.8)
94
- avm-eac_rails_base1 (~> 0.7)
101
+ avm-eac_rails_base1 (~> 0.7, >= 0.7.1)
95
102
  avm-eac_ubuntu_base0 (~> 0.3)
96
103
  curb (~> 0.9, >= 0.9.11)
97
104
  eac_fs (~> 0.15)
@@ -101,9 +108,9 @@ PATH
101
108
  PATH
102
109
  remote: sub/avm-eac_redmine_plugin_base0
103
110
  specs:
104
- avm-eac_redmine_plugin_base0 (0.3.0)
105
- avm-eac_ruby_base1 (~> 0.11)
106
- eac_ruby_utils (~> 0.95, >= 0.95.1)
111
+ avm-eac_redmine_plugin_base0 (0.4.0)
112
+ avm-eac_ruby_base1 (~> 0.27, >= 0.27.1)
113
+ eac_ruby_utils (~> 0.107, >= 0.107.1)
107
114
 
108
115
  PATH
109
116
  remote: sub/avm-eac_ruby_base1
@@ -116,13 +123,13 @@ PATH
116
123
  PATH
117
124
  remote: sub/avm-eac_webapp_base0
118
125
  specs:
119
- avm-eac_webapp_base0 (0.12.2)
120
- avm (~> 0.54)
126
+ avm-eac_webapp_base0 (0.12.3)
127
+ avm (~> 0.57)
121
128
  avm-eac_generic_base0 (~> 0.8)
122
- avm-eac_postgresql_base0 (~> 0.2)
129
+ avm-eac_postgresql_base0 (~> 0.2, >= 0.2.1)
123
130
  avm-eac_ubuntu_base0 (~> 0.3)
124
131
  avm-files (~> 0.6)
125
- eac_ruby_utils (~> 0.106, >= 0.106.1)
132
+ eac_ruby_utils (~> 0.107, >= 0.107.1)
126
133
 
127
134
  PATH
128
135
  remote: sub/avm-eac_wordpress_base0
@@ -173,7 +180,7 @@ PATH
173
180
  PATH
174
181
  remote: sub/avm
175
182
  specs:
176
- avm (0.56.1)
183
+ avm (0.57.0)
177
184
  aranha-parsers (~> 0.14, >= 0.14.4)
178
185
  eac_cli (~> 0.30)
179
186
  eac_config (~> 0.12)
@@ -255,9 +262,6 @@ GEM
255
262
  public_suffix (>= 2.0.2, < 6.0)
256
263
  asciidoctor (2.0.18)
257
264
  ast (2.4.2)
258
- avm-eac_postgresql_base0 (0.2.0)
259
- avm (~> 0.12, >= 0.12.1)
260
- eac_ruby_utils (~> 0.82)
261
265
  avm-eac_ubuntu_base0 (0.3.0)
262
266
  avm (~> 0.7)
263
267
  eac_ruby_utils (~> 0.77, >= 0.77.1)
@@ -383,6 +387,7 @@ DEPENDENCIES
383
387
  avm-eac_generic_base0!
384
388
  avm-eac_latex_base0!
385
389
  avm-eac_php_base0!
390
+ avm-eac_postgresql_base0!
386
391
  avm-eac_python_base0!
387
392
  avm-eac_rails_base0!
388
393
  avm-eac_rails_base1!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacTools
4
- VERSION = '0.45.2'
4
+ VERSION = '0.46.0'
5
5
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/callbacks'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Data
8
+ module Callbacks
9
+ common_concern do
10
+ include ::ActiveSupport::Callbacks
11
+
12
+ %i[dump load].each do |action|
13
+ define_callbacks action
14
+
15
+ %i[before after].each do |callback|
16
+ method_name = "#{callback}_#{action}"
17
+ singleton_class.class_eval do
18
+ define_method method_name do |callback_method = nil, &block|
19
+ if callback_method
20
+ set_callback action, callback, callback_method
21
+ else
22
+ set_callback action, callback, &block
23
+ end
24
+ self
25
+ end
26
+ end
27
+
28
+ define_method method_name do |callback_method = nil, &block|
29
+ singleton_class.send(method_name, callback_method, &block)
30
+ self
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/data/package/dump'
4
- require 'avm/data/package/load'
3
+ require 'avm/data/callbacks'
4
+ require 'eac_ruby_utils/core_ext'
5
5
 
6
6
  module Avm
7
7
  module Data
8
8
  class Package
9
- attr_reader :units
9
+ require_sub __FILE__
10
+ include ::Avm::Data::Callbacks
10
11
 
11
12
  def initialize(options)
12
- @units = {}
13
13
  options = options.to_options_consumer
14
14
  units = options.consume(:units)
15
15
  options.validate
@@ -19,7 +19,7 @@ module Avm
19
19
  end
20
20
 
21
21
  def add_unit(identifier, unit)
22
- @units[identifier.to_sym] = unit
22
+ units[identifier.to_sym] = unit
23
23
  end
24
24
 
25
25
  def dump(data_path, options = {})
@@ -31,11 +31,19 @@ module Avm
31
31
  end
32
32
 
33
33
  def dump_units_to_directory(directory)
34
- @units.each { |identifier, unit| unit.dump_to_directory(directory, identifier) }
34
+ run_callbacks :dump do
35
+ units.each { |identifier, unit| unit.dump_to_directory(directory, identifier) }
36
+ end
35
37
  end
36
38
 
37
39
  def load_units_from_directory(directory)
38
- @units.each { |identifier, unit| unit.load_from_directory(directory, identifier) }
40
+ run_callbacks :load do
41
+ units.each { |identifier, unit| unit.load_from_directory(directory, identifier) }
42
+ end
43
+ end
44
+
45
+ def units
46
+ @units ||= {}
39
47
  end
40
48
  end
41
49
  end
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/data/callbacks'
3
4
  require 'eac_ruby_utils/core_ext'
4
- require 'active_support/callbacks'
5
5
 
6
6
  module Avm
7
7
  module Data
8
8
  class Unit
9
- include ::ActiveSupport::Callbacks
9
+ include ::Avm::Data::Callbacks
10
10
 
11
- define_callbacks :dump, :load
12
11
  enable_speaker
13
12
 
14
13
  %w[dump load].each do |action|
@@ -20,26 +19,6 @@ module Avm
20
19
  fail "\\"#{method_name}\\" is a abstract method. Override in #{singleton_class}."
21
20
  end
22
21
  CODE
23
-
24
- # Callbacks
25
- %w[before after].each do |callback|
26
- method = "#{callback}_#{action}"
27
- class_eval <<~CODE, __FILE__, __LINE__ + 1
28
- def self.#{method}(callback_method = nil, &block)
29
- if callback_method
30
- set_callback :#{action}, :#{callback}, callback_method
31
- else
32
- set_callback :#{action}, :#{callback}, &block
33
- end
34
- self
35
- end
36
-
37
- def #{method}(callback_method = nil, &block)
38
- singleton_class.#{method}(callback_method, &block)
39
- self
40
- end
41
- CODE
42
- end
43
22
  end
44
23
 
45
24
  def extension
@@ -15,7 +15,7 @@ module Avm
15
15
  .if_present do |v|
16
16
  ::File.join(
17
17
  v,
18
- "#{id}#{::Avm::Data::Instance::Package::Dump::DEFAULT_FILE_EXTENSION}"
18
+ "#{id}#{::Avm::Instances::Data::Package::Dump::DEFAULT_FILE_EXTENSION}"
19
19
  )
20
20
  end
21
21
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/data/unit'
4
+
5
+ module Avm
6
+ module Instances
7
+ module Data
8
+ class FilesUnit < ::Avm::Instances::Data::Unit
9
+ EXTENSION = '.tar.gz'
10
+
11
+ enable_listable
12
+ lists.add_symbol :option, :sudo_user
13
+
14
+ common_constructor :instance, :fs_path_subpath, :options, default: [{}],
15
+ super_args: -> { [instance] } do
16
+ self.fs_path_subpath = fs_path_subpath.to_pathname
17
+ self.options = self.class.lists.option.hash_keys_validate!(options)
18
+ end
19
+
20
+ before_load :clear_files
21
+
22
+ # @return [Pathname]
23
+ def files_path
24
+ fs_path_subpath
25
+ .expand_path(instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH))
26
+ end
27
+
28
+ def dump_command
29
+ instance_command('tar', '-czf', '-', '-C', files_path, '.')
30
+ end
31
+
32
+ def load_command
33
+ instance_command('tar', '-xzf', '-', '-C', files_path)
34
+ end
35
+
36
+ def clear_files
37
+ infom "Removing all files under #{files_path}..."
38
+ instance_command('mkdir', '-p', files_path).execute!
39
+ instance_command('find', files_path, '-mindepth', 1, '-delete').execute!
40
+ end
41
+
42
+ # @return [EacRubyUtils::Envs::Command]
43
+ def instance_command(*args)
44
+ args = ['sudo', '-Hu', sudo_user] + args if sudo_user.present?
45
+ instance.host_env.command(*args)
46
+ end
47
+
48
+ # @return [String, nil]
49
+ def sudo_user
50
+ options[OPTION_SUDO_USER]
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -3,8 +3,8 @@
3
3
  require 'avm/data/package'
4
4
 
5
5
  module Avm
6
- module Data
7
- module Instance
6
+ module Instances
7
+ module Data
8
8
  class Package < ::Avm::Data::Package
9
9
  attr_reader :instance
10
10
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/unit'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Instances
8
+ module Data
9
+ class Unit < ::Avm::Data::Unit
10
+ common_constructor :instance
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Instances
7
+ module Data
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avm
4
- VERSION = '0.56.1'
4
+ VERSION = '0.57.0'
5
5
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ require 'avm/eac_postgresql_base0/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'avm-eac_postgresql_base0'
9
+ s.version = Avm::EacPostgresqlBase0::VERSION
10
+ s.authors = ['Put here the authors']
11
+ s.summary = 'Put here de description.'
12
+
13
+ s.files = Dir['{lib}/**/*']
14
+
15
+ s.add_dependency 'avm', '~> 0.56', '>= 0.56.1'
16
+ s.add_dependency 'eac_ruby_utils', '~> 0.107', '>= 0.107.1'
17
+
18
+ s.add_development_dependency 'eac_ruby_gem_support', '~> 0.4'
19
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacPostgresqlBase0
7
+ class Instance
8
+ class Assert
9
+ common_constructor :instance
10
+ delegate :name, :password, :user, to: :instance
11
+
12
+ def perform
13
+ create_user unless user_exist?
14
+ change_password unless password_ok?
15
+ create_database unless database_exist?
16
+ change_owner unless user_owner?
17
+ end
18
+
19
+ def change_owner
20
+ root_execute("ALTER DaTABASE \"#{name}\" OWNER TO \"#{user}\"")
21
+ end
22
+
23
+ def change_password
24
+ root_execute("ALTER USER \"#{user}\" WITH PASSWORD '#{password}'")
25
+ end
26
+
27
+ def create_user
28
+ root_execute("CREATE USER \"#{user}\" WITH PASSWORD '#{password}'")
29
+ end
30
+
31
+ def current_owner
32
+ root_query(<<~SQL
33
+ SELECT pg_catalog.pg_get_userbyid(datdba)
34
+ FROM pg_catalog.pg_database
35
+ WHERE datname = '#{name}'
36
+ SQL
37
+ )
38
+ end
39
+
40
+ def database_exist?
41
+ root_boolean_query("FROM pg_database WHERE datname='#{name}'")
42
+ end
43
+
44
+ def password_ok?
45
+ instance.psql_command_command('SELECT 1', false)
46
+ .execute!(exit_outputs: { 512 => 'login_failed' }).strip == '1'
47
+ end
48
+
49
+ def user_exist?
50
+ root_boolean_query("FROM pg_roles WHERE rolname='#{user}'")
51
+ end
52
+
53
+ def user_owner?
54
+ user == current_owner
55
+ end
56
+
57
+ def create_database
58
+ root_execute("CREATE DATABASE \"#{name}\" WITH OWNER \"#{user}\"")
59
+ end
60
+
61
+ private
62
+
63
+ def root_boolean_query(sql_after_projection)
64
+ root_query("SELECT 1 #{sql_after_projection}") == '1'
65
+ end
66
+
67
+ def root_execute(sql)
68
+ instance.root_psql_command(sql).execute!
69
+ end
70
+
71
+ def root_query(sql)
72
+ root_execute(sql).strip
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/data/unit'
4
+
5
+ module Avm
6
+ module EacPostgresqlBase0
7
+ class Instance
8
+ class DataUnit < ::Avm::Instances::Data::Unit
9
+ EXTENSION = '.pgdump.gz'
10
+
11
+ before_load :clear_database
12
+
13
+ def dump_command
14
+ instance.dump_gzip_command
15
+ end
16
+
17
+ def load_command
18
+ instance.psql_command.prepend(['gzip', '-d', '@ESC_|'])
19
+ end
20
+
21
+ private
22
+
23
+ def clear_database
24
+ info 'Clearing database (Dropping all tables)...'
25
+ run_sql(drop_all_tables_sql).if_present { |v| run_sql(v) }
26
+ end
27
+
28
+ def drop_all_tables_sql
29
+ "select 'drop table \"' || tablename || '\" cascade;' from pg_tables " \
30
+ "where schemaname = 'public';"
31
+ end
32
+
33
+ def run_sql(sql)
34
+ instance.psql_command_command(sql).execute!
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_postgresql_base0/instance/data_unit'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module EacPostgresqlBase0
8
+ class Instance
9
+ require_sub __FILE__
10
+
11
+ MAINTENANCE_DATABASE = 'postgres'
12
+
13
+ common_constructor :env, :connection_params do
14
+ self.connection_params = connection_params.with_indifferent_access
15
+ end
16
+
17
+ def assert
18
+ ::Avm::EacPostgresqlBase0::Instance::Assert.new(self).perform
19
+ end
20
+
21
+ def data_unit
22
+ ::Avm::EacPostgresqlBase0::Instance::DataUnit.new(self)
23
+ end
24
+
25
+ def dump_command
26
+ env.command('pg_dump', '--no-privileges', '--clean', '--no-owner', *common_command_args)
27
+ .envvar('PGPASSWORD', password)
28
+ end
29
+
30
+ def dump_gzip_command
31
+ dump_command.append(['@ESC_|', 'gzip', '-9', '-c'])
32
+ end
33
+
34
+ def psql_command(database = true)
35
+ env.command("@ESC_PGPASSWORD=#{password}", 'psql', *common_command_args(database))
36
+ end
37
+
38
+ def psql_command_command(sql, database = true)
39
+ psql_command(database).append(['--quiet', '--tuples-only', '--command', sql])
40
+ end
41
+
42
+ def root_psql_command(sql = nil)
43
+ args = ['sudo', '-u', 'postgres', 'psql']
44
+ args += ['--quiet', '--tuples-only', '--command', sql] if sql.present?
45
+ env.command(*args)
46
+ end
47
+
48
+ def common_command_args(database = true)
49
+ ['--host', host, '--username', user, '--port', port,
50
+ (database ? name : MAINTENANCE_DATABASE)]
51
+ end
52
+
53
+ def host
54
+ connection_params[:host] || '127.0.0.1'
55
+ end
56
+
57
+ def port
58
+ connection_params[:port] || '5432'
59
+ end
60
+
61
+ def user
62
+ connection_params.fetch(:user)
63
+ end
64
+
65
+ def password
66
+ connection_params.fetch(:password)
67
+ end
68
+
69
+ def name
70
+ connection_params.fetch(:name)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/entry_keys'
4
+ require 'avm/eac_postgresql_base0/instance'
5
+
6
+ module Avm
7
+ module EacPostgresqlBase0
8
+ module InstanceWith
9
+ def pg
10
+ @pg ||= ::Avm::EacPostgresqlBase0::Instance.new(
11
+ host_env, user: read_entry(::Avm::Instances::EntryKeys::DATABASE_USERNAME),
12
+ password: read_entry(::Avm::Instances::EntryKeys::DATABASE_PASSWORD),
13
+ name: read_entry(::Avm::Instances::EntryKeys::DATABASE_NAME)
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module EacPostgresqlBase0
5
+ VERSION = '0.2.1'
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacPostgresqlBase0
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ ::EacRubyUtils::Rspec.default_setup.describe_rubocop
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/rspec/default_setup'
4
+ ::EacRubyUtils::Rspec.default_setup_create(::File.expand_path('..', __dir__))
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib,template}/**/*']
14
14
 
15
- s.add_dependency 'avm', '~> 0.45'
16
- s.add_dependency 'avm-eac_ruby_base1', '~> 0.21'
17
- s.add_dependency 'avm-eac_webapp_base0', '~> 0.9'
18
- s.add_dependency 'eac_ruby_utils', '~> 0.104'
15
+ s.add_dependency 'avm', '~> 0.57'
16
+ s.add_dependency 'avm-eac_ruby_base1', '~> 0.27', '>= 0.27.1'
17
+ s.add_dependency 'avm-eac_webapp_base0', '~> 0.12', '>= 0.12.3'
18
+ s.add_dependency 'eac_ruby_utils', '~> 0.107', '>= 0.107.1'
19
19
 
20
20
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
21
21
  end