2019-02-07 16:37:40 +01:00
|
|
|
defmodule Mobilizon.Repo.Migrations.MoveParticipantRoleToEnum do
|
|
|
|
use Ecto.Migration
|
2019-09-13 01:01:17 +02:00
|
|
|
alias Mobilizon.Events.ParticipantRole
|
2019-02-07 16:37:40 +01:00
|
|
|
|
|
|
|
def up do
|
2019-09-13 01:01:17 +02:00
|
|
|
ParticipantRole.create_type()
|
2019-02-07 16:37:40 +01:00
|
|
|
|
|
|
|
alter table(:participants) do
|
2019-09-13 01:01:17 +02:00
|
|
|
add(:role_tmp, ParticipantRole.type(), default: "participant")
|
2019-02-07 16:37:40 +01:00
|
|
|
end
|
|
|
|
|
2019-02-22 14:18:52 +01:00
|
|
|
execute("UPDATE participants set role_tmp = 'not_approved' where role = 0")
|
|
|
|
execute("UPDATE participants set role_tmp = 'participant' where role = 1")
|
|
|
|
execute("UPDATE participants set role_tmp = 'moderator' where role = 2")
|
|
|
|
execute("UPDATE participants set role_tmp = 'administrator' where role = 3")
|
|
|
|
execute("UPDATE participants set role_tmp = 'creator' where role = 4")
|
2019-02-07 16:37:40 +01:00
|
|
|
|
|
|
|
alter table(:participants) do
|
|
|
|
remove(:role)
|
|
|
|
end
|
2019-02-22 14:18:52 +01:00
|
|
|
|
|
|
|
rename(table(:participants), :role_tmp, to: :role)
|
2019-02-07 16:37:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def down do
|
|
|
|
alter table(:participants) do
|
|
|
|
add(:role_tmp, :integer, default: 1)
|
|
|
|
end
|
|
|
|
|
2019-02-22 14:18:52 +01:00
|
|
|
execute("UPDATE participants set role_tmp = 0 where role = 'not_approved'")
|
|
|
|
execute("UPDATE participants set role_tmp = 1 where role = 'participant'")
|
|
|
|
execute("UPDATE participants set role_tmp = 2 where role = 'moderator'")
|
|
|
|
execute("UPDATE participants set role_tmp = 3 where role = 'administrator'")
|
|
|
|
execute("UPDATE participants set role_tmp = 4 where role = 'creator'")
|
2019-02-07 16:37:40 +01:00
|
|
|
|
|
|
|
alter table(:participants) do
|
|
|
|
remove(:role)
|
|
|
|
end
|
2019-02-22 14:18:52 +01:00
|
|
|
|
2019-09-13 01:01:17 +02:00
|
|
|
ParticipantRole.drop_type()
|
2019-02-07 16:37:40 +01:00
|
|
|
|
2019-02-22 14:18:52 +01:00
|
|
|
rename(table(:participants), :role_tmp, to: :role)
|
2019-02-07 16:37:40 +01:00
|
|
|
end
|
|
|
|
end
|