Rails CLI Commands for Elixir & Phoenix
At first glance, Elixir might look like Ruby, but it’s not Ruby, anyone who has worked in both languages for any amount of time should back that up. But just because it’s not Ruby, doesn’t mean that Rubyists should be turned off by Elixir, and all that it has to offer, including the Phoenix Framework.
When you install Elixir, you also get a tool called “mix” which basically handles and performs the functionality that “rails” and “rake do in a Rails project. Here is a list of standard rails/rake commands, and their mix equivalents.
Generate New App
# Rails
$ rails new <app_name>
# Mix
$ mix phoenix.new <app_name>
As with rails, mix will create a new sub-directory with the app name, and will install a new Phoenix application inside that directory.
Launch a Server
# Rails
$ rails server
# Mix
$ iex -S mix phoenix.server
Launch a Console
# Rails
$ rails console
# Mix
$ iex -S mix
Install Dependencies
# Rails
$ bundle install
# Mix
$ mix deps.get
Update Dependencies
# Rails
$ bundle update <gem_name>
$ bundle update
# Mix
$ mix deps.update <package_name>
$ mix deps.update --all
View Routes
# Rails
$ rake routes
# Mix
$ mix phoenix.routes
Migrate Database
# Rails
$ rake db:migrate
# Mix
$ mix ecto.migrate
Ecto is the Elixir package used to communicate with our database, and you will notice it’s used in place of “db” for most rake/rails commands.
Rollback Migration
# Rails
$ rake db:rollback
# Mix
$ mix ecto.rollback
Create Database
# Rails
$ rake db:create
# Mix
$ mix ecto.create
Drop Database
# Rails
$ rake db:drop
# Mix
$ mix ecto.drop
Generate a Migration
# Rails
$ rails g migration CreatePictures
# Mix
$ mix ecto.gen.migration create_pictures
Run Tests
# Rails
$ rake test
# Mix
$ mix test