Phoenix执行SQL

如何在Phoenix应用中执行 SQL呢?

首先生成一个migration

iex> mix ecto.gen.migration my_database_structure_migration

然后在migration中priv/repo/migrations/2017xxxxxxxxxxx_my_database_structure_migration.exs修改:

defmodule My.Database.Structure.Migration do
  use Ecto.Migration

  def up do
    execute File.read!("/path/to/sql_dump.sql")
  end

  def down do
    
  end
end

大功告成!

https://elixirforum.com/t/how-to-execute-sql-file-script-in-phoenix/7779/2

你可能感兴趣的:(Phoenix执行SQL)