Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
Advice on Pre-Populating PostgreSQL Table with Ecto

TL;DR When playing with Ecto, where (in the code) should I load data to pre-populate a small table after it is created?

I'm learning Elixir, Phoenix, and Ecto. I have a table in my schema to define a list of configurable options. I'd like to pre-populate this table with a minimum set of options when the table is created.

It seems to me that the _create_table.exs script is the place to do that since that's where the table is created. I was looking at an execute{} block but that seems klunky.

Is there a better place in the code to accomplish pre-populating a new table?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

In Phoenix, the common way to populate the DB is to use priv/repo/seeds.exs it generates with mix run task as:

mix run priv/repo/seeds.exs

But this approach does actually work pretty fine with any Ecto project. Simply create the file, put seeding code there, and update your mix.exs aliases section as

defp aliases do
  [
    "ecto.setup": [
      "ecto.create",
      "ecto.migrate",
      "run priv/repo/seeds.exs"
    ],
    ...
  ]

Now mix ecto.setup would create, migrate, and fill in the database.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda