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!
Trending in Questions
Other Trending 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
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 5 of 5 Posts
benwilson512
I think the big issue is that
structure.sqlALSO 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.sqlthat has just a bigpsql_dumpof things and call that from your migration, but the output ofmix ecto.dumpis really designed to be used withmix ecto.loadfireproofsocks
In this case, the database had no migrations. I just have a structure dump, and it does properly represent the structure of the database. But I hear what you’re saying: the structure.sql is best handled by
ecto.load.Hermanverschooten
ecto.loadunder the hood just does apsqlto load the structure.sql into the database.So if you have access to it on the server, you could call it yourself from a migration.
sbuttgereit
Just a note… PostgreSQL allows you to create schema objects within a transaction without problem:
New databases are not allowed to be created in an ongoing transaction:
benwilson512
FYI you can set
@disable_ddl_transaction truein your ecto migration file and then this is no longer in a transaction. As @sbuttgereit notes I don’t think there is actually an issue here though.