pgchief 0.3.0 → 0.3.1

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: 756ccf173c3d0cbe56bb969e2f7d20e9032e1a7b1c600155e212548fa81f93bb
4
- data.tar.gz: c00f369d5e6013bedb955daba82da8c54ad2a77c978b2ead411cae3ef0ca5f0f
3
+ metadata.gz: 627e9af2dc140bd7210c9f4e999f5be13ba0bf514e6397619d42bef8a6d8b838
4
+ data.tar.gz: 78a5456432854cebd9b6d6fb68f9f02256a9a37c626ac0d78ef35b3bf79f4f21
5
5
  SHA512:
6
- metadata.gz: 5ec3b0a81250bd7c8b479780ec658adf5a51f7f19db08c0447f1470ba4477cee24c7a00affec84ba5db0cf136a18e02de636e1d2f6701f0b6aa13d3ffee88afa
7
- data.tar.gz: 828bf9aebb8235af34a0462f2d2890e5d51245e98841c97644a1d4411ba9147d5f9a1b594c2367f0dd34a96dff47f45201d0d312e8b862e90f27f83b5aad4514
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
- # make sure the DATABASE_URL is set to the connection string for a pg server's superuser
34
- export DATABASE_URL=postgresql://postgres:password@postgres.local:5432
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
  ```
@@ -12,7 +12,7 @@ module Pgchief
12
12
 
13
13
  def initialize(*params)
14
14
  @params = params
15
- @conn = PG.connect(Pgchief::DATABASE_URL)
15
+ @conn = PG.connect(Pgchief::Config.pgurl)
16
16
  end
17
17
 
18
18
  def call
@@ -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::DATABASE_URL}/#{database}")
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::DATABASE_URL,
53
+ Pgchief::Config.pgurl,
54
54
  username: username,
55
55
  password: password,
56
56
  database: database
@@ -49,7 +49,7 @@ module Pgchief
49
49
 
50
50
  def connection_string
51
51
  ConnectionString.new(
52
- Pgchief::DATABASE_URL,
52
+ Pgchief::Config.pgurl,
53
53
  username: username,
54
54
  password: password
55
55
  ).to_s
@@ -8,8 +8,9 @@ module Pgchief
8
8
  class << self
9
9
  attr_accessor \
10
10
  :backup_dir,
11
- :credentials_file,
12
- :pgurl
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
 
@@ -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::DATABASE_URL)
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::DATABASE_URL)
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" }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgchief
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/pgchief.rb CHANGED
@@ -36,8 +36,6 @@ require "pgchief/command/user_drop"
36
36
  require "pgchief/command/user_list"
37
37
 
38
38
  module Pgchief
39
- DATABASE_URL = ENV.fetch("DATABASE_URL")
40
-
41
39
  class Error < StandardError; end
42
40
 
43
41
  module Errors
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.0
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 00:00:00.000000000 Z
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.5.21
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.