Introduce the group activity section
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
20
priv/repo/migrations/20210215092515_add_activity_table.exs
Normal file
20
priv/repo/migrations/20210215092515_add_activity_table.exs
Normal file
@@ -0,0 +1,20 @@
|
||||
defmodule Mobilizon.Storage.Repo.Migrations.AddActivityTable do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:activities) do
|
||||
add(:priority, :integer, null: false)
|
||||
add(:type, :string, null: false)
|
||||
add(:author_id, references(:actors, on_delete: :delete_all), null: false)
|
||||
add(:group_id, references(:actors, on_delete: :delete_all), null: false)
|
||||
add(:subject, :string, null: false)
|
||||
add(:subject_params, :map, null: false)
|
||||
add(:message, :string)
|
||||
add(:message_params, :map)
|
||||
add(:object_type, :string)
|
||||
add(:object_id, :string)
|
||||
|
||||
timestamps(updated_at: false, type: :utc_datetime)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
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,
|
||||
"UPDATE members SET member_since = '#{DateTime.to_iso8601(DateTime.utc_now())}' WHERE id = '#{
|
||||
Ecto.UUID.cast!(id)
|
||||
}'"
|
||||
)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
def down do
|
||||
alter table(:members) do
|
||||
remove(:member_since)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user