Class: Pgai::Dblab

Inherits:
Object
  • Object
show all
Defined in:
lib/pgai/dblab.rb

Constant Summary collapse

DEFAULT_DBLAB =
Pathname.new("~/.dblab/dblab").expand_path
DBLAB_RELEASE_CHANNEL =
"master"
DBLAB_BINARY_URL =
"https://storage.googleapis.com/database-lab-cli/#{DBLAB_RELEASE_CHANNEL}/dblab-%{os}-%{cpu}"

Instance Method Summary collapse

Constructor Details

#initialize(config:, hostname:) ⇒ Dblab

Returns a new instance of Dblab.



15
16
17
18
# File 'lib/pgai/dblab.rb', line 15

def initialize(config:, hostname:)
  @config = config
  @hostname = hostname
end

Instance Method Details

#configure_env(port:, token:, id:) ⇒ Object



20
21
22
23
# File 'lib/pgai/dblab.rb', line 20

def configure_env(port:, token:, id:)
  dblab("init", "--url", "http://#{hostname}:#{port}", "--token", token, "--environment-id", id, silence: true)
  dblab("config", "switch", id, raw: true)
end

#create_clone(id:, user:, password:) ⇒ Object



29
30
31
32
33
34
# File 'lib/pgai/dblab.rb', line 29

def create_clone(id:, user:, password:)
  data = dblab("clone", "create", "--id", id, "--username", user, "--password", password)
  raise "Could not create clone" unless data

  data
end

#destroy_clone(id:) ⇒ Object



36
37
38
# File 'lib/pgai/dblab.rb', line 36

def destroy_clone(id:)
  dblab("clone", "destroy", id, raw: true)
end

#list_clonesObject



25
26
27
# File 'lib/pgai/dblab.rb', line 25

def list_clones
  Array(dblab("clone", "list"))
end