mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Factorize bin/update in bin/setup, and make bin/setup idempotent
`bin/setup` and `bin/update` are currently almost the same file. The only thing that keeps them apart is that one is running `bin/rails db:setup` and the other `bin/rails db:migrate`. I'm suggesting here that they should be a unique script, which needs to be idempotent. - New to a project, need to get started? `bin/setup` - Need to install new dependencies that were added recently? `bin/setup`. Before deprecating `bin/update`, I'm suggesting we just have it call `bin/setup`.
This commit is contained in:
parent
7424d2fd2e
commit
6f73a31c0c
3 changed files with 14 additions and 50 deletions
|
@ -8,7 +8,8 @@ def system!(*args)
|
|||
end
|
||||
|
||||
FileUtils.chdir APP_ROOT do
|
||||
# This script is a starting point to setup your application.
|
||||
# This script is a way to setup or update your development environment automatically.
|
||||
# This script is idempotent, so that you can run it at anytime and get an expectable outcome.
|
||||
# Add necessary setup steps to this file.
|
||||
|
||||
puts '== Installing dependencies =='
|
||||
|
@ -27,7 +28,7 @@ FileUtils.chdir APP_ROOT do
|
|||
# end
|
||||
|
||||
puts "\n== Preparing database =="
|
||||
system! 'bin/rails db:setup'
|
||||
system! 'bin/rails db:prepare'
|
||||
<% end -%>
|
||||
|
||||
puts "\n== Removing old logs and tempfiles =="
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
require 'fileutils'
|
||||
|
||||
# path to your application root.
|
||||
APP_ROOT = File.expand_path('..', __dir__)
|
||||
|
||||
def system!(*args)
|
||||
system(*args) || abort("\n== Command #{args} failed ==")
|
||||
end
|
||||
|
||||
FileUtils.chdir APP_ROOT do
|
||||
# This script is a way to update your development environment automatically.
|
||||
# Add necessary update steps to this file.
|
||||
|
||||
puts '== Installing dependencies =='
|
||||
system! 'gem install bundler --conservative'
|
||||
system('bundle check') || system!('bundle install')
|
||||
<% unless options.skip_javascript? -%>
|
||||
|
||||
# Install JavaScript dependencies
|
||||
# system('bin/yarn')
|
||||
<% end -%>
|
||||
<% unless options.skip_active_record? -%>
|
||||
|
||||
puts "\n== Updating database =="
|
||||
system! 'rails db:migrate'
|
||||
<% end -%>
|
||||
|
||||
puts "\n== Removing old logs and tempfiles =="
|
||||
system! 'rails log:clear tmp:clear'
|
||||
|
||||
puts "\n== Restarting application server =="
|
||||
system! 'rails restart'
|
||||
end
|
|
@ -6,21 +6,12 @@ module ApplicationTests
|
|||
class BinSetupTest < ActiveSupport::TestCase
|
||||
include ActiveSupport::Testing::Isolation
|
||||
|
||||
def setup
|
||||
build_app
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
end
|
||||
setup :build_app
|
||||
teardown :teardown_app
|
||||
|
||||
def test_bin_setup
|
||||
Dir.chdir(app_path) do
|
||||
app_file "db/schema.rb", <<-RUBY
|
||||
ActiveRecord::Schema.define(version: 20140423102712) do
|
||||
create_table(:articles) {}
|
||||
end
|
||||
RUBY
|
||||
rails "generate", "model", "article"
|
||||
|
||||
list_tables = lambda { rails("runner", "p ActiveRecord::Base.connection.tables").strip }
|
||||
File.write("log/test.log", "zomg!")
|
||||
|
@ -28,15 +19,20 @@ module ApplicationTests
|
|||
assert_equal "[]", list_tables.call
|
||||
assert_equal 5, File.size("log/test.log")
|
||||
assert_not File.exist?("tmp/restart.txt")
|
||||
|
||||
`bin/setup 2>&1`
|
||||
assert_equal 0, File.size("log/test.log")
|
||||
assert_equal '["articles", "schema_migrations", "ar_internal_metadata"]', list_tables.call
|
||||
assert_equal '["schema_migrations", "ar_internal_metadata", "articles"]', list_tables.call
|
||||
assert File.exist?("tmp/restart.txt")
|
||||
end
|
||||
end
|
||||
|
||||
def test_bin_setup_output
|
||||
Dir.chdir(app_path) do
|
||||
# SQLite3 seems to auto-create the database on first checkout.
|
||||
rails "db:system:change", "--to=postgresql"
|
||||
rails "db:drop"
|
||||
|
||||
app_file "db/schema.rb", ""
|
||||
|
||||
output = `bin/setup 2>&1`
|
||||
|
@ -53,8 +49,8 @@ module ApplicationTests
|
|||
The Gemfile's dependencies are satisfied
|
||||
|
||||
== Preparing database ==
|
||||
Created database 'db/development.sqlite3'
|
||||
Created database 'db/test.sqlite3'
|
||||
Created database 'app_development'
|
||||
Created database 'app_test'
|
||||
|
||||
== Removing old logs and tempfiles ==
|
||||
|
||||
|
|
Loading…
Reference in a new issue