Execute the Rails-generated bin/setup
script
After generating the new project’s scaffolding, the first thing we’ll do is ensure that the application is executable.
Rails generates an executable bin/setup
file that automates some of
the development environment configuration process, including:
- installing Ruby dependencies
- ensuring that SQL databases exist
- removing old
log/
andtmp/
directories - restarting any running Rails servers
This commit un-comments a Rails-generated line so that the script will
also install our project’s JavaScript dependencies with
yarn
.
When we execute bin/setup
for the first time, an error is raised:
== Installing dependencies ==
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ru
by but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle
lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
The Gemfile's dependencies are satisfied
yarn install v1.15.2
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
error @rails/webpacker@4.0.2: The engine "node" is incompatible with this module. Expected version ">=6.14.4". Got "6.14.2"
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
For emphasis, the line of that error message that is most interesting:
error @rails/webpacker@4.0.2: The engine "node" is incompatible with
this module. Expected version ">=6.14.4". Got "6.14.2"
By executing rails new
, Rails has already generated a .ruby-version
file on our behalf.
Locally, we’re using the asdf
Tool Version Manager to ensure
that our the versions of our languages that this project depends on are
available.
Out-of-the-box, ASDF expects all dependencies to be declared in
the .tool-versions
file, so this commit first renames .ruby-version
to .tool-versions
.
To respond to the error raised by Webpacker, this commit extends that
.tool-versions
file to configure the asdf-nodejs
plugin.
Our .tool-versions
file declares that the project
requires Node version 11.14.0
, which meets the ">=6.14.4"
requirement.
By running bin/setup
again, a new error is raised:
== Preparing database ==
Created database 'db/development.sqlite3'
Created database 'db/test.sqlite3'
/Users/seanpdoyle/src/prix-fixe/db/schema.rb doesn't exist yet. Run `rails db:migrate` to create it, then try again. If you do $
ot intend to use a database, you should instead alter /Users/seanpdoyle/src/prix-fixe/config/application.rb to limit the framew$
rks that will be loaded.
== Command ["bin/rails db:setup"] failed ==
For emphasis, the most interesting part of the error message is:
/Users/seanpdoyle/src/prix-fixe/db/schema.rb doesn't exist yet. Run
`rails db:migrate` to create it, then try again.
To resolve this issue, run:
% rails db:migrate
This commit includes the output of that command in the
db/schema.rb
file.