avm-eac_postgresql_base0 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 231e086f7da14eed7a6cc7ca494c5f6f2f2f95e4a5f140f4b4117e1796d8e963
4
- data.tar.gz: 6d6a062291acb635d8e348341316641988981eb9af3fe335046cd966fa688a83
3
+ metadata.gz: 84e0a14809137d8b08980f06cb62e81f4ea0142bd3d7c0f3d646a906f49be832
4
+ data.tar.gz: 8e3f20b69e7af8cc0e4a1445438d0a3696c60bc8debdf9654e180a1c1f51662e
5
5
  SHA512:
6
- metadata.gz: 1a99015236ad00d72abe000e6525cdaf283511789ca6a479e33258d991ce22fe59ce49205ce255393897e3eff83df49480b61ea1c9051ff919b1321726bff490
7
- data.tar.gz: 61420029ee36af6cb8a25f97d778b18ec164cc8ca4e13c592128cd101df62bb6de5fb111fc29bf782dc5e5af1cabc5b8c21a669ebbcc59ab0067c0e0b29b4aac
6
+ metadata.gz: 520e4c244648f74bd1ba2f870abe3e6e3f4c58d22bf06f4c0b04e6dd926fc401f1e6d7492bfaa37c2a77d52683c85b522c4d74ed60b8824fa99823ca762885c3
7
+ data.tar.gz: 6c47c1cb2dec4acd690ce7ff7750f38f29b11c5714e2191ceff4cba4601c5da7669ed7f4c1b1058da87a0e5eecd35f2de70e841bee92032f0393ad205b3191a2
@@ -7,6 +7,7 @@ module Avm
7
7
  class Instance
8
8
  class DataUnit < ::Avm::Instances::Data::Unit
9
9
  EXTENSION = '.pgdump.gz'
10
+ TABLES_SQL = 'select tablename from pg_tables where schemaname = \'public\''
10
11
 
11
12
  before_load :clear_database
12
13
 
@@ -15,24 +16,29 @@ module Avm
15
16
  end
16
17
 
17
18
  def load_command
18
- instance.psql_command.prepend(['gzip', '-d', '@ESC_|'])
19
+ instance.load_gzip_command
19
20
  end
20
21
 
21
22
  private
22
23
 
23
24
  def clear_database
24
25
  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';"
26
+ ts = tables
27
+ if ts.empty?
28
+ info 'Database has no tables'
29
+ else
30
+ info "Removing #{ts.count} table(s)..."
31
+ run_sql('drop table ' + ts.map { |t| "\"#{t}\"" }.join(', ') + ' cascade')
32
+ end
31
33
  end
32
34
 
33
35
  def run_sql(sql)
34
36
  instance.psql_command_command(sql).execute!
35
37
  end
38
+
39
+ def tables
40
+ run_sql(TABLES_SQL).each_line.map(&:strip).reject(&:blank?)
41
+ end
36
42
  end
37
43
  end
38
44
  end
@@ -27,12 +27,33 @@ module Avm
27
27
  .envvar('PGPASSWORD', password)
28
28
  end
29
29
 
30
+ # @return [EacRubyUtils::Envs::Command]
30
31
  def dump_gzip_command
31
- dump_command.append(['@ESC_|', 'gzip', '-9', '-c'])
32
+ dump_command.pipe(gzip_compress_command)
33
+ end
34
+
35
+ # @return [EacRubyUtils::Envs::Command]
36
+ def gzip_compress_command
37
+ env.command('gzip', '-9', '-c')
38
+ end
39
+
40
+ # @return [EacRubyUtils::Envs::Command]
41
+ def gzip_decompress_command
42
+ env.command('gzip', '-d')
43
+ end
44
+
45
+ # @return [EacRubyUtils::Envs::Command]
46
+ def load_gzip_command
47
+ gzip_decompress_command.pipe(psql_command)
48
+ end
49
+
50
+ # @return [String]
51
+ def password_command_argument
52
+ "@ESC_PGPASSWORD=#{password}"
32
53
  end
33
54
 
34
55
  def psql_command(database = true)
35
- env.command("@ESC_PGPASSWORD=#{password}", 'psql', *common_command_args(database))
56
+ env.command(password_command_argument, 'psql', *common_command_args(database))
36
57
  end
37
58
 
38
59
  def psql_command_command(sql, database = true)
@@ -8,9 +8,11 @@ module Avm
8
8
  module InstanceWith
9
9
  def pg
10
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)
11
+ host_env, host: database_hostname,
12
+ port: database_port,
13
+ user: database_username,
14
+ password: database_password,
15
+ name: database_name
14
16
  )
15
17
  end
16
18
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacPostgresqlBase0
5
- VERSION = '0.2.1'
5
+ VERSION = '0.2.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-eac_postgresql_base0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-22 00:00:00.000000000 Z
11
+ date: 2022-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm
@@ -16,40 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.56'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.56.1
19
+ version: '0.57'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0.56'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.56.1
26
+ version: '0.57'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: eac_ruby_utils
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '0.107'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 0.107.1
33
+ version: '0.109'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
38
  - - "~>"
48
39
  - !ruby/object:Gem::Version
49
- version: '0.107'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 0.107.1
40
+ version: '0.109'
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: eac_ruby_gem_support
55
43
  requirement: !ruby/object:Gem::Requirement