pgai 0.1.8 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/pgai/cli/main.rb +15 -0
- data/lib/pgai/clone_manager.rb +26 -3
- data/lib/pgai/config.rb +1 -1
- data/lib/pgai/dblab.rb +4 -0
- data/lib/pgai/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c07781fdcd787b0aaba1d7fe23afcb6e63ee1b5da7900ac454bd9d2e95dde4f
|
4
|
+
data.tar.gz: 3ff5e06bc552e96b04359bca358f83563f11d76eed0cd205d4d8210ab9f86604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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=<
|
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
|
39
|
+
Configuring the proxy attributes must be done via the `~/.ssh/config` file. Example:
|
40
40
|
|
41
41
|
```
|
42
|
-
Host <
|
43
|
-
|
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
|
data/lib/pgai/clone_manager.rb
CHANGED
@@ -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(
|
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
|
-
@
|
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
data/lib/pgai/version.rb
CHANGED
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
|
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-
|
11
|
+
date: 2023-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|