How to Use Vue.js and Axios to Display Data from an API

The writer chosen Code.org to obtain a $300 donation as a part of the Write for DOnations program.

Introduction

Within the tutorial The best way to Automate Elixir Phoenix Deployment with Distillery and edeliver, you created a Phoenix software with out a database and deployed it to a manufacturing server with edeliver. Most real-world functions require a database which requires some modifications to the deployment course of.

You should use edeliver to push software and database modifications to your manufacturing server on the similar time so you possibly can handle database modifications throughout deployments.

On this information, you may configure your current Phoenix software to hook up with a MySQL database utilizing Phoenix-Ecto and Mariaex. Ecto is a broadly used database wrapper for Phoenix functions. Mariaex is a database driver that integrates with Ecto and talks to MySQL and MariaDB databases.

You may additionally create a easy handle guide in your improvement machine that makes use of a database and use edeliver to deploy the modifications to your manufacturing server. Customers of your web site will be capable to create, learn, replace, and delete entries on this handle guide.

Stipulations

To finish this tutorial, you may want:

Step 1 — Including Mariaex and Ecto to Your Software

Usually, Phoenix functions don’t immediately set up connections to databases and execute SQL queries. As an alternative, a database driver is used to hook up with the specified database and a database wrapper is then used to question the database.

A database driver is an Elixir software that takes care of the mundane duties of utilizing a database corresponding to establishing connections, closing connections and executing queries. The database wrapper is a layer on high of the database driver that permits Elixir programmers to create database queries with Elixir code and offers extra options corresponding to question composition (chaining of queries).

This separation makes for a modular software. The database wrapper, and due to this fact the applying code to work together with the database, is basically the identical whatever the database used. Simply by altering the database driver, Phoenix functions can use a special database software program.

Because you equipped the --no-ecto flag when creating your software within the earlier tutorial, the applying has neither Ecto nor Mariaex put in. You may add Ecto and Mariaex as dependencies in your venture now.

Notice: Phoenix functions use PostgreSQL by default. To generate a brand new software with a MySQL database, use the command combine phx.new --database mysql myproject.

First, change to the listing containing your Phoenix venture.

Then open the combine.exs file, which comprises the listing of dependencies in your software.

Discover the next block of code:

~/myproject/combine.exs

  defp deps do
    [
      {:phoenix, "~> 1.3.0"},
      {:phoenix_pubsub, "~> 1.0"},
      {:phoenix_html, "~> 2.10"},
      {:phoenix_live_reload, "~> 1.0", solely: :dev},
      {:gettext, "~> 0.11"},
      {:cowboy, "~> 1.0"},
      {:edeliver, "~> 1.4.3"},
      {:distillery, "~> 1.4"}
    ]
  finish

Add Mariaex and Phoenix-Ecto as dependencies:

~/myproject/combine.exs

  defp deps do
    [
      {:phoenix, "~> 1.3.0"},
      {:phoenix_pubsub, "~> 1.0"},
      {:phoenix_html, "~> 2.10"},
      {:phoenix_live_reload, "~> 1.0", solely: :dev},
      {:gettext, "~> 0.11"},
      {:cowboy, "~> 1.0"},
      {:edeliver, "~> 1.4.3"},
      {:distillery, "~> 1.4"},
      {:phoenix_ecto, "~> 3.2"},
      {:mariaex, "~> 0.8.2"}
    ]
  finish

Warning: To keep away from potential configuration issues, double-check that you've got added a comma (,) on the finish of the road previous the brand new phoenix_ecto entry.

Save and shut combine.exs. Then run the next command to obtain the dependencies you simply added to the venture.

You may see this output as your dependencies are put in:

Output

Operating dependency decision... ... * Getting phoenix_ecto (Hex package deal) Checking package deal (https://repo.hex.pm/tarballs/phoenix_ecto-3.3.0.tar) Fetched package deal * Getting mariaex (Hex package deal) Checking package deal (https://repo.hex.pm/tarballs/mariaex-0.8.3.tar) Fetched package deal ...

The output reveals that Combine checked for compatibility between the packages and received the packages together with their dependencies from the Hex repository. If this command fails, guarantee that you've Hex put in and have modified combine.exs accurately.

With Ecto and Mariaex in place, you possibly can arrange the Ecto repository.

Step 2 — Setting Up an Ecto Repository in Your Software

Phoenix functions entry the database by way of a database wrapper known as Ecto. The database wrapper is carried out within the type of an Elixir module in your venture. You'll be able to import this module each time you'll want to work together with the database and use the features the module offers. The wrapped database is known as the repository.

This repository module should embrace the Ecto.Repo macro to offer entry to the question features outlined by Ecto. Moreover, it has to comprise the code to initialize the choices handed to the database adapter in a perform named init.

In case you hadn't used the --no-ecto flag when creating your Phoenix venture, Phoenix would have mechanically generated this module for you. However since you probably did, you may should create it your self.

Let's create the module in a file named repo.ex within the lib/myproject listing. First create the file:

  • nano lib/myproject/repo.ex

Add the next code into the file to outline the repository:

~/myproject/lib/myproject/repo.ex

defmodule Myproject.Repo do
  use Ecto.Repo, otp_app: :myproject

  @doc """
  Dynamically masses the repository url from the
  DATABASE_URL setting variable.
  """
  def init(_, opts) do
    {:okay, Key phrase.put(opts, :url, System.get_env("DATABASE_URL"))}
  finish
finish

By default, Phoenix tasks outline the init perform such that if the setting variable DATABASE_URL exists, then Ecto will use the configuration within the setting variable to hook up with the database as an alternative of utilizing the credentials within the Phoenix configuration information (as we do on this tutorial later).

Save and shut repo.ex.

Phoenix tasks use light-weight Elixir processes for concurrency and fault-tolerance. Supervisors handle these processes and restart them, ought to they crash. Supervisors may also supervise different supervisors, and this construction is named a supervision tree.

The Myproject.Repo module you simply added implements a supervisor that manages processes connecting to the database. To begin this supervisor, you have to add it to the venture's supervision tree.

Open the software.ex file within the lib/myproject folder.

  • nano lib/myproject/software.ex

Discover the next block of code which defines the supervision tree:

~/myproject/lib/myproject/software.ex

...
    youngsters = [
      # Begin the endpoint when the applying begins
      supervisor(MyprojectWeb.Endpoint, []),
      ...
    ]
...

You'll be able to see that the applying endpoint, MyprojectWeb.Endpoint, is being began as a supervisor. Add Myproject.Repo to this listing:

~/myproject/lib/myproject/myproject.ex

    youngsters = [
      # Begin the Ecto repository
      supervisor(Myproject.Repo, []),
      # Begin the endpoint when the applying begins
      supervisor(MyprojectWeb.Endpoint, []),
      ...
    ]

In case you skip this step, Ecto won't create processes to work together with the database and any try and work together with the database will trigger the applying to crash.

Save and shut software.ex earlier than persevering with.

Lastly, specify the Ecto repository within the software configuration so you should utilize Combine duties like ecto.create and ecto.migrate to create and handle your database.

Open the configuration file at config/config.exs.

Find the next line on the finish of the file:

~/myproject/config/config.exs

import_config "#{Mix.env}.exs"

This line permits environment-specific configuration information, corresponding to prod.exs and check.exs, to override the settings in config.exs if crucial. Add the next code above that line to configure the Ecto repository:

~/myproject/config/config.exs

...

config :myproject,
  ecto_repos: [Myproject.Repo]
...

Save your modifications and shut the file.

Now that you've Ecto configured, transfer on to including your database credentials to the applying.

Step 3 — Configuring Your Software with MySQL Credentials

There are three conditions through which your software would connect with a database: throughout improvement, throughout testing and through manufacturing.

Correspondingly, Phoenix offers three environment-specific configuration information that comprise credentials related to the setting the applying is working in. These information are positioned within the config listing within the root of the venture. You may modify these three information on this step.

First, let's configure the event setting. Open dev.exs.

Add the next strains to configure the database adapter to be Ecto.Adapters.MySQL since we're utilizing MySQL.

~/myproject/config/dev.exs

config :myproject, Myproject.Repo,
  adapter: Ecto.Adapters.MySQL

Subsequent, specify the specified identify of the database in the identical code block.

~/myproject/config/dev.exs

config :myproject, Myproject.Repo,
  adapter: Ecto.Adapters.MySQL,
  database: "myproject_dev"

Right here, we outline the event database identify to be myproject_dev. It is a naming conference Phoenix apps use for databases. Following this conference, the manufacturing database can be known as myproject_prod and the check database myproject_test. You should use your individual naming scheme as an alternative.

Now, present the hostname, username, and password in your improvement database server.

~/myproject/config/dev.exs

config :myproject, Myproject.Repo,
  adapter: Ecto.Adapters.MySQL,
  database: "myproject_dev",
  username: "root",
  password: "password",
  hostname: "localhost"

Lastly, set the pool dimension to an acceptable quantity. The pool dimension is the utmost variety of connections to the database that the applying can have. These connections will probably be shared throughout requests. The optimum dimension is dependent upon your {hardware} however you should utilize 10 to begin.

~/myproject/config/dev.exs

config :myproject, Myproject.Repo,
  adapter: Ecto.Adapters.MySQL,
  username: "root",
  password: "password",
  database: "myproject_dev",
  hostname: "localhost",
  pool_size: 10

Save and shut dev.exs.

Subsequent, configure your check setting. Open the check setting configuration file check.exs.

On this tutorial, we'll host the check database on the native database server alongside the event database. As such, the configurations for the check database are virtually the identical.

As an alternative of pool dimension, nonetheless, we specify Ecto.Adapters.SQL.Sandbox for the pool worth. This can run checks in a sandbox mode. That's, any transactions made with the check database throughout a check will probably be rolled again. And this implies unit checks could be run in a random order because the database is reset to the preliminary state after every check.

And we'll use myproject_test because the database identify.

Add the next configuration to the check.exs file:

~/myproject/config/check.exs

config :myproject, Myproject.Repo,
  adapter: Ecto.Adapters.MySQL,
  username: "root",
  password: "password",
  database: "myproject_test",
  hostname: "localhost",
  pool: Ecto.Adapters.SQL.Sandbox

Save and shut check.exs.

Lastly, to configure the credentials in your software in manufacturing, open your manufacturing secret file, prod.secret.exs.

  • nano config/prod.secret.exs

Add this code into the prod.secret.exs file. Notice that we're utilizing the username myproject right here with the password password. . We'll create this person on the manufacturing database server shortly, utilizing the password specified right here. You may wish to use a safer password right here.

~/myproject/config/prod.secret.exs

config :myproject, Myproject.Repo,
  adapter: Ecto.Adapters.MySQL,
  username: "myapp",
  password: "password",
  database: "myproject_prod",
  hostname: "localhost",
  pool_size: 10

Save your modifications and shut the file.

This file will not be tracked by Git for safety causes, so you have to manually switch it to the server. For extra data on this course of, seek the advice of step Three of the prerequisite tutorial on deploying Phoenix functions.

  • scp ~/myproject/config/prod.secret.exs sammy@your_server_ip:/house/sammy/app_config/prod.secret.exs

Then invoke the ecto.create Combine job to create the event database. Notice that you do not have to create the check database as Phoenix will try this for you if you run your checks.

You may see the next output displaying that Ecto has efficiently created the database:

Output

... The database for Myproject.Repo has been created

In case you do not see this output, be sure that your configuration particulars are right and that MySQL is working. Ecto would additionally refuse to create the database in case your software fails to compile because of any errors.

Now that you've got arrange the venture to hook up with a database, and even used Ecto to create a database within the improvement machine, you possibly can proceed to change the database on the server.

Step 4 — Organising the Manufacturing Database

With the ecto.create Combine job, you created an empty database in your improvement machine. Now, you may do the identical in your manufacturing server. Sadly, there are not any Combine duties or edeliver instructions to assist us obtain this, so you may manually log in to the server and create an empty database with SQL instructions utilizing the MySQL console.

Connect with the server through SSH.

Now entry the MySQL console utilizing the root person and the password you configured.

As soon as logged in, create the manufacturing database:

  • CREATE DATABASE myproject_prod;

You may see the next output, letting you recognize the database was created:

Output

Question OK, 1 row affected (0.00 sec)

Subsequent, create a person for the app, utilizing the username myproject and the password you specified within the earlier step:

  • CREATE USER 'myproject'@'localhost' IDENTIFIED BY 'password';

Then give the myproject person entry to the database you created:

  • GRANT ALL PRIVILEGES ON myproject_prod.* to 'myproject'@'localhost';

Lastly, apply the permission modifications:

Exit the MySQL console by typing exit. Terminate the SSH connection by typing exit once more.

Any longer, you may not often have to the touch the manufacturing database, as you may carry out virtually all operations like creating and altering tables out of your native machine.

With the manufacturing database now prepared, you possibly can redeploy your software to the server.

Step 5 — Deploying the Mission to the Server

On this step, you are going to exchange the working software that has no connection to a database together with your freshly configured software and its new Ecto repository. This step will let you be sure that the applying is configured accurately and that it nonetheless runs as anticipated.

Open combine.exs and increment the applying model. The model quantity makes it simpler to trace releases and roll again to earlier variations if crucial. Additionally it is utilized by edeliver to improve your software with out downtime.

Increment the model area to an acceptable worth.

~/myproject/combine.exs

  def venture do
    [
      app: :myproject,
      model: "0.0.3",
      elixir: "~> 1.4",
      elixirc_paths: elixirc_paths(Combine.env),
      compilers: [:phoenix, :gettext] ++ Combine.compilers,
      start_permanent: Combine.env == :prod,
      deps: deps()
    ]
  finish

With the intention to use edeliver to carry out database migrations, edeliver should be the final software to begin inside your venture. Discover the next block of code:

~/myproject/combine.exs

  def software do
    [
      mod: {Myproject.Software, []},
      extra_applications: [:logger, :runtime_tools]
    ]
  finish

Add edeliver to the top of the extra_applications listing:

~/myproject/combine.exs

  def software do
    [
      mod: {Myproject.Software, []},
      extra_applications: [:logger, :runtime_tools, :edeliver]
    ]
  finish

Save and shut combine.exs.

Launch the applying to make sure every thing works and there are not any compilation errors:

Go to http://localhost:4000/addresses to make sure the app nonetheless works. If it does not begin, otherwise you see compilation errors, evaluate the steps on this tutorial and resolve them earlier than transferring on.

If every thing is working as anticipated, press CTRL+C twice in your terminal to cease the server.

Then, commit modifications with Git. You need to do that each time you make modifications to your venture as a result of edeliver makes use of Git to push the code from the newest decide to the construct server for additional motion.

  • git add .
  • git commit -m "Configured application with database"

Lastly, use edeliver to replace the applying on the manufacturing server. The next command will construct and deploy the newest model of your venture earlier than upgrading the applying working on the manufacturing machine with out downtime.

  • combine edeliver improve manufacturing

You may see the next output:

Output

EDELIVER MYPROJECT WITH UPGRADE COMMAND -----> Upgrading to revision 2512398 from department grasp -----> Detecting launch variations on manufacturing hosts -----> Deploying upgrades to 1 on-line hosts -----> Checking whether or not put in model 0.0.2 is in launch retailer -----> Constructing the improve from model 0.0.2 -----> Authorizing hosts -----> Validating * model 0.0.2 is in native launch retailer -----> Guaranteeing hosts are prepared to just accept git pushes -----> Pushing new commits with git to: sammy@instance.com -----> Resetting distant hosts to 2512398838c2dcc43de3ccd869779dded4fd5b6b -----> Cleansing generated information from final construct -----> Testing 2512398838c2dcc43de3ccd869779dded4fd5b6b -----> Fetching / Updating dependencies -----> Compiling sources -----> Checking model of recent launch -----> Importing archive of launch 0.0.2 from native launch retailer -----> Extracting archive myproject_0.0.2.tar.gz -----> Eradicating previous releases which had been included in improve package deal -----> Producing launch -----> Eradicating constructed launch 0.0.2 from distant launch listing -----> Copying launch 0.0.Three to native launch retailer -----> Copying myproject.tar.gz to launch retailer -----> Upgrading manufacturing hosts to model 0.0.3 -----> Authorizing hosts -----> Importing archive of launch 0.0.Three from native launch retailer -----> Upgrading launch to 0.0.3 UPGRADE DONE!

Though the improve has accomplished efficiently, you will not be capable to run the database-related edeliver duties till you restart the applying.

Warning: The next command will trigger your software to go offline for a short time.

  • combine edeliver restart manufacturing

You may see this output:

Output

EDELIVER MYPROJECT WITH RESTART COMMAND -----> restarting manufacturing servers manufacturing node: person : sammy host : instance.com path : /house/sammy/app_release response: okay RESTART DONE!

edeliver tells us that it has efficiently restarted the manufacturing server.

To make sure that your software has been upgraded, run the next edeliver command to retrieve the model of the applying that's at present working on manufacturing.

  • combine edeliver model manufacturing

Output

EDELIVER MYPROJECT WITH VERSION COMMAND -----> getting launch variations from manufacturing servers manufacturing node: person : sammy host : instance.com path : /house/sammy/app_release response: 0.0.3 VERSION DONE!

The output tells us that the manufacturing server is working software model 0.0.3.

You may as well go to your software at https://instance.com to make sure that it is working. There should not be any observable modifications to the applying as we did not contact the applying code itself.

If the improve succeeds however fails to replace the applying, be sure that you have dedicated your code and have bumped up your software model. If the improve command fails, edeliver will output the bash code it was executing on the server when the error occurred and the error message itself. You should use these clues to repair your drawback.

Now that you've got added database assist to your app and deployed it to manufacturing, you are now prepared so as to add some options that make use of MySQL.

Step 6 — Creating the Handle Ebook

To display the right way to deploy database modifications, let's construct a easy handle guide into our software and deploy it to manufacturing.

Warning: This handle guide will probably be publicly accessible, and anybody would be capable to entry and edit it. Both take down the function after finishing this tutorial, or add an authentication system like Guardian to restrict entry.

As an alternative of writing the code for the handle guide from scratch, we'll use Phoenix turbines to create the handle guide. Phoenix turbines are utilities that generate code for a easy CRUD (Create, Learn, Replace, Delete) function. This offers a superb place to begin for a lot of software options that you could be wish to construct.

The handle guide may also require a desk within the database to retailer the entries. So as to add this desk to the database, you possibly can assemble and execute a SQL question, however we'll use Ecto's migrations function to change the database as an alternative. This method has a number of benefits. Firstly, it's database impartial; the instructions are the identical whether or not you might be utilizing a PostgreSQL, MySQL or another database. Subsequent, migration information present a handy strategy to monitor how your database schema has modified with time. Lastly, you may also roll again the newest migrations in your improvement machine if you'll want to.

Fortunately, you do not have to put in writing a migration file from scratch as Phoenix turbines will make one for you until in any other case specified.

To make use of the generator, specify the context, singular identify of the entity, plural identify of the entity and all the opposite fields with their respective varieties.

The context is a module that may comprise features for associated assets. For example, if you're planning to take care of a listing of customers who signed up in your web site and a log of periods when the customers register, it is smart to place customers and periods below a single context module named "Account".

Notice that by conference, Phoenix assumes the plural identify of the entity to be the identify of the database desk for that useful resource.

Let's create the handle guide with the generator. To maintain the handle guide easy, we'll embrace simply three fields for every file — identify, e-mail and ZIP code. We'll refer to every entry as an Handle, a number of entries as addresses and the context through which the handle guide ought to reside as AddressBook.

Run this command to generate the handle guide:

  • combine phx.gen.html AddressBook Handle addresses identify:string e-mail:string zip_code:integer

Output

* creating lib/myproject_web/controllers/address_controller.ex ... * creating priv/repo/migrations/20180318032834_create_address.exs Add the useful resource to your browser scope in net/router.ex: assets "/addresses", AddressController Bear in mind to replace your repository by working migrations: $ combine ecto.migrate

Phoenix tells us that it mechanically generated the template information, check information, the mannequin, the controller, and the migration file. It additionally instructs us so as to add the useful resource to the router file and replace the repository.

You can observe the directions you see within the output, however by doing so, you'll bundle software code improve and database migration in a single launch. This will trigger sure elements of the applying to fail in manufacturing from the time the applying is deployed to the manufacturing server to the time the manufacturing database is migrated. Throughout this interval, the applying code could also be referencing non-existent tables or columns within the database.

To stop downtime and errors, deploy the modifications in two steps:

  1. Add a database migration file with the required modifications to the database with out making modifications to the applying code. Create a launch, improve the manufacturing server and migrate the manufacturing database.
  2. Make modifications to the applying code, then create and deploy one other launch.

If we do not take this method, the code for the handle guide will attempt to reference the addresses desk that we've got but to create and our software will crash.

Earlier than we migrate the manufacturing database, let's take a look at the migration file. It is positioned at priv/repo/migrations/20180501040548_create_addresses.exs, though the filename can have a special datestamp primarily based on if you created it. Open the file in your editor:

  • nano priv/repo/migrations/*_create_addresses.exs

The migration file generated by Phoenix is an Elixir module with a single perform known as change. While you perform the migration later, this perform will probably be known as.

~/myproject/priv/repo/migrations/20180501040548_create_addresses.exs

defmodule Myproject.Repo.Migrations.CreateAddresses do
  use Ecto.Migration

  def change do
    create desk(:addresses) do
      add :identify, :string
      add :e-mail, :string
      add :zip_code, :integer

      timestamps()
    finish

  finish
finish

On this perform, the Phoenix generator has written the code to create the addresses desk together with the fields you equipped. Moreover, the generator has additionally included the timestamps() perform which provides two extra fields for you: inserted_at and updated_at. The values saved in these fields are up to date mechanically if you insert or replace information.

Shut the file with out making any modifications; the generated code is all you want.

To deploy simply the migration file with out together with the applying code, we'll make use of the truth that edeliver makes use of Git to switch our venture to the construct server. Particularly, we'll simply stage and commit the migration file whereas leaving the remainder of the generated information untracked.

However earlier than you are able to do that, increment the applying model in combine.exs. Edeliver makes use of the model quantity to organize for hot-upgrades, so you'll want to increment the model quantity for each replace.

Open up combine.exs.

Increment your software model to an acceptable worth.

~/myproject/combine.exs

  def venture do
    [
      app: :myproject,
      model: "0.0.4",
      ...

Save and shut the file.

Now, use Git to stage each the combine.exs file and the migration file.

  • git add combine.exs priv/repo/migrations/*_create_addresses.exs

Subsequent, commit the staged information.

  • git commit -m "Adding addresses table to the database"

With that, improve your manufacturing software with edeliver.

  • combine edeliver improve manufacturing

As soon as the improve completes, execute the next edeliver command emigrate the manufacturing database.

combine edeliver migrate manufacturing

The output reveals that the migration was efficiently run, and reveals the timestamp of the migration file:

Output

EDELIVER MYPROJECT WITH MIGRATE COMMAND -----> migrateing manufacturing servers manufacturing node: person : sammy host : instance.com path : /house/sammy/app_release response: [20180501040548] MIGRATE DONE!

The manufacturing database now has an empty desk named addresses.

The response area would present [] if no migrations had been run. If so, be sure that you have dedicated your code utilizing Git earlier than upgrading once more. Ought to the issue persist, restart the manufacturing software by typing combine edeliver restart manufacturing, and run the database migration job once more.

With the addresses desk in place, we will proceed to observe the directions issued by Phoenix after we generated the handle guide and create a brand new launch.

First, open the file lib/myproject_web/router.ex file:

nano lib/myproject_web/router.ex

Discover the next block of code:

~/myproject/lib/myproject_web/router.ex

  scope "/", MyprojectWeb do
    pipe_through :browser 

    get "/", PageController, :index
  finish

Insert the route for the addresses useful resource:

~/myproject/lib/myproject_web/router.ex

  scope "/", MyprojectWeb do
    pipe_through :browser 

    get "/", PageController, :index
    assets "/addresses", AddressController
  finish

Save and shut router.ex.

Subsequent, ask Ecto to make modifications to the native database.

combine ecto.migrate

The output reveals that the perform within the migration file was invoked, which efficiently created the desk addresses.

Output

... [info] == Operating Myproject.Repo.Migrations.CreateAddresses.change/Zero ahead [info] create desk addresses [info] == Migrated in 0.0s

Now begin up the native improvement server to check out your new function:

Level your browser at http://localhost:4000/addresses to see the brand new function in motion.

While you're glad that issues are working regionally, return to your terminal and press CTRL+C twice to terminate the server.

Now that issues are working, you possibly can deploy the modifications to manufacturing. Open combine.exs to replace the applying model.

Increment the model area to an acceptable worth.

~/myproject/combine.exs

  def venture do
    [
      app: :myproject,
      model: "0.0.5",
      elixir: "~> 1.4",
      elixirc_paths: elixirc_paths(Combine.env),
      compilers: [:phoenix, :gettext] ++ Combine.compilers,
      start_permanent: Combine.env == :prod,
      deps: deps()
    ]
  finish

Save and shut combine.exs.

Commit your modifications with Git. This time, stage all the information.

git add .
git commit -m "Added application code for address book"

Improve the manufacturing software with edeliver.

combine edeliver improve manufacturing

When the replace has accomplished, you possibly can entry the brand new function at https://instance.com/addresses.

With that, you have efficiently upgraded the manufacturing software and database.

Conclusion

On this article, you configured your Phoenix software to make use of a MySQL database and used edeliver and Ecto migrations to make modifications to the manufacturing database. With this methodology, you do not have to the touch the manufacturing database and any modifications you wish to make to the manufacturing database are finished by way of Ecto migration information. This makes it simpler to roll again modifications and monitor modifications to the database over time.

To study extra about Ecto migrations and the right way to carry out complicated database manipulations, check with the official Ecto migrations doc.

LEAVE A REPLY

Please enter your comment!
Please enter your name here