← All series

Series contents

Log in to track your progress

  1. 1. A worker to log stats from a YouTube’s API Episode
  2. 2. Querying Alexa Site API and parsing XML Episode
  3. 3. Adding Ecto and a Postgres database to StatWatch Episode
  4. 4. Putting an Elixir OTP app in our Elixir OTP app Episode
  5. 5. Launching StatWatch.me (side project) Episode
  6. 6. Planning a Phoenix web app for StatWatch Episode
  7. 7. From backend OTP app to Phoenix app Episode
  8. 8. Adding sessions and logins to StatWatch Episode
  9. 9. Password hashing and Ecto associations for StatWatch Episode
  10. 10. Permalinks and an admin auth plug for StatWatch Episode
  11. 11. Creating Ecto associations between profiles and stats Episode
  12. 12. Zero Dependency Pagination in Phoenix (Part 1) Episode
  13. 13. Zero Dependency Pagination in Phoenix (Part 2) Episode

Adding Ecto and a Postgres database to StatWatch

Our StatWatch module has been serving Alchemist.Camp well, but let's add a database and work towards eliminating our reliance on .csv files.

This is our first video to cover Ecto so we went into some detail about getting it set up, creating a user for our db in psql, running

mix ecto.gen.repo
mix ecto.create
mix ecto.gen.migration (YOUR_MIGRATION)
mix ecto.migrate

And then we set up an Ecto Schema for our table, fired up iex and manually added and manipulated some data. Kernel.struct, Repo.insert, Repo.all, Repo.get, Repo.get_by, Repo.delete, Ecto.Changeset.change and Repo.update were used.

Finally we dealt with a common mix error that comes up when using Ecto in an OTP sub-application that's not an umbrella project.

Today's challenge

Read over the docs on Ecto Associations

Then figure out how we could create an association between the profiles we're collecting stats for and the stats we've collected.

Open standalone page ↗

2 Comments

Thanks, @minimizer!

- alchemist · 4 years ago