ash_hq/priv/repo/migrations/20221103061339_migrate_resources31.exs

44 lines
888 B
Elixir

defmodule AshHq.Repo.Migrations.MigrateResources31 do
@moduledoc """
Updates resources based on their most recent snapshots.
This file was autogenerated with `mix ash_postgres.generate_migrations`
"""
use Ecto.Migration
import Ecto.Query
def up do
alter table(:guides) do
add(:sanitized_name, :text, null: true)
end
flush()
query =
from row in "guides",
update: [
set: [
sanitized_name:
fragment(
"(string_to_array(?, '/'))[array_upper(string_to_array(?, '/'), 1)]",
row.route,
row.route
)
]
]
AshHq.Repo.update_all(query, [])
alter table(:guides) do
modify(:sanitized_name, :text, null: false)
end
end
def down do
alter table(:guides) do
remove(:sanitized_name)
end
end
end