Raggaer
Import .sql file on a migration
I am currently trying to import a .sql file containing database tables on an Ecto migration, basically my Phoenix application adds some extra funcionality to the given database, so I need to import it:
defmodule XXX.Repo.Migrations.XXX do
use Ecto.Migration
def change do
execute File.read!("schema.sql")
end
end
However the migration fails, complaining its not valid SQL, the migration success if my .sql file only contains one table to create, when I add more the syntax fails for some reason…
The file is valid SQL and it works just fine doing “mysql -u root -p XX < file.sql” or even copy/paste into terminal. This is the file I am trying to import https://hastebin.com/zifosewayi.sql
Most Liked
dimitarvp
No clue why it’s failing – I think I remember it only accepts one SQL statement but I wouldn’t bet my life on it.
One thing you could try is splitting the SQL at the ; delimiter and then loop over the results and execute them one by one?
hauleth
It is limitation of prepared statements which are used internally in Ecto. This is security measure among other things.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









