Running Phonix with SQLite for weather-data directly on the Pi (with nerves)

I’d recommend trying Ecto SQLite3 instead of SQLite2: GitHub - elixir-sqlite/ecto_sqlite3: An Ecto SQLite3 adapter. · GitHub

The readme of the project should help you get started with it and there’s not really any nerves-specific setup that you’ll need I think.

To create the database I usually create a release module like:

defmodule Dash.Release do
  @app :dash

  def migrate do
    load_app()

    for repo <- repos() do
      {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
    end
  end

  def rollback(repo, version) do
    load_app()
    {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
  end

  defp repos do
    Application.fetch_env!(@app, :ecto_repos)
  end

  defp load_app do
    Application.load(@app)
  end
end

Then connect to your Pi via ssh and run Dash.Release.migrate() and that should create the sqlite file on the Pi.

Good luck!

3 Likes