pgchief 0.5.2 → 0.5.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: 613ce14b91c64d69a6fa16449f8ea8aa2a3dfcab054684efaefe978eaae0f564
4
- data.tar.gz: 7116499bc9a4ea6e30b850bbe07e953e7068b7c2b8c03b32daef87dde6fe0061
3
+ metadata.gz: 8c695989f5431e21f2c33b016b34a7197fb5cca9ea62592391fab10fcdbfe385
4
+ data.tar.gz: 195ab95c85943e54d41455ae25b1458aa538d6bc4b6319685b609de7549504f9
5
5
  SHA512:
6
- metadata.gz: 3725ab140a34f5e8c41fb13e9c737835a96ca440d2519ee377991921af672109321984e8d089813be6042af732642a4c94127da2d8873d1214f32c0073583299
7
- data.tar.gz: f560244827039f3258151f2e8e573b5d4584847cd5ddccf84e085b00104f21b45fa77af1c6a85df54d8ee2ace45a5915d4240ef06ee24ae5714625072eb5ec46
6
+ metadata.gz: 352d1edab7569b64483b3abf178297cf2a213ff1c24dfdc40f39ecd8548a06acfffd650ae30a7284fba34368c15e7d58c09e9f3153e9cfc8657613fa01fe4da0
7
+ data.tar.gz: e6e5f42192398383a2b8bc481c6a2b5f37722eef72111a04e2250a84bd1ac4125a9e783123ea1b3d4d64d2c3721a177482b3c83fd1bc656cc4d9b564ac2af4fc
data/CHANGELOG.md CHANGED
@@ -13,6 +13,24 @@ and this project will try its best to adhere to [Semantic Versioning](https://se
13
13
 
14
14
  ### Fixes
15
15
 
16
+ ## [0.5.3]
17
+
18
+ ### Additions
19
+
20
+ * Add spec for database backup command class.
21
+ * Add check on the resulting db dump file. Make sure it's > 0 bytes.
22
+
23
+ ### Changes
24
+
25
+ * Allow created users the proper permissions to add PG extensions to a database.
26
+
27
+ ### Fixes
28
+
29
+ * Fix typo in backup command class description.
30
+ * Fix backup command to use full database connection string to the database when
31
+ executing the pg_dump command.
32
+ * Reset s3 config in db backup spec to prevent config leaks from other test runs.
33
+
16
34
  ## [0.5.2]
17
35
 
18
36
  ### Changes
@@ -119,7 +137,8 @@ and this project will try its best to adhere to [Semantic Versioning](https://se
119
137
  - Drop user ✅
120
138
  - List databases ✅
121
139
 
122
- [Unreleased]: https://github.com/jayroh/pgchief/compare/v0.5.2...HEAD
140
+ [Unreleased]: https://github.com/jayroh/pgchief/compare/v0.5.3...HEAD
141
+ [0.5.3]: https://github.com/jayroh/pgchief/releases/tag/v0.5.3
123
142
  [0.5.2]: https://github.com/jayroh/pgchief/releases/tag/v0.5.2
124
143
  [0.5.1]: https://github.com/jayroh/pgchief/releases/tag/v0.5.1
125
144
  [0.5.0]: https://github.com/jayroh/pgchief/releases/tag/v0.5.0
@@ -4,7 +4,7 @@ require "forwardable"
4
4
 
5
5
  module Pgchief
6
6
  module Command
7
- # Command object to drop a database
7
+ # Command object to back up a database
8
8
  class DatabaseBackup < Base
9
9
  extend Forwardable
10
10
 
@@ -12,12 +12,17 @@ module Pgchief
12
12
 
13
13
  attr_reader :database
14
14
 
15
- def call
15
+ def initialize(*params)
16
+ super
16
17
  @database = params.first
17
18
  @uploader = Pgchief::Command::S3Upload.new(local_location)
19
+ end
20
+
21
+ def call
18
22
  raise Pgchief::Errors::DatabaseMissingError unless db_exists?
19
23
 
20
24
  backup!
25
+ check_backup!
21
26
  upload! if configured?
22
27
 
23
28
  "Database '#{database}' backed up to #{location}"
@@ -30,7 +35,11 @@ module Pgchief
30
35
  private
31
36
 
32
37
  def backup!
33
- `pg_dump -Fc #{database} -f #{local_location}`
38
+ `pg_dump -Fc #{Pgchief::Config.pgurl}/#{database} -f #{local_location}`
39
+ end
40
+
41
+ def check_backup!
42
+ raise Pgchief::Errors::BackupError, "Backup file has 0 bytes" unless File.size?(local_location)
34
43
  end
35
44
 
36
45
  def db_exists?
@@ -27,6 +27,9 @@ module Pgchief
27
27
  def grant_privs! # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
28
28
  conn = PG.connect("#{Pgchief::Config.pgurl}/#{database}")
29
29
  conn.exec("GRANT CONNECT ON DATABASE #{database} TO #{username};")
30
+ conn.exec("GRANT CREATE ON DATABASE #{database} TO #{username};")
31
+ conn.exec("GRANT USAGE ON SCHEMA pg_catalog TO #{username};")
32
+ conn.exec("GRANT CREATE ON SCHEMA pg_catalog TO #{username};")
30
33
  conn.exec("GRANT CREATE ON SCHEMA public TO #{username};")
31
34
  conn.exec("GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO #{username};")
32
35
  conn.exec("GRANT USAGE ON SCHEMA public TO #{username};")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgchief
4
- VERSION = "0.5.2"
4
+ VERSION = "0.5.3"
5
5
  end
data/lib/pgchief.rb CHANGED
@@ -50,5 +50,6 @@ module Pgchief
50
50
  class UserExistsError < Error; end
51
51
  class DatabaseExistsError < Error; end
52
52
  class DatabaseMissingError < Error; end
53
+ class BackupError < Error; end
53
54
  end
54
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgchief
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Oliveira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-17 00:00:00.000000000 Z
11
+ date: 2024-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3