zoeys.computer/priv/repo/migrations/20241027003540_change_gists_id.exs
2024-10-26 21:41:22 -04:00

26 lines
512 B
Elixir

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