Skip to content

Instantly share code, notes, and snippets.

@moxley
Last active November 27, 2019 16:33
Show Gist options
  • Save moxley/d9fb07d8549b0f3974b6b4387f6e0742 to your computer and use it in GitHub Desktop.
Save moxley/d9fb07d8549b0f3974b6b4387f6e0742 to your computer and use it in GitHub Desktop.
Ecto flattened migrations, initial migration
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