Last active
November 27, 2019 16:33
-
-
Save moxley/d9fb07d8549b0f3974b6b4387f6e0742 to your computer and use it in GitHub Desktop.
Ecto flattened migrations, initial migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Repo.Migrations.InitialSchema do | |
use Ecto.Migration | |
def up do | |
db = Application.fetch_env!(:my_app, MyApp.Repo) | |
file_path = "priv/repo/initial_schema.sql" | |
{output, errno} = | |
System.cmd( | |
"psql", | |
[ | |
"-f", file_path, | |
"-U", db[:username], | |
"-h", db[:hostname], | |
db[:database] | |
], | |
env: [{"PGPASSWORD", db[:password]}] | |
) | |
if errno != 0 do | |
raise "psql error: #{output}" | |
end | |
end | |
def down do | |
raise "Rollback of initial schema not allowed" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment