Raggaer

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

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

hauleth

It is limitation of prepared statements which are used internally in Ecto. This is security measure among other things.

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement