Class: GTA::HerokuDB

Inherits:
Object
  • Object
show all
Includes:
Sh
Defined in:
lib/gta/heroku_db.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sh

#commander, #sh, #sh!

Constructor Details

#initialize(app, env) ⇒ HerokuDB

Returns a new instance of HerokuDB.



7
8
9
10
# File 'lib/gta/heroku_db.rb', line 7

def initialize(app, env)
  @env = env
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



5
6
7
# File 'lib/gta/heroku_db.rb', line 5

def app
  @app
end

#database_yml_pathObject (readonly)

Returns the value of attribute database_yml_path.



5
6
7
# File 'lib/gta/heroku_db.rb', line 5

def database_yml_path
  @database_yml_path
end

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/gta/heroku_db.rb', line 5

def env
  @env
end

Instance Method Details

#app_signatureObject



32
33
34
# File 'lib/gta/heroku_db.rb', line 32

def app_signature
  "#{app}-#{env}"
end

#backupObject



16
17
18
# File 'lib/gta/heroku_db.rb', line 16

def backup
  sh("heroku pgbackups:capture --expire --app #{app_signature}")
end

#fetchObject



24
25
26
# File 'lib/gta/heroku_db.rb', line 24

def fetch
  sh!("curl -o #{file_name} \"#{url}\"")
end

#file_nameObject



28
29
30
# File 'lib/gta/heroku_db.rb', line 28

def file_name
  "~/Downloads/#{app_signature}.sql"
end

#restore_from(url) ⇒ Object



20
21
22
# File 'lib/gta/heroku_db.rb', line 20

def restore_from(url)
  sh!("heroku pgbackups:restore DATABASE_URL \"#{url}\" --app #{app_signature} --confirm #{app_signature}")
end

#urlObject



12
13
14
# File 'lib/gta/heroku_db.rb', line 12

def url
  sh!("heroku pgbackups:url --app #{app_signature}").strip
end