pgai 0.1.7 → 0.2.0

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: '028a01e72ff3ca2ffa39e2cf32e400b2e375d79da46f65c51f746d5667dc0719'
4
- data.tar.gz: 8f2ea632ff8d19a4382af4b5647a322ef9489da49ccdfa4f462779eb9d184456
3
+ metadata.gz: fd5bb462021691510f2c194497d6fb87ef5e100a9c48d7ca1c9afab037774628
4
+ data.tar.gz: 636221fc95e3cc65f22267fe0d922129749104d9eaf9658e15e408cd8b2df1e0
5
5
  SHA512:
6
- metadata.gz: 9b561b90c9a9d9fd230534eb08e0c2c713302f8789a16a4536639a941355f1d6234240d93b2baf55f4845e23ad3377b62f1b075d03a2b9ff1ca26b17cdca4b88
7
- data.tar.gz: e46cb2fa48461f6986ee5e41d00aa6d7022d91906f14abf78e0620b85c83ae77c3a6ed4f60392de922b91f79e2c569792efbedf058edc5017d203d38bbfcde31
6
+ metadata.gz: f3cdda7843c5752d3fcfd0bcae46b4184c2104800d9c071eb056b2f719be7f905f2c88ac92ba2bac9af825afdf446e2f8e674b34d2d39476024ebd1f89fc6e7b
7
+ data.tar.gz: 39b881e6da03d37b8950bedad53e1d2093260f85bb1ee8a4640ad1e1f2d90d931d2a4eef11de89b5173fa9ae644277f52f22309b334789ad1257043cde5d993e
data/README.md CHANGED
@@ -25,7 +25,7 @@ An access token will be required and it can be obtained from: https://console.po
25
25
  Example:
26
26
 
27
27
  ```shell
28
- pgai config --dbname=gitlabhq_dblab --prefix=<gitlab handle> --proxy=<domain> --exe=<optional /path/to/dblab>
28
+ pgai config --dbname=gitlabhq_dblab --prefix=<gitlab handle> --proxy=<alias> --exe=<optional /path/to/dblab>
29
29
  ```
30
30
 
31
31
  To configure environments:
@@ -36,12 +36,13 @@ pgai env add --alias ci --id ci-database --port 12345
36
36
 
37
37
  The environment id, port, and proxy domain can be found by clicking on the `Connect` button on a database instance page.
38
38
 
39
- Configuring the user and identity file for the proxy domain must be done using the `~/.ssh/config` file. Example:
39
+ Configuring the proxy attributes must be done via the `~/.ssh/config` file. Example:
40
40
 
41
41
  ```
42
- Host <domain>
43
- IdentityFile ~/.ssh/id_ed25519
42
+ Host <alias>
43
+ HostName <domain.postgres.ai>
44
44
  User <username>
45
+ IdentityFile ~/.ssh/id_ed25519
45
46
  ```
46
47
 
47
48
  ## dblab binary file
data/lib/pgai/cli/main.rb CHANGED
@@ -2,7 +2,7 @@ module Pgai::Cli
2
2
  class Main < Base
3
3
  desc "config", "Configure CLI options"
4
4
  method_option :prefix, aliases: "-p", desc: "Specify prefix name to be used for clones", required: true
5
- method_option :dbname, aliases: "-n", desc: "Specify database name to connect to by default", required: true
5
+ method_option :dbname, aliases: "-n", desc: "Specify database name to connect to by default", required: true, default: "postgres"
6
6
  method_option :proxy, aliases: "-x", desc: "Specify proxy host name", required: true
7
7
  method_option :exe, aliases: "-e", desc: "dblab binary path"
8
8
  def config
@@ -25,6 +25,14 @@ module Pgai::Cli
25
25
  Pgai::CloneManager.new(env, config: configuration).cleanup
26
26
  end
27
27
 
28
+ desc "info database-name", "Show clone details"
29
+ def info(name)
30
+ env = configuration.enviroments.fetch(name)
31
+
32
+ data = Pgai::CloneManager.new(env, config: configuration).info
33
+ print_table data
34
+ end
35
+
28
36
  desc "env", "Manage environments"
29
37
  subcommand "env", Pgai::Cli::Env
30
38
  end
@@ -28,6 +28,19 @@ module Pgai
28
28
  port_forward.stop
29
29
  end
30
30
 
31
+ def info
32
+ configure_enviroment
33
+
34
+ clone = find_clone
35
+ return {} unless clone
36
+
37
+ {
38
+ connection_string: clone.connection_string,
39
+ created_at: clone.created_at,
40
+ data_state_at: clone.data_state_at
41
+ }
42
+ end
43
+
31
44
  private
32
45
 
33
46
  attr_reader :environment, :config, :port_forward, :dblab
@@ -45,7 +58,7 @@ module Pgai
45
58
  raw_clone = find_raw_clone
46
59
 
47
60
  if raw_clone
48
- config.find_clone(clone_id) || raise(Pagi::CloneNotFount, "clone not tracked")
61
+ config.find_clone(clone_id) || raise(Pgai::CloneNotFount, "clone not tracked")
49
62
  else
50
63
  config.remove_clone(clone_id) && nil
51
64
  end
@@ -63,13 +76,16 @@ module Pgai
63
76
  password: clone_password,
64
77
  user: clone_user,
65
78
  host: HOSTNAME,
66
- dbname: config.dbname
79
+ dbname: config.dbname,
80
+ created_at: raw_clone["createdAt"],
81
+ data_state_at: raw_clone.dig("snapshot", "dataStateAt")
67
82
  }
68
83
 
69
84
  config.persist_clone(clone_id, attributes)
70
85
  end
71
86
 
72
87
  def psql(clone)
88
+ puts "Data state at: #{clone.data_state_at}"
73
89
  port_forward.start(clone.port)
74
90
 
75
91
  psql_pid = fork do
@@ -101,7 +117,7 @@ module Pgai
101
117
  end
102
118
 
103
119
  def clone_password
104
- @clone_user ||= SecureRandom.hex(16)
120
+ @clone_password ||= SecureRandom.hex(16)
105
121
  end
106
122
 
107
123
  def start_caffeinate(pid)
data/lib/pgai/config.rb CHANGED
@@ -6,7 +6,7 @@ require "fileutils"
6
6
 
7
7
  module Pgai
8
8
  class Config
9
- Clone = Struct.new(:host, :port, :password, :user, :dbname, keyword_init: true) do
9
+ Clone = Struct.new(:host, :port, :password, :user, :dbname, :created_at, :data_state_at, keyword_init: true) do
10
10
  def connection_string
11
11
  "'host=#{host} port=#{port} user=#{user} dbname=#{dbname} password=#{password}'"
12
12
  end
data/lib/pgai/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pgai
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marius Bobin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-27 00:00:00.000000000 Z
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor