pgchief 0.3.0 → 0.3.1
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 +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +6 -3
- data/lib/pgchief/command/base.rb +1 -1
- data/lib/pgchief/command/database_privileges_grant.rb +2 -2
- data/lib/pgchief/command/user_create.rb +1 -1
- data/lib/pgchief/config.rb +7 -2
- data/lib/pgchief/database.rb +1 -1
- data/lib/pgchief/user.rb +1 -1
- data/lib/pgchief/version.rb +1 -1
- data/lib/pgchief.rb +0 -2
- metadata +3 -4
- data/LICENSE +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 627e9af2dc140bd7210c9f4e999f5be13ba0bf514e6397619d42bef8a6d8b838
|
4
|
+
data.tar.gz: 78a5456432854cebd9b6d6fb68f9f02256a9a37c626ac0d78ef35b3bf79f4f21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26a19391751adbd9846cd70532becfa91c4f2e6a704405764c207e817f388b5ad900a5993eb2e20b574e09e78a089658b9f1f14591e9ea5f0349476fa7b49c13
|
7
|
+
data.tar.gz: e96db718dd3e594b4f612d47b2d63bfe0792e94b4ba622d9093db6b2d8138c02cf8dc45885557a8048f767d280f597103a410468914496dd937e25b759eb2c18
|
data/CHANGELOG.md
CHANGED
@@ -13,6 +13,19 @@ and this project will try its best to adhere to [Semantic Versioning](https://se
|
|
13
13
|
|
14
14
|
### Fixes
|
15
15
|
|
16
|
+
## [0.3.1]
|
17
|
+
|
18
|
+
### Changes
|
19
|
+
|
20
|
+
- The main database url will be accessed via the config class and will prioritize
|
21
|
+
the ENV over the config file, if it is set.
|
22
|
+
|
23
|
+
### Fixes
|
24
|
+
|
25
|
+
- Do not use the ENV only. Until now that was the only method and it was ignoring
|
26
|
+
what was set in the config file. This fixes the issue where nothing will work
|
27
|
+
if `ENV["DATABASE_URL"]` is not set.
|
28
|
+
|
16
29
|
## [0.3.0]
|
17
30
|
|
18
31
|
### Additions
|
data/README.md
CHANGED
@@ -26,12 +26,15 @@ below for the feature check-list and current progress.
|
|
26
26
|
```sh
|
27
27
|
gem install pgchief
|
28
28
|
|
29
|
-
# To initialize the config file at `~/.pgchief.toml`:
|
29
|
+
# To initialize the config file at `~/.config/pgchief/config.toml`:
|
30
30
|
|
31
31
|
pgchief --init
|
32
32
|
|
33
|
-
#
|
34
|
-
|
33
|
+
# edit the config file and set your main administrative connection string
|
34
|
+
# (vim|nano|pico|ed) ~/.config/pgchief/config.toml
|
35
|
+
|
36
|
+
# OR ... make sure the DATABASE_URL env is set to the connection string
|
37
|
+
# export DATABASE_URL=postgresql://postgres:password@postgres.local:5432
|
35
38
|
|
36
39
|
pgchief
|
37
40
|
```
|
data/lib/pgchief/command/base.rb
CHANGED
@@ -25,7 +25,7 @@ module Pgchief
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def grant_privs! # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
28
|
-
conn = PG.connect("#{Pgchief::
|
28
|
+
conn = PG.connect("#{Pgchief::Config.pgurl}/#{database}")
|
29
29
|
conn.exec("GRANT CONNECT ON DATABASE #{database} TO #{username};")
|
30
30
|
conn.exec("GRANT CREATE ON SCHEMA public TO #{username};")
|
31
31
|
conn.exec("GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO #{username};")
|
@@ -50,7 +50,7 @@ module Pgchief
|
|
50
50
|
|
51
51
|
def connection_string
|
52
52
|
ConnectionString.new(
|
53
|
-
Pgchief::
|
53
|
+
Pgchief::Config.pgurl,
|
54
54
|
username: username,
|
55
55
|
password: password,
|
56
56
|
database: database
|
data/lib/pgchief/config.rb
CHANGED
@@ -8,8 +8,9 @@ module Pgchief
|
|
8
8
|
class << self
|
9
9
|
attr_accessor \
|
10
10
|
:backup_dir,
|
11
|
-
:credentials_file
|
12
|
-
|
11
|
+
:credentials_file
|
12
|
+
|
13
|
+
attr_writer :pgurl
|
13
14
|
|
14
15
|
def load_config!(toml_file = "#{Dir.home}/.config/pgchief/config.toml")
|
15
16
|
config = TomlRB.load_file(toml_file, symbolize_keys: true)
|
@@ -19,6 +20,10 @@ module Pgchief
|
|
19
20
|
@pgurl = config[:pgurl]
|
20
21
|
end
|
21
22
|
|
23
|
+
def pgurl
|
24
|
+
ENV.fetch("DATABASE_URL", @pgurl)
|
25
|
+
end
|
26
|
+
|
22
27
|
def set_up_file_structure!
|
23
28
|
FileUtils.mkdir_p(backup_dir)
|
24
29
|
|
data/lib/pgchief/database.rb
CHANGED
@@ -6,7 +6,7 @@ module Pgchief
|
|
6
6
|
# Database information and operations
|
7
7
|
class Database
|
8
8
|
def self.all
|
9
|
-
conn = PG.connect(Pgchief::
|
9
|
+
conn = PG.connect(Pgchief::Config.pgurl)
|
10
10
|
result = conn.exec("SELECT datname FROM pg_database WHERE datistemplate = false")
|
11
11
|
result
|
12
12
|
.map { |row| row["datname"] }
|
data/lib/pgchief/user.rb
CHANGED
@@ -6,7 +6,7 @@ module Pgchief
|
|
6
6
|
# Database information and operations
|
7
7
|
class User
|
8
8
|
def self.all
|
9
|
-
conn = PG.connect(Pgchief::
|
9
|
+
conn = PG.connect(Pgchief::Config.pgurl)
|
10
10
|
result = conn.exec("SELECT usename FROM pg_user")
|
11
11
|
|
12
12
|
result.map { |row| row["usename"] }.reject { |name| name == "postgres" }
|
data/lib/pgchief/version.rb
CHANGED
data/lib/pgchief.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.1
|
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-
|
11
|
+
date: 2024-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -79,7 +79,6 @@ files:
|
|
79
79
|
- ".rubocop.yml"
|
80
80
|
- CHANGELOG.md
|
81
81
|
- CODE_OF_CONDUCT.md
|
82
|
-
- LICENSE
|
83
82
|
- LICENSE.txt
|
84
83
|
- README.md
|
85
84
|
- Rakefile
|
@@ -140,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
139
|
- !ruby/object:Gem::Version
|
141
140
|
version: '0'
|
142
141
|
requirements: []
|
143
|
-
rubygems_version: 3.
|
142
|
+
rubygems_version: 3.2.33
|
144
143
|
signing_key:
|
145
144
|
specification_version: 4
|
146
145
|
summary: A simple ruby script to manage postgresql databases and users
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2024 Joel Oliveira
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|