Skip to content

Commit

Permalink
Updated Vagrantfile
Browse files Browse the repository at this point in the history
Added triggers to Vagrantfile for up and destroy commands.
After vagrant up is executed an attempt to restore db data accures.
Before vagrant destroy is executed a save to db data accures.
  • Loading branch information
DoRTaL94 committed Apr 25, 2020
1 parent a43367c commit 2d56d44
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
db_file_exists = "test -f /vagrant/edison/db.sql"
restore_db = "sudo -u postgres psql edison < /vagrant/edison/db.sql"
db_restored_msg = "echo \"Database restored.\""
db_not_exists_msg = "echo \"db.sql not exists.\""
try_restore_db = "bash -c '#{db_file_exists} && #{restore_db} && #{db_restored_msg} || #{db_not_exists_msg}'"
save_db_data = "sudo -u postgres pg_dump edison > /vagrant/edison/db.sql"

Vagrant.configure("2") do |config|
config.trigger.before :destroy do |trigger|
trigger.info = "Saving database data inside synced folder..."
trigger.run_remote = {inline: "#{save_db_data}"}
end

config.trigger.after :up do |trigger|
trigger.info = "Trying to restore database from /vagrant/edison/db.sql..."
trigger.run_remote = {inline: "#{try_restore_db}"}
end

config.vm.box = "ubuntu/bionic64"
config.vm.provision :shell, path: "setup.sh"
Expand Down

0 comments on commit 2d56d44

Please sign in to comment.