pgai 0.1.8 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03fa1355e1b4ddb4b4377cc88c8a402085c525693719c36a92cc61b76b0c1738
4
- data.tar.gz: fcf92ab74e0a897fd8b0d59ef06cc71963946f648e33462b2f1835f1afd118a2
3
+ metadata.gz: 7c07781fdcd787b0aaba1d7fe23afcb6e63ee1b5da7900ac454bd9d2e95dde4f
4
+ data.tar.gz: 3ff5e06bc552e96b04359bca358f83563f11d76eed0cd205d4d8210ab9f86604
5
5
  SHA512:
6
- metadata.gz: 406edf0028a55c3ee1f86bc4e8702bdac35af844fde8aa6401897ce9f5475296b80255a59f16c4fbf6ceb59d1fdcd0c3c361bb05ed5323bc762e61c94032965d
7
- data.tar.gz: 6d4cbaeecbdea0c3354dd83973192450cdca24e4b7ffa4a3b07d699efa2b8c9fd341c0c025eed1b689821c734b2cd85ba0f05f2aa2d40d9f28768afe8a2f2017
6
+ metadata.gz: 82dc1b7d5aea1922e36753731125e85239c1a4d03e7bcaeb172e37c4db959fdbee24aa55ecaaf82eeb6312ade4b15efcbf827687acf0012eb135487b6b918bd3
7
+ data.tar.gz: 3308fcc8359891f10b550e20f448ca0e0e32e1ee00753aedbfcf08bd90efe18de7a932fd3de3dd43c841468a45280b663a664d854eb823a98de516a2bb6d7a9d
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
@@ -25,6 +25,21 @@ module Pgai::Cli
25
25
  Pgai::CloneManager.new(env, config: configuration).cleanup
26
26
  end
27
27
 
28
+ desc "reset database-name", "Reset clone's state"
29
+ def reset(name)
30
+ env = configuration.enviroments.fetch(name)
31
+
32
+ Pgai::CloneManager.new(env, config: configuration).reset
33
+ end
34
+
35
+ desc "info database-name", "Show clone details"
36
+ def info(name)
37
+ env = configuration.enviroments.fetch(name)
38
+
39
+ data = Pgai::CloneManager.new(env, config: configuration).info
40
+ print_table data
41
+ end
42
+
28
43
  desc "env", "Manage environments"
29
44
  subcommand "env", Pgai::Cli::Env
30
45
  end
@@ -28,6 +28,26 @@ module Pgai
28
28
  port_forward.stop
29
29
  end
30
30
 
31
+ def reset
32
+ configure_enviroment
33
+ return unless find_raw_clone
34
+
35
+ dblab.reset_clone(id: clone_id)
36
+ end
37
+
38
+ def info
39
+ configure_enviroment
40
+
41
+ clone = find_clone
42
+ return {} unless clone
43
+
44
+ {
45
+ connection_string: clone.connection_string,
46
+ created_at: clone.created_at,
47
+ data_state_at: clone.data_state_at
48
+ }
49
+ end
50
+
31
51
  private
32
52
 
33
53
  attr_reader :environment, :config, :port_forward, :dblab
@@ -45,7 +65,7 @@ module Pgai
45
65
  raw_clone = find_raw_clone
46
66
 
47
67
  if raw_clone
48
- config.find_clone(clone_id) || raise(Pagi::CloneNotFount, "clone not tracked")
68
+ config.find_clone(clone_id) || raise(Pgai::CloneNotFount, "clone not tracked")
49
69
  else
50
70
  config.remove_clone(clone_id) && nil
51
71
  end
@@ -63,13 +83,16 @@ module Pgai
63
83
  password: clone_password,
64
84
  user: clone_user,
65
85
  host: HOSTNAME,
66
- dbname: config.dbname
86
+ dbname: config.dbname,
87
+ created_at: raw_clone["createdAt"],
88
+ data_state_at: raw_clone.dig("snapshot", "dataStateAt")
67
89
  }
68
90
 
69
91
  config.persist_clone(clone_id, attributes)
70
92
  end
71
93
 
72
94
  def psql(clone)
95
+ puts "Data state at: #{clone.data_state_at}"
73
96
  port_forward.start(clone.port)
74
97
 
75
98
  psql_pid = fork do
@@ -101,7 +124,7 @@ module Pgai
101
124
  end
102
125
 
103
126
  def clone_password
104
- @clone_user ||= SecureRandom.hex(16)
127
+ @clone_password ||= SecureRandom.hex(16)
105
128
  end
106
129
 
107
130
  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/dblab.rb CHANGED
@@ -37,6 +37,10 @@ module Pgai
37
37
  dblab("clone", "destroy", id, raw: true)
38
38
  end
39
39
 
40
+ def reset_clone(id:)
41
+ dblab("clone", "reset", id, raw: true)
42
+ end
43
+
40
44
  private
41
45
 
42
46
  attr_reader :config, :hostname
data/lib/pgai/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pgai
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.1"
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.8
4
+ version: 0.2.1
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-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor