pgchief 0.5.1 → 0.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22c8374fdee4a24fde56bb1edd737694551b73288643b93078efa5f73c149a1b
4
- data.tar.gz: bbebe5882166def3e96dc08804d695c4c2f9d629735173fbde82dcfcd70aaa1e
3
+ metadata.gz: 8c695989f5431e21f2c33b016b34a7197fb5cca9ea62592391fab10fcdbfe385
4
+ data.tar.gz: 195ab95c85943e54d41455ae25b1458aa538d6bc4b6319685b609de7549504f9
5
5
  SHA512:
6
- metadata.gz: 0fd0d65a33b1370a2dda33e4ecd06710b7140eefe911c4f3f9eadbe2bea81bd272a43b8bf013c472afa0cee035f785bd9336d8521b86210536cef43dffc944a8
7
- data.tar.gz: 3314266704ccb6db85feffdd93a104441565bf89f034295f0ce29d4d3f6783e5ccc134964a409c5885066852f27975c062773b77c6a126cc159dbaace3d8bde3
6
+ metadata.gz: 352d1edab7569b64483b3abf178297cf2a213ff1c24dfdc40f39ecd8548a06acfffd650ae30a7284fba34368c15e7d58c09e9f3153e9cfc8657613fa01fe4da0
7
+ data.tar.gz: e6e5f42192398383a2b8bc481c6a2b5f37722eef72111a04e2250a84bd1ac4125a9e783123ea1b3d4d64d2c3721a177482b3c83fd1bc656cc4d9b564ac2af4fc
data/CHANGELOG.md CHANGED
@@ -13,11 +13,40 @@ 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
+
34
+ ## [0.5.2]
35
+
36
+ ### Changes
37
+
38
+ * Change S3 config option `s3_path_prefix` to `s3_objects_path`.
39
+ * Above change retains backwards compatibility with the old `s3_path_prefix` option.
40
+
41
+ ### Fixes
42
+
43
+ * Fix S3 regex to allow `-` in the path.
44
+
16
45
  ## [0.5.1]
17
46
 
18
47
  ### Changes
19
48
 
20
- * Update README to note that libpq-dev is a required dependency in order to build
49
+ * Update README to note that libpq-dev is a required dependency in order to build.
21
50
 
22
51
  ### Fixes
23
52
 
@@ -27,14 +56,14 @@ and this project will try its best to adhere to [Semantic Versioning](https://se
27
56
 
28
57
  ### Additions
29
58
 
30
- * Restore database from local file(s)
31
- * Restore database from s3
59
+ * Restore database from local file(s).
60
+ * Restore database from s3.
32
61
 
33
62
  ## [0.4.0]
34
63
 
35
64
  ### Changes
36
65
 
37
- * Clean up the config object
66
+ * Clean up the config object.
38
67
 
39
68
  ### Additions
40
69
 
@@ -43,7 +72,7 @@ and this project will try its best to adhere to [Semantic Versioning](https://se
43
72
  ### Fixes
44
73
 
45
74
  * Capture error where the config file does not exist and provide some guidance.
46
- * Make a `PG::ConnectionBad` error a little less scary(?)
75
+ * Make a `PG::ConnectionBad` error a little less scary(?).
47
76
  * Do not inherit the base `Command` class in `ConfigCreate`. It doesn't need to connect to the DB.
48
77
 
49
78
  ## [0.3.1]
@@ -63,24 +92,24 @@ and this project will try its best to adhere to [Semantic Versioning](https://se
63
92
 
64
93
  ### Additions
65
94
 
66
- - Refactor `exe/pgchief` to utilize `TTY::Option` for kicking off config initialization
67
- - `pgchief --init` now creates a toml config file in your `$HOME`
95
+ - Refactor `exe/pgchief` to utilize `TTY::Option` for kicking off config initialization.
96
+ - `pgchief --init` now creates a toml config file in your `$HOME`.
68
97
  - Added ability to store credentials if your config sets `credentials_file`
69
- when db's and users are created
98
+ when db's and users are created.
70
99
  - Added `ConnectionString` class that abstracts the base db connection,
71
- allowing for additions of users and db's
72
- - Load everything in the config file to the Config attributes
100
+ allowing for additions of users and db's.
101
+ - Load everything in the config file to the Config attributes.
73
102
 
74
103
  ### Changes
75
104
 
76
- - Default location of config changed from `~/.pgchief.toml` to `~/.config/pgchief/config.toml`
77
- - Automatically require 'pry' in the test suite
105
+ - Default location of config changed from `~/.pgchief.toml` to `~/.config/pgchief/config.toml`.
106
+ - Automatically require 'pry' in the test suite.
78
107
 
79
108
  ### Fixes
80
109
 
81
110
  - When dropping user, ignore whenever a database has no privileges for the
82
- selected user
83
- - Retroactive addition of tests to cover any regressions
111
+ selected user.
112
+ - Retroactive addition of tests to cover any regressions.
84
113
 
85
114
  ## [0.2.0] - 2024-08-30
86
115
 
@@ -108,7 +137,9 @@ and this project will try its best to adhere to [Semantic Versioning](https://se
108
137
  - Drop user ✅
109
138
  - List databases ✅
110
139
 
111
- [Unreleased]: https://github.com/jayroh/pgchief/compare/v0.5.1...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
142
+ [0.5.2]: https://github.com/jayroh/pgchief/releases/tag/v0.5.2
112
143
  [0.5.1]: https://github.com/jayroh/pgchief/releases/tag/v0.5.1
113
144
  [0.5.0]: https://github.com/jayroh/pgchief/releases/tag/v0.5.0
114
145
  [0.4.0]: https://github.com/jayroh/pgchief/releases/tag/v0.4.0
data/README.md CHANGED
@@ -137,3 +137,5 @@ Give "rando-username" access to database(s):
137
137
  * [x] Restore remote database @ S3
138
138
  * [ ] Quickly back up via command line option
139
139
  * [ ] Quickly restore via command line option
140
+ * [ ] Task for inclusion in a Rakefile
141
+ * [ ] Support environment variables in config
data/config/pgchief.toml CHANGED
@@ -13,4 +13,4 @@ backup_dir = "~/.config/pgchief/backups"
13
13
  # s3_key = ""
14
14
  # s3_secret = ""
15
15
  # s3_region = "us-east-1"
16
- # s3_path_prefix = "s3://bucket-name/database-backups/"
16
+ # s3_objects_path = "s3://bucket-name/database-backups/"
@@ -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};")
@@ -13,9 +13,9 @@ module Pgchief
13
13
  :s3_key,
14
14
  :s3_secret,
15
15
  :s3_region,
16
- :s3_path_prefix
16
+ :s3_objects_path
17
17
 
18
- PREFIX_REGEX = %r{\As3://(?<bucket>(\w|-)*)/(?<path>(\w|/)*/)\z}
18
+ PREFIX_REGEX = %r{\As3://(?<bucket>(\w|-)*)/(?<path>(\w|/|-)*/)\z}
19
19
 
20
20
  attr_reader :config
21
21
 
@@ -44,14 +44,14 @@ module Pgchief
44
44
  s3_key,
45
45
  s3_secret,
46
46
  s3_region,
47
- s3_path_prefix
47
+ s3_objects_path
48
48
  ].none?(&:nil?)
49
49
  end
50
50
 
51
51
  private
52
52
 
53
53
  def s3_match
54
- @s3_match ||= s3_path_prefix.match(PREFIX_REGEX)
54
+ @s3_match ||= s3_objects_path.match(PREFIX_REGEX)
55
55
  end
56
56
  end
57
57
  end
@@ -14,7 +14,7 @@ module Pgchief
14
14
  attr_writer :pgurl
15
15
 
16
16
  attr_reader \
17
- :s3_path_prefix,
17
+ :s3_objects_path,
18
18
  :backup_dir,
19
19
  :credentials_file
20
20
 
@@ -26,7 +26,7 @@ module Pgchief
26
26
  self.s3_key = config[:s3_key]
27
27
  self.s3_secret = config[:s3_secret]
28
28
  self.s3_region = config[:s3_region]
29
- self.s3_path_prefix = config[:s3_path_prefix]
29
+ self.s3_objects_path = config[:s3_objects_path] || config[:s3_path_prefix]
30
30
  rescue Errno::ENOENT
31
31
  puts config_missing_error(toml_file)
32
32
  end
@@ -43,8 +43,8 @@ module Pgchief
43
43
  @backup_dir = value ? "#{value.chomp("/")}/".gsub("~", Dir.home) : "/tmp/"
44
44
  end
45
45
 
46
- def s3_path_prefix=(value)
47
- @s3_path_prefix = value ? "#{value.chomp("/")}/" : nil
46
+ def s3_objects_path=(value)
47
+ @s3_objects_path = value ? "#{value.chomp("/")}/" : nil
48
48
  end
49
49
 
50
50
  def credentials_file=(value)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgchief
4
- VERSION = "0.5.1"
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.1
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-11-28 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
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  requirements: []
163
- rubygems_version: 3.5.21
163
+ rubygems_version: 3.5.23
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: A simple ruby script to manage postgresql databases and users