mmmrrr
I need to include multiple legacy migrations (written in plain SQL) in an ecto migration.
The current legacy application relies heavily on custom ENUM types in postgresql.
When I try to run the existing migrations (concatenated as a string) via execute my_combined_sql I will get the error cannot insert multiple commands into a prepared statement.
The minimal example of a failing SQL file is:
CREATE TYPE UState AS ENUM ("state1", "state2");
CREATE TABLE IF NOT EXISTS Users
(userEmail VARCHAR(320) NOT NULL PRIMARY KEY,
state UState NOT NULL);
Is there a way to do this with ecto, or do I need another process to apply the legacy migrations to the database?
Trending in Questions
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
Keynote: What Comes Next - Chris McCord | ElixirConf US 2026
https://www.youtube.com/watch?v=wR9O_MiwZ-8
Comments welcome! View the <s...
New
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #elixirconf-us
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kip
By default Ecto uses prepared statements (this is like a precompiled form of the statement which is the cached so that reuse is materially faster).
There is an option
prepare: :unnamedwhich I think goes on the Repo configuration (its a Postgrex adapter option) but I can’t recall and I’m in China this week so googling isn’t an option.Sorry its an incomplete answer but hopefully thats enough to get you started…
kip
On reflection, I suspect this won’t go either because the statements are still prepared and, as the message says, you can’t have more than one.
Indeed I recall having to split SQL statements at the
;in one use case and passing them one-by-one.This is primarily a
Postegrexissue, notEcto.mmmrrr
Hey @kip
Thanks for the input and taking the time.
In principle this shouldn’t be a problem to execute the statements one by one. This specific migration does not need to execute fast.
Just to clearify: I could split my SQL statements into a list and then call
execute SUBQUERY1,execute SUBQUERY2, etc. in the sameup/downstatement, right?This sounds a lot like “macro” to me
kip
Now I’ve paid a little more attention… I believe the issue is that you can’t create the
Enumin the same transaction as using it.Typically what I do in this case is actually prepare two migrations: one to create the
Enumand the other to create the table.However should be perfectly ok to:
mmmrrr
Awesome!
Thanks for the feedback. I will try that
mmmrrr
Great! That worked. It needed a little cleanup in the sql files in order to work, but it does now.
For anyone interested: If you have a List/Array of sql statements, you can use a simple macro like:
in your up migration:
NobbZ
Why a macro at all? If you had written it as a function, then there would be no noeed to quote and unquote…
Or even simpler, have it inline:
mmmrrr
Hm. Good point.
I somehow assumed the execute statement would not allow to be called at runtime… now that I think of it, it’s probably stupid
Thanks for the input