pgai 0.2.1 → 0.2.3

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: 7c07781fdcd787b0aaba1d7fe23afcb6e63ee1b5da7900ac454bd9d2e95dde4f
4
- data.tar.gz: 3ff5e06bc552e96b04359bca358f83563f11d76eed0cd205d4d8210ab9f86604
3
+ metadata.gz: 16b287abec3a2748a73207afe42f679c03055a989496ba5610bcae530f565352
4
+ data.tar.gz: c2414c821b4fbf99fe12e7d8031c40cc17aa437a33a68d0a4ecdb8c2586418fd
5
5
  SHA512:
6
- metadata.gz: 82dc1b7d5aea1922e36753731125e85239c1a4d03e7bcaeb172e37c4db959fdbee24aa55ecaaf82eeb6312ade4b15efcbf827687acf0012eb135487b6b918bd3
7
- data.tar.gz: 3308fcc8359891f10b550e20f448ca0e0e32e1ee00753aedbfcf08bd90efe18de7a932fd3de3dd43c841468a45280b663a664d854eb823a98de516a2bb6d7a9d
6
+ metadata.gz: d113076e6e8568cea4bbf34a9c6e2101c0375063e9458baafd87a2510ef2ff79f912d082adeec6abfdd0177dcf349fec59b76c0c2544d933522b437a1fca370a
7
+ data.tar.gz: cbe551ec80fe9a53b47f8d99789fd603bf01d5b4217f34d6df1eded1a2ae6005cad94006ddcba52b00acea28be5b841eca71db32f4eca724e59bc3f9374e62f4
data/README.md CHANGED
@@ -63,6 +63,12 @@ pgai connect <env alias>
63
63
 
64
64
  Multiple `connect` commands for an environment will connect to the same clone, it won't start a new one.
65
65
 
66
+ `pgai info <env alias>` prints out a database URL variable that can be used from Rails to integrate with dblab. Example for `CI` database:
67
+
68
+ ```shell
69
+ CI_DATABASE_URL="postgresql://foo:bar@localhost:9000/foo_test" bin/rails c -e test
70
+ ```
71
+
66
72
  ### Features
67
73
 
68
74
  - multiple psql sessions to the same clone
data/lib/pgai/cli/main.rb CHANGED
@@ -40,6 +40,18 @@ module Pgai::Cli
40
40
  print_table data
41
41
  end
42
42
 
43
+ desc "exp", "Show clone details"
44
+ method_option :only, aliases: "-o", desc: "Configure only this variable", repeatable: true
45
+ def exp(*command)
46
+ envs = options.fetch(:only) { configuration.enviroments.keys }
47
+ clones = envs.each_with_object({}) { |env, acc|
48
+ acc[env] = Pgai::CloneManager.new(configuration.enviroments.fetch(env), config: configuration).clone
49
+ }
50
+ vars = clones.map { |env, clone| ["#{env.to_s.upcase}_DATABASE_URL", clone.database_url] }.to_h
51
+
52
+ exec(vars, *command)
53
+ end
54
+
43
55
  desc "env", "Manage environments"
44
56
  subcommand "env", Pgai::Cli::Env
45
57
  end
@@ -41,13 +41,23 @@ module Pgai
41
41
  clone = find_clone
42
42
  return {} unless clone
43
43
 
44
+ database_url = "#{enviroment_alias.to_s.upcase}_DATABASE_URL='#{clone.database_url}'"
45
+
44
46
  {
45
- connection_string: clone.connection_string,
47
+ psql_connection_string: clone.connection_string,
48
+ rails_database_url: database_url,
46
49
  created_at: clone.created_at,
47
50
  data_state_at: clone.data_state_at
48
51
  }
49
52
  end
50
53
 
54
+ def clone
55
+ configure_enviroment
56
+ clone = find_or_create_clone
57
+ port_forward.start(clone.port)
58
+ clone
59
+ end
60
+
51
61
  private
52
62
 
53
63
  attr_reader :environment, :config, :port_forward, :dblab
@@ -115,8 +125,12 @@ module Pgai
115
125
  environment.fetch(:port)
116
126
  end
117
127
 
128
+ def enviroment_alias
129
+ environment.fetch(:alias)
130
+ end
131
+
118
132
  def clone_id
119
- @clone_id ||= [config.clone_prefix, environment.fetch(:alias)].join("_")
133
+ @clone_id ||= [config.clone_prefix, enviroment_alias].join("_")
120
134
  end
121
135
 
122
136
  def clone_user
data/lib/pgai/config.rb CHANGED
@@ -10,6 +10,10 @@ module Pgai
10
10
  def connection_string
11
11
  "'host=#{host} port=#{port} user=#{user} dbname=#{dbname} password=#{password}'"
12
12
  end
13
+
14
+ def database_url
15
+ "postgresql://#{user}:#{password}@#{host}:#{port}/#{dbname}"
16
+ end
13
17
  end
14
18
 
15
19
  attr_accessor :clone_prefix
@@ -68,7 +72,7 @@ module Pgai
68
72
 
69
73
  def persist_clone(id, attributes = {})
70
74
  store.transaction do
71
- store[:clones] = {}
75
+ store[:clones] ||= {}
72
76
  store[:clones].merge!(id => attributes)
73
77
  end
74
78
 
data/lib/pgai/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pgai
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.3"
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.2.1
4
+ version: 0.2.3
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-05-10 00:00:00.000000000 Z
11
+ date: 2023-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor