#!/bin/ruby
#-----------------------------------------------------------------------------------------------------------------------
# command line arguments (passed from run.rb through docker run)
# both are optional; only the first argument takes effect
#  -seed:dev  = delete any existing db, create new db and instantiate schema, create users w/random data
#  -seed:prod = delete any existing db, create new db and instantiate schema, create users w/o data
#  -seed:test = delete any existing db, create new db and instantiate schema, create test-specific data

if [ "-seed:dev", "-seed:prod", "-seed:test" ].include?( ARGV.first )
   %x( ./bin/rails db:drop )
   %x( ./bin/rails db:migrate )
   %x( ./bin/rails db:seed SEED=#{ ARGV.first } )
end

# exec() so stdout of rails server appears on terminal attached to this process (which was created by docker)
exec( "./bin/rails server" )
