Skip to content

Instantly share code, notes, and snippets.

@davidteren
Last active July 13, 2023 00:57
Show Gist options
  • Save davidteren/dac38a1d85636731b93b3e8ec2026ddb to your computer and use it in GitHub Desktop.
Save davidteren/dac38a1d85636731b93b3e8ec2026ddb to your computer and use it in GitHub Desktop.
Script to update dependencies and reset the db.
#!/usr/bin/env ruby
require "fileutils"
# path to your application root.
APP_ROOT = File.expand_path("..", __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
def continue
puts "Press Enter to continue\r"
gets
end
FileUtils.chdir APP_ROOT do
# This script is a way to update your development environment automatically.
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
# Add necessary setup steps to this file.
puts "== Starting Respawn =="
puts "Warning! Be sure to stop all Procfile managed processes"
continue
puts "== Installing dependencies =="
system! "gem install bundler -v \"$(grep -A 1 \"BUNDLED WITH\" Gemfile.lock | tail -n 1)\""
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")
# Install JavaScript dependencies
system! "bin/yarn --check"
puts "\n== Clear Redis queues =="
system! "redis-cli flushall"
puts "\n== Preparing & seeding database =="
# db:setup rebuilds the database structure for both test and development
# and then runs db:seed
# db:reset command will drop the database and set it up again.
# This is functionally equivalent to db:drop db:setup.
system! "bin/rails db:reset"
puts "\n== Completed! =="
puts "You may start your Procfile managed processes now."
end
@peterberkenbosch
Copy link

Thanks @davidteren, very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment