2021-02-24 19:06:48 +01:00
|
|
|
defmodule Mobilizon.Storage.Repo.Migrations.AddMemberSinceToMembers do
|
|
|
|
use Ecto.Migration
|
|
|
|
|
|
|
|
def up do
|
|
|
|
alter table(:members) do
|
|
|
|
add(:member_since, :utc_datetime)
|
|
|
|
end
|
|
|
|
|
|
|
|
flush()
|
|
|
|
|
|
|
|
%Postgrex.Result{rows: rows} =
|
|
|
|
Ecto.Adapters.SQL.query!(
|
|
|
|
Mobilizon.Storage.Repo,
|
|
|
|
"SELECT id, role FROM members"
|
|
|
|
)
|
|
|
|
|
|
|
|
Enum.each(rows, fn [id, role] ->
|
|
|
|
if role in ["member", "moderator", "administrator", "creator"] do
|
|
|
|
Ecto.Adapters.SQL.query!(
|
|
|
|
Mobilizon.Storage.Repo,
|
2021-06-07 16:39:44 +02:00
|
|
|
"UPDATE members SET member_since = '#{DateTime.to_iso8601(DateTime.utc_now())}' WHERE id = '#{Ecto.UUID.cast!(id)}'"
|
2021-02-24 19:06:48 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
def down do
|
|
|
|
alter table(:members) do
|
|
|
|
remove(:member_since)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|