defmodule Zoeyscomputer.Repo.Migrations.ChangeGistsId do alias Ecto.Repo alias Zoeyscomputer.IdGenerator use Ecto.Migration import Ecto.Query, only: [from: 2] def change do alter table(:gists) do add(:new_id, :string) end flush() execute """ UPDATE gists SET new_id = substring(md5(random()::text), 0, 8) """ alter table(:gists) do remove(:id) modify(:new_id, :string, primary_key: true) end rename(table(:gists), :new_id, to: :id) end end