avm-eac_postgresql_base0 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 21a34c355a48e71fa5a12b91b27238a98844495a5742b30ac79b277f7e56fec4
4
+ data.tar.gz: 9e5b87bbca77cb621b8cb207c1ed220321b6bbfddddf548025461af03fa25aec
5
+ SHA512:
6
+ metadata.gz: f8edfd9211f650e24d3e93503ceda6f6cce0637abd4111289a3bdf7c2c253d35417b95a497a26a4d3721db8ed711df5ad46ff751f6324b2bf29e34130965bcbc
7
+ data.tar.gz: e1ab05d6d11d6adbe238e902b787c0fb0994527d951ba2d44f79a686e4138291a9e2f1241caeb6933dc9edfee3c40b41e65ff1322c1ff26e79a77142c32408d6
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/data/instance/unit'
4
+
5
+ module Avm
6
+ module EacPostgresqlBase0
7
+ class Instance
8
+ class DataUnit < ::Avm::Data::Instance::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,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_postgresql_base0/instance/data_unit'
4
+
5
+ module Avm
6
+ module EacPostgresqlBase0
7
+ class Instance
8
+ def initialize(env, connection_params)
9
+ @env = env
10
+ @connection_params = connection_params.with_indifferent_access
11
+ end
12
+
13
+ def data_unit
14
+ ::Avm::EacPostgresqlBase0::Instance::DataUnit.new(self)
15
+ end
16
+
17
+ def dump_command
18
+ env.command('pg_dump', '--no-privileges', '--clean', '--no-owner', *common_command_args)
19
+ .envvar('PGPASSWORD', password)
20
+ end
21
+
22
+ def dump_gzip_command
23
+ dump_command.append(['@ESC_|', 'gzip', '-9', '-c'])
24
+ end
25
+
26
+ def psql_command
27
+ env.command("@ESC_PGPASSWORD=#{password}", 'psql', *common_command_args)
28
+ end
29
+
30
+ def psql_command_command(sql)
31
+ psql_command.append(['--quiet', '--tuples-only', '--command', sql])
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :env, :connection_params
37
+
38
+ def common_command_args
39
+ ['--host', host, '--username', user, '--port', port, name]
40
+ end
41
+
42
+ def host
43
+ connection_params[:host] || '127.0.0.1'
44
+ end
45
+
46
+ def port
47
+ connection_params[:port] || '5432'
48
+ end
49
+
50
+ def user
51
+ connection_params.fetch(:user)
52
+ end
53
+
54
+ def password
55
+ connection_params.fetch(:password)
56
+ end
57
+
58
+ def name
59
+ connection_params.fetch(:name)
60
+ end
61
+ end
62
+ end
63
+ 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.1.0'
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
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: avm-eac_postgresql_base0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Put here the authors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: avm
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.12'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.12.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.12'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.12.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: eac_ruby_utils
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.82'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.82'
47
+ - !ruby/object:Gem::Dependency
48
+ name: eac_ruby_gem_support
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.4'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.4'
61
+ description:
62
+ email:
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - lib/avm/eac_postgresql_base0.rb
68
+ - lib/avm/eac_postgresql_base0/instance.rb
69
+ - lib/avm/eac_postgresql_base0/instance/data_unit.rb
70
+ - lib/avm/eac_postgresql_base0/instance_with.rb
71
+ - lib/avm/eac_postgresql_base0/version.rb
72
+ homepage:
73
+ licenses: []
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.1.6
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Put here de description.
94
+ test_files: []