fireproofsocks

fireproofsocks

Load structure.sql as a migration?

I’m working on a fairly mature database and writing a new Elixir app to sit on top of it. The problem is getting the migrations started. The structure.sql is a great starting point, but we’d like to have it be part of the migrations.

I tried to do something similar once before on a much smaller database and I remember eventually giving up and re-creating the database with regular Ecto migrations. But with this big/mature database, re-creating everything would be really time intensive. IIRC, one of the problems is that each Postgres “schema” (something analogous to a “folder” or partition) has to be created in its own transaction, so if we have a dozen separate schemas, we would need at least that many migrations (because each migration happens in its own transaction). It’s not the end of the world to use mix ecto.load (e.g. done as part of an alias), but a standard migration would be preferred.

Any thoughts on this? Is this maybe more difficult than it’s worth? Thanks for any pointers!

Most Liked Responses

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I think the big issue is that structure.sql ALSO lists all of the migrations that you’ve done, so there’s a recursive dependency here that is sort of weird if you do it inside of a migration.

You could do a sort of custom my_structure.sql that has just a big psql_dump of things and call that from your migration, but the output of mix ecto.dump is really designed to be used with mix ecto.load

Where Next?

Popular in Questions Top

skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
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
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New

We're in Beta

About us Mission Statement