![]() app_dir( :my_app, "priv/repo/migrations") Insert_users() # My startup task 2 end def migrate do # Get the path to the migration files # Execute my startup tasks syncronously # Always run your migrations first before any database related things! ![]() The Codeĭefmodule MyApp.StartupTasks do def init do # We check that all necessary components have started Note: When in development/test environments, I suggest that you do include a call to run your startup tasks so that you can automate activities such as inserting demo data. However, as these GenServers are started up asyncronously, it is not guaranteed that Ecto will startup when your code calls the YourApplication.Repo module or any database related modules. When your Elixir app starts up, it starts up each GenServer marked in the dependency tree. Reason why you do not want to put any database reliant code it into the application.ex startup call However, we’re going to modify this method into a generalized “startup tasks” strategy that we can use to ensure that our database-related tasks are executed in the correct sequence. ![]() remote produce call) module to call an elixir script that then executes an Elixir module’s function for us. ![]() What Sophie describes in her blog post is basically to run a shell script that uses Erlang’s rpc (i.e. When using Distillery for your OTP releases, it exposes a post-startup hook that you can use to execute shell scripts. When I was trawling the web for an easy way to run database migrations for my side project, PillowSkin, a Phoenix application that I am building written in Elixir, I came across this post by Sophie DeBenedetto on her blog The Great Code Adventure, and gave it a try. Running Ecto Migrations and Other Startup Tasks With Distillery Hooks Last updated on March 15, 2019 ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |