mirror of
https://github.com/ash-project/ash_hq.git
synced 2024-09-20 05:13:23 +12:00
44 lines
888 B
Elixir
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
|