Creating the Phoenix Application

To persist our data in PostgreSQL, we’ll need to execute some database migrations so that we have the necessary table in place to store our data. Do that by running the following:

 $ ​​mix​​ ​​ecto.gen.migration​​ ​​set_up_weather_data_table

That command should have generated a file in the priv/repo/migrations directory. Open up that file and set it up so that it looks like this:

 defmodule​ WeatherTracker.Repo.Migrations.SetUpWeatherDataTable ​do
 use​ Ecto.Migration
 
 def​ up ​do
  execute(​"​​CREATE EXTENSION IF NOT EXISTS timescaledb"​)
 
  create table(​:weather_conditions​, ​primary_key:​ false) ​do
  add ​:timestamp ...

Get Build a Weather Station with Elixir and Nerves now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.