#25: Moving to Elixir Part 1
Elixir 1.4.5
Phoenix 1.3
MySQL 5.7
Download the sql here: dealership_course.sql
Setting up MySQL
I’m using a Mac with Homebrew. My installation was:
$ brew install mysql
Or you can watch this video
In this series we’ll build a new Phoenix application with data exported from an existing database. This will give us an introduction to moving an existing application to Elixir.
The application we’re going to build is a website for a car dealership. While the site will be fairly straightforward - we’ll get to cover some fundamental parts of Elixir and Phoenix
For example we’ll learn how to map existing database tables and columns to Ecto, define a context, we’ll even get to write a module that imports new inventory using Erlang and Flow.
In this episode we’ll create our repo and load the existing data into a new database.
Let’s get started.
The first thing we need to do is create our new Elixir project.
Let’s go to the command line to create a new project named dealership. Because a new Phoenix app uses Postgres by default and our existing database is MySQL, we’ll need to pass in the database flag with mysql
, which sets our new Phoenix app up to use MySQL.
$ mix phx.new dealership --database mysql
And we’ll install the dependencies.
$ Y
Now let’s cd into our new project:
$ cd dealership
And we’ll need to configure our application to use MySQL. Let’s open our dev.exs
and make sure our configuration looks good and is updated with your local MySQL details:
config/dev.exs...
# Configure your database
config :dealership, Dealership.Repo,
adapter: Ecto.Adapters.MySQL,
username: "root",
password: "",
database: "dealership_dev",
hostname: "localhost",
pool_size: 10
And then we can create our database:
$ mix ecto.create
With that, let’s start up our server to make sure everything is running.
$ mix phx.server
And great - everything looks good.
Now let’s load our existing database, which you can download here or in the notes above as a file named dealership_course.sql
.
Let’s go ahead and import it. I’ll use the MySQL client Sequel Pro - but you can use whatever method you’d like.
And if we inspect what was imported we should see a table named cars
with 25 rows loaded.
It looks like everything imported successfully.