Merge branch 'ci-allow-format-failure' into 'master'

Fix mix format and format migrations too

See merge request framasoft/mobilizon!75
This commit is contained in:
Thomas Citharel 2019-02-22 15:00:36 +01:00
commit d73f738b1b
52 changed files with 370 additions and 324 deletions

View File

@ -1,3 +1,3 @@
[ [
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"] inputs: ["{mix,.formatter}.exs", "{config,lib,test,priv}/**/*.{ex,exs}"]
] ]

View File

@ -41,8 +41,9 @@ elixir_check:
before_script: before_script:
- mix deps.get - mix deps.get
script: script:
- mix format --check-formatted --dry-run
- mix credo list - mix credo list
- mix format --check-formatted --dry-run
- mix hex.outdated
cache: cache:
paths: paths:
- deps - deps

View File

@ -1,4 +1,7 @@
defmodule MobilizonWeb.API.Search do defmodule MobilizonWeb.API.Search do
@moduledoc """
API for Search
"""
alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub
alias Mobilizon.Actors alias Mobilizon.Actors
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
@ -80,7 +83,7 @@ defmodule MobilizonWeb.API.Search do
actor actor
else else
{:error, _err} -> {:error, _err} ->
Logger.debug("Unable to find or make actor '#{search}'") Logger.debug(fn -> "Unable to find or make actor '#{search}'" end)
nil nil
end end
end end
@ -92,7 +95,7 @@ defmodule MobilizonWeb.API.Search do
object object
else else
{:error, _err} -> {:error, _err} ->
Logger.debug("Unable to find or make object from URL '#{search}'") Logger.debug(fn -> "Unable to find or make object from URL '#{search}'" end)
nil nil
end end
end end

View File

@ -3,20 +3,19 @@ defmodule Mobilizon.Repo.Migrations.CreateAccounts do
def change do def change do
create table(:accounts) do create table(:accounts) do
add :username, :string, null: false add(:username, :string, null: false)
add :domain, :string, null: true add(:domain, :string, null: true)
add :display_name, :string, null: true add(:display_name, :string, null: true)
add :description, :text, null: true add(:description, :text, null: true)
add :private_key, :text, null: true add(:private_key, :text, null: true)
add :public_key, :text, null: false add(:public_key, :text, null: false)
add :suspended, :boolean, default: false, null: false add(:suspended, :boolean, default: false, null: false)
add :uri, :string, null: false add(:uri, :string, null: false)
add :url, :string, null: false add(:url, :string, null: false)
timestamps() timestamps()
end end
create unique_index(:accounts, [:username, :domain]) create(unique_index(:accounts, [:username, :domain]))
end end
end end

View File

@ -3,14 +3,14 @@ defmodule Mobilizon.Repo.Migrations.CreateUsers do
def change do def change do
create table(:users) do create table(:users) do
add :email, :string, null: false add(:email, :string, null: false)
add :role, :integer, default: 0, null: false add(:role, :integer, default: 0, null: false)
add :password_hash, :string, null: false add(:password_hash, :string, null: false)
add :account_id, references(:accounts, on_delete: :delete_all), null: false add(:account_id, references(:accounts, on_delete: :delete_all), null: false)
timestamps() timestamps()
end end
create unique_index(:users, [:email]) create(unique_index(:users, [:email]))
end end
end end

View File

@ -3,14 +3,13 @@ defmodule Mobilizon.Repo.Migrations.CreateCategories do
def change do def change do
create table(:categories) do create table(:categories) do
add :title, :string add(:title, :string)
add :description, :string add(:description, :string)
add :picture, :string add(:picture, :string)
timestamps() timestamps()
end end
create unique_index(:categories, [:title]) create(unique_index(:categories, [:title]))
end end
end end

View File

@ -3,17 +3,16 @@ defmodule Mobilizon.Repo.Migrations.CreateAddresses do
def change do def change do
create table(:addresses) do create table(:addresses) do
add :description, :string add(:description, :string)
add :floor, :string add(:floor, :string)
add :addressCountry, :string add(:addressCountry, :string)
add :addressLocality, :string add(:addressLocality, :string)
add :addressRegion, :string add(:addressRegion, :string)
add :postalCode, :string add(:postalCode, :string)
add :streetAddress, :string add(:streetAddress, :string)
add :geom, :geometry add(:geom, :geometry)
timestamps() timestamps()
end end
end end
end end

View File

@ -3,18 +3,17 @@ defmodule Mobilizon.Repo.Migrations.CreateGroups do
def change do def change do
create table(:groups) do create table(:groups) do
add :title, :string, null: false add(:title, :string, null: false)
add :slug, :string, null: false add(:slug, :string, null: false)
add :description, :string add(:description, :string)
add :suspended, :boolean, default: false, null: false add(:suspended, :boolean, default: false, null: false)
add :url, :string add(:url, :string)
add :uri, :string add(:uri, :string)
add :address_id, references(:addresses, on_delete: :delete_all) add(:address_id, references(:addresses, on_delete: :delete_all))
timestamps() timestamps()
end end
create unique_index(:groups, [:slug]) create(unique_index(:groups, [:slug]))
end end
end end

View File

@ -3,28 +3,27 @@ defmodule Mobilizon.Repo.Migrations.CreateEvents do
def change do def change do
create table(:events) do create table(:events) do
add :title, :string, null: false add(:title, :string, null: false)
add :slug, :string, null: false add(:slug, :string, null: false)
add :description, :string, null: true add(:description, :string, null: true)
add :begins_on, :datetimetz add(:begins_on, :datetimetz)
add :ends_on, :datetimetz add(:ends_on, :datetimetz)
add :state, :integer, null: false add(:state, :integer, null: false)
add :public, :boolean, null: false add(:public, :boolean, null: false)
add :status, :integer, null: false add(:status, :integer, null: false)
add :large_image, :string add(:large_image, :string)
add :thumbnail, :string add(:thumbnail, :string)
add :publish_at, :datetimetz add(:publish_at, :datetimetz)
add :organizer_account_id, references(:accounts, on_delete: :nothing) add(:organizer_account_id, references(:accounts, on_delete: :nothing))
add :organizer_group_id, references(:groups, on_delete: :nothing) add(:organizer_group_id, references(:groups, on_delete: :nothing))
add :category_id, references(:categories, on_delete: :nothing), null: false add(:category_id, references(:categories, on_delete: :nothing), null: false)
add :address_id, references(:addresses, on_delete: :delete_all) add(:address_id, references(:addresses, on_delete: :delete_all))
timestamps() timestamps()
end end
create index(:events, [:organizer_account_id]) create(index(:events, [:organizer_account_id]))
create index(:events, [:organizer_group_id]) create(index(:events, [:organizer_group_id]))
create unique_index(:events, [:slug]) create(unique_index(:events, [:slug]))
end end
end end

View File

@ -3,13 +3,12 @@ defmodule Mobilizon.Repo.Migrations.CreateTags do
def change do def change do
create table(:tags) do create table(:tags) do
add :title, :string add(:title, :string)
add :slug, :string, null: false add(:slug, :string, null: false)
timestamps() timestamps()
end end
create unique_index(:tags, [:slug]) create(unique_index(:tags, [:slug]))
end end
end end

View File

@ -3,8 +3,8 @@ defmodule Mobilizon.Repo.Migrations.CreateEventsTags do
def change do def change do
create table(:events_tags, primary_key: false) do create table(:events_tags, primary_key: false) do
add :event_id, references(:events) add(:event_id, references(:events))
add :tag_id, references(:tags) add(:tag_id, references(:tags))
end end
end end
end end

View File

@ -3,15 +3,14 @@ defmodule Mobilizon.Repo.Migrations.CreateParticipants do
def change do def change do
create table(:participants, primary_key: false) do create table(:participants, primary_key: false) do
add :role, :integer add(:role, :integer)
add :event_id, references(:events, on_delete: :nothing), primary_key: true add(:event_id, references(:events, on_delete: :nothing), primary_key: true)
add :account_id, references(:accounts, on_delete: :nothing), primary_key: true add(:account_id, references(:accounts, on_delete: :nothing), primary_key: true)
timestamps() timestamps()
end end
create index(:participants, [:event_id]) create(index(:participants, [:event_id]))
create index(:participants, [:account_id]) create(index(:participants, [:account_id]))
end end
end end

View File

@ -3,15 +3,14 @@ defmodule Mobilizon.Repo.Migrations.CreateEventRequests do
def change do def change do
create table(:event_requests) do create table(:event_requests) do
add :state, :integer add(:state, :integer)
add :event_id, references(:events, on_delete: :nothing) add(:event_id, references(:events, on_delete: :nothing))
add :account_id, references(:accounts, on_delete: :nothing) add(:account_id, references(:accounts, on_delete: :nothing))
timestamps() timestamps()
end end
create index(:event_requests, [:event_id]) create(index(:event_requests, [:event_id]))
create index(:event_requests, [:account_id]) create(index(:event_requests, [:account_id]))
end end
end end

View File

@ -3,15 +3,14 @@ defmodule Mobilizon.Repo.Migrations.CreateMembers do
def change do def change do
create table(:members, primary_key: false) do create table(:members, primary_key: false) do
add :role, :integer add(:role, :integer)
add :group_id, references(:groups, on_delete: :nothing) add(:group_id, references(:groups, on_delete: :nothing))
add :account_id, references(:accounts, on_delete: :nothing) add(:account_id, references(:accounts, on_delete: :nothing))
timestamps() timestamps()
end end
create index(:members, [:group_id]) create(index(:members, [:group_id]))
create index(:members, [:account_id]) create(index(:members, [:account_id]))
end end
end end

View File

@ -3,15 +3,14 @@ defmodule Mobilizon.Repo.Migrations.CreateGroupRequests do
def change do def change do
create table(:group_requests) do create table(:group_requests) do
add :state, :integer add(:state, :integer)
add :group_id, references(:groups, on_delete: :nothing) add(:group_id, references(:groups, on_delete: :nothing))
add :account_id, references(:accounts, on_delete: :nothing) add(:account_id, references(:accounts, on_delete: :nothing))
timestamps() timestamps()
end end
create index(:group_requests, [:group_id]) create(index(:group_requests, [:group_id]))
create index(:group_requests, [:account_id]) create(index(:group_requests, [:account_id]))
end end
end end

View File

@ -3,14 +3,13 @@ defmodule Mobilizon.Repo.Migrations.CreateTracks do
def change do def change do
create table(:tracks) do create table(:tracks) do
add :name, :string add(:name, :string)
add :description, :text add(:description, :text)
add :color, :string add(:color, :string)
add :event_id, references(:events, on_delete: :delete_all), null: false add(:event_id, references(:events, on_delete: :delete_all), null: false)
timestamps() timestamps()
end end
end end
end end

View File

@ -3,22 +3,21 @@ defmodule Mobilizon.Repo.Migrations.CreateSessions do
def change do def change do
create table(:sessions) do create table(:sessions) do
add :title, :string add(:title, :string)
add :subtitle, :string add(:subtitle, :string)
add :short_abstract, :text add(:short_abstract, :text)
add :long_abstract, :text add(:long_abstract, :text)
add :language, :string add(:language, :string)
add :slides_url, :string add(:slides_url, :string)
add :videos_urls, :string add(:videos_urls, :string)
add :audios_urls, :string add(:audios_urls, :string)
add :begins_on, :datetimetz add(:begins_on, :datetimetz)
add :ends_on, :datetimetz add(:ends_on, :datetimetz)
add :event_id, references(:events, on_delete: :delete_all), null: false add(:event_id, references(:events, on_delete: :delete_all), null: false)
add :track_id, references(:tracks, on_delete: :delete_all) add(:track_id, references(:tracks, on_delete: :delete_all))
add :speaker_id, references(:accounts, on_delete: :delete_all) add(:speaker_id, references(:accounts, on_delete: :delete_all))
timestamps() timestamps()
end end
end end
end end

View File

@ -3,21 +3,21 @@ defmodule Mobilizon.Repo.Migrations.RemoveUri do
def up do def up do
alter table("accounts") do alter table("accounts") do
remove :uri remove(:uri)
end end
alter table("groups") do alter table("groups") do
remove :uri remove(:uri)
end end
end end
def down do def down do
alter table("accounts") do alter table("accounts") do
add :uri, :string, null: false, default: "https://" add(:uri, :string, null: false, default: "https://")
end end
alter table("groups") do alter table("groups") do
add :uri, :string, null: false, default: "https://" add(:uri, :string, null: false, default: "https://")
end end
end end
end end

View File

@ -3,13 +3,13 @@ defmodule Mobilizon.Repo.Migrations.AddUrlFieldToEvents do
def up do def up do
alter table("events") do alter table("events") do
add :url, :string, null: false, default: "https://" add(:url, :string, null: false, default: "https://")
end end
end end
def down do def down do
alter table("events") do alter table("events") do
remove :url remove(:url)
end end
end end
end end

View File

@ -3,13 +3,13 @@ defmodule Mobilizon.Repo.Migrations.CreateComments do
def change do def change do
create table(:comments) do create table(:comments) do
add :url, :string add(:url, :string)
add :text, :text add(:text, :text)
add :account_id, references(:accounts, on_delete: :nothing), null: false add(:account_id, references(:accounts, on_delete: :nothing), null: false)
add :event_id, references(:events, on_delete: :nothing) add(:event_id, references(:events, on_delete: :nothing))
add :in_reply_to_comment_id, references(:categories, on_delete: :nothing) add(:in_reply_to_comment_id, references(:categories, on_delete: :nothing))
add :origin_comment_id, references(:addresses, on_delete: :delete_all) add(:origin_comment_id, references(:addresses, on_delete: :delete_all))
timestamps() timestamps()
end end

View File

@ -3,15 +3,15 @@ defmodule Mobilizon.Repo.Migrations.AlterEventTimestampsToDateTimeWithTimeZone d
def up do def up do
alter table("events") do alter table("events") do
modify :inserted_at, :utc_datetime modify(:inserted_at, :utc_datetime)
modify :updated_at, :utc_datetime modify(:updated_at, :utc_datetime)
end end
end end
def down do def down do
alter table("events") do alter table("events") do
modify :inserted_at, :timestamptz modify(:inserted_at, :timestamptz)
modify :updated_at, :timestamptz modify(:updated_at, :timestamptz)
end end
end end
end end

View File

@ -3,21 +3,21 @@ defmodule Mobilizon.Repo.Migrations.AddLocalAttributeToEventsAndComments do
def up do def up do
alter table("events") do alter table("events") do
add :local, :boolean, null: false, default: true add(:local, :boolean, null: false, default: true)
end end
alter table("comments") do alter table("comments") do
add :local, :boolean, null: false, default: true add(:local, :boolean, null: false, default: true)
end end
end end
def down do def down do
alter table("events") do alter table("events") do
remove :local remove(:local)
end end
alter table("comments") do alter table("comments") do
remove :local remove(:local)
end end
end end
end end

View File

@ -2,101 +2,106 @@ defmodule Mobilizon.Repo.Migrations.MoveFromAccountToActor do
use Ecto.Migration use Ecto.Migration
def up do def up do
drop table("event_requests") drop(table("event_requests"))
drop table("group_requests") drop(table("group_requests"))
alter table("events") do alter table("events") do
remove :organizer_group_id remove(:organizer_group_id)
end end
rename table("members"), :account_id, to: :actor_id rename(table("members"), :account_id, to: :actor_id)
alter table("members") do alter table("members") do
remove :group_id remove(:group_id)
add :parent_id, references(:accounts, on_delete: :nothing) add(:parent_id, references(:accounts, on_delete: :nothing))
end end
drop table("groups") drop(table("groups"))
rename table("accounts"), to: table("actors") rename(table("accounts"), to: table("actors"))
Mobilizon.Actors.ActorTypeEnum.create_type Mobilizon.Actors.ActorTypeEnum.create_type()
rename table("actors"), :username, to: :name rename(table("actors"), :username, to: :name)
rename table("actors"), :description, to: :summary rename(table("actors"), :description, to: :summary)
rename table("actors"), :display_name, to: :preferred_username rename(table("actors"), :display_name, to: :preferred_username)
alter table("actors") do alter table("actors") do
add :inbox_url, :string add(:inbox_url, :string)
add :outbox_url, :string add(:outbox_url, :string)
add :following_url, :string, null: true add(:following_url, :string, null: true)
add :followers_url, :string, null: true add(:followers_url, :string, null: true)
add :shared_inbox_url, :string, null: false, default: "" add(:shared_inbox_url, :string, null: false, default: "")
add :type, :actor_type add(:type, :actor_type)
add :manually_approves_followers, :boolean, default: false add(:manually_approves_followers, :boolean, default: false)
modify :name, :string, null: true modify(:name, :string, null: true)
modify :preferred_username, :string, null: false modify(:preferred_username, :string, null: false)
end end
create unique_index(:actors, [:preferred_username, :domain]) create(unique_index(:actors, [:preferred_username, :domain]))
rename table("events"), :organizer_account_id, to: :organizer_actor_id rename(table("events"), :organizer_account_id, to: :organizer_actor_id)
rename table("participants"), :account_id, to: :actor_id rename(table("participants"), :account_id, to: :actor_id)
create table("followers") do create table("followers") do
add :approved, :boolean, default: false add(:approved, :boolean, default: false)
add :score, :integer, default: 1000 add(:score, :integer, default: 1000)
add :actor_id, references(:actors, on_delete: :nothing) add(:actor_id, references(:actors, on_delete: :nothing))
add :target_actor_id, references(:actors, on_delete: :nothing) add(:target_actor_id, references(:actors, on_delete: :nothing))
end end
rename table("comments"), :account_id, to: :actor_id rename(table("comments"), :account_id, to: :actor_id)
rename table("users"), :account_id, to: :actor_id rename(table("users"), :account_id, to: :actor_id)
end end
def down do def down do
create table("event_requests") create(table("event_requests"))
create table("group_requests") create(table("group_requests"))
alter table("events") do alter table("events") do
add :organizer_group_id, :integer add(:organizer_group_id, :integer)
end end
rename table("members"), :actor_id, to: :account_id rename(table("members"), :actor_id, to: :account_id)
alter table("members") do alter table("members") do
add :group_id, :integer add(:group_id, :integer)
remove :parent_id remove(:parent_id)
end end
create table("groups") create(table("groups"))
rename table("actors"), to: table("accounts") rename(table("actors"), to: table("accounts"))
rename table("accounts"), :name, to: :username rename(table("accounts"), :name, to: :username)
rename table("accounts"), :summary, to: :description rename(table("accounts"), :summary, to: :description)
rename table("accounts"), :preferred_username, to: :display_name rename(table("accounts"), :preferred_username, to: :display_name)
alter table("accounts") do alter table("accounts") do
remove :inbox_url remove(:inbox_url)
remove :outbox_url remove(:outbox_url)
remove :following_url remove(:following_url)
remove :followers_url remove(:followers_url)
remove :shared_inbox_url remove(:shared_inbox_url)
remove :type remove(:type)
remove :manually_approves_followers remove(:manually_approves_followers)
modify :username, :string, null: false modify(:username, :string, null: false)
modify :display_name, :string, null: true modify(:display_name, :string, null: true)
end end
Mobilizon.Actors.ActorTypeEnum.drop_type() Mobilizon.Actors.ActorTypeEnum.drop_type()
rename table("events"), :organizer_actor_id, to: :organizer_account_id rename(table("events"), :organizer_actor_id, to: :organizer_account_id)
rename table("participants"), :actor_id, to: :account_id rename(table("participants"), :actor_id, to: :account_id)
rename table("comments"), :actor_id, to: :account_id rename(table("comments"), :actor_id, to: :account_id)
rename table("users"), :actor_id, to: :account_id rename(table("users"), :actor_id, to: :account_id)
drop index("accounts", [:preferred_username, :domain], name: :actors_preferred_username_domain_index) drop(
index("accounts", [:preferred_username, :domain],
name: :actors_preferred_username_domain_index
)
)
drop table("followers") drop(table("followers"))
end end
end end

View File

@ -3,16 +3,16 @@ defmodule Mobilizon.Repo.Migrations.AddBotsTable do
def up do def up do
create table(:bots) do create table(:bots) do
add :source, :string, null: false add(:source, :string, null: false)
add :type, :string, default: "ics" add(:type, :string, default: "ics")
add :actor_id, references(:actors, on_delete: :delete_all), null: false add(:actor_id, references(:actors, on_delete: :delete_all), null: false)
add :user_id, references(:users, on_delete: :delete_all), null: false add(:user_id, references(:users, on_delete: :delete_all), null: false)
timestamps() timestamps()
end end
end end
def down do def down do
drop table(:bots) drop(table(:bots))
end end
end end

View File

@ -3,15 +3,15 @@ defmodule Mobilizon.Repo.Migrations.AddAvatarAndBannerToActor do
def up do def up do
alter table(:actors) do alter table(:actors) do
add :avatar_url, :string add(:avatar_url, :string)
add :banner_url, :string add(:banner_url, :string)
end end
end end
def down do def down do
alter table(:actors) do alter table(:actors) do
remove :avatar_url remove(:avatar_url)
remove :banner_url remove(:banner_url)
end end
end end
end end

View File

@ -3,13 +3,13 @@ defmodule Mobilizon.Repo.Migrations.MakeActorPublicKeyNullable do
def up do def up do
alter table(:actors) do alter table(:actors) do
modify :public_key, :text, null: true modify(:public_key, :text, null: true)
end end
end end
def down do def down do
alter table(:actors) do alter table(:actors) do
modify :public_key, :text, null: false modify(:public_key, :text, null: false)
end end
end end
end end

View File

@ -3,13 +3,13 @@ defmodule Mobilizon.Repo.Migrations.AddUUIDIdToEvents do
def up do def up do
alter table(:events) do alter table(:events) do
add :uuid, :uuid add(:uuid, :uuid)
end end
end end
def down do def down do
alter table(:events) do alter table(:events) do
remove :uuid remove(:uuid)
end end
end end
end end

View File

@ -3,13 +3,13 @@ defmodule Mobilizon.Repo.Migrations.AddApprovedStatusToMember do
def up do def up do
alter table(:members) do alter table(:members) do
add :approved, :boolean, default: true add(:approved, :boolean, default: true)
end end
end end
def down do def down do
alter table(:members) do alter table(:members) do
remove :approved remove(:approved)
end end
end end
end end

View File

@ -3,13 +3,13 @@ defmodule Mobilizon.Repo.Migrations.AddUUIDToComments do
def up do def up do
alter table(:comments) do alter table(:comments) do
add :uuid, :uuid add(:uuid, :uuid)
end end
end end
def down do def down do
alter table(:comments) do alter table(:comments) do
remove :uuid remove(:uuid)
end end
end end
end end

View File

@ -3,13 +3,13 @@ defmodule Mobilizon.Repo.Migrations.MakeSharedInboxUrlNullable do
def up do def up do
alter table(:actors) do alter table(:actors) do
modify :shared_inbox_url, :string, null: true, default: nil modify(:shared_inbox_url, :string, null: true, default: nil)
end end
end end
def down do def down do
alter table(:actors) do alter table(:actors) do
add :shared_inbox_url, :string, null: false, default: "" add(:shared_inbox_url, :string, null: false, default: "")
end end
end end
end end

View File

@ -2,16 +2,17 @@ defmodule Mobilizon.Repo.Migrations.FusionPublicPrivateKeyIntoKeysColumn do
use Ecto.Migration use Ecto.Migration
def up do def up do
rename table(:actors), :private_key, to: :keys rename(table(:actors), :private_key, to: :keys)
alter table(:actors) do alter table(:actors) do
remove :public_key remove(:public_key)
end end
end end
def down do def down do
alter table(:actors) do alter table(:actors) do
rename :keys, to: :private_key rename(:keys, to: :private_key)
add :public_key, :text, null: true add(:public_key, :text, null: true)
end end
end end
end end

View File

@ -3,21 +3,21 @@ defmodule Mobilizon.Repo.Migrations.AddAttributedToFieldToEventsAndComments do
def up do def up do
alter table(:events) do alter table(:events) do
add :attributed_to_id, references(:actors, on_delete: :nothing) add(:attributed_to_id, references(:actors, on_delete: :nothing))
end end
alter table(:comments) do alter table(:comments) do
add :attributed_to_id, references(:actors, on_delete: :nothing) add(:attributed_to_id, references(:actors, on_delete: :nothing))
end end
end end
def down do def down do
alter table(:events) do alter table(:events) do
remove :attributed_to_id remove(:attributed_to_id)
end end
alter table(:comments) do alter table(:comments) do
remove :attributed_to_id remove(:attributed_to_id)
end end
end end
end end

View File

@ -3,18 +3,21 @@ defmodule :"Elixir.Mobilizon.Repo.Migrations.Add-user-confirm-email-fields" do
def up do def up do
alter table(:users) do alter table(:users) do
add :confirmed_at, :utc_datetime add(:confirmed_at, :utc_datetime)
add :confirmation_sent_at, :utc_datetime add(:confirmation_sent_at, :utc_datetime)
add :confirmation_token, :string add(:confirmation_token, :string)
end end
create unique_index(:users, [:confirmation_token], name: "index_unique_users_confirmation_token")
create(
unique_index(:users, [:confirmation_token], name: "index_unique_users_confirmation_token")
)
end end
def down do def down do
alter table(:users) do alter table(:users) do
remove :confirmed_at remove(:confirmed_at)
remove :confirmation_sent_at remove(:confirmation_sent_at)
remove :confirmation_token remove(:confirmation_token)
end end
end end
end end

View File

@ -3,16 +3,21 @@ defmodule :"Elixir.Mobilizon.Repo.Migrations.Add-user-password-reset-fields" do
def up do def up do
alter table(:users) do alter table(:users) do
add :reset_password_sent_at, :utc_datetime add(:reset_password_sent_at, :utc_datetime)
add :reset_password_token, :string add(:reset_password_token, :string)
end end
create unique_index(:users, [:reset_password_token], name: "index_unique_users_reset_password_token")
create(
unique_index(:users, [:reset_password_token],
name: "index_unique_users_reset_password_token"
)
)
end end
def down do def down do
alter table(:users) do alter table(:users) do
remove :reset_password_sent_at remove(:reset_password_sent_at)
remove :reset_password_token remove(:reset_password_token)
end end
end end
end end

View File

@ -3,15 +3,15 @@ defmodule Mobilizon.Repo.Migrations.RevertAlterEventTimestampsToDateTimeWithTime
def up do def up do
alter table(:events) do alter table(:events) do
modify :inserted_at, :timestamptz modify(:inserted_at, :timestamptz)
modify :updated_at, :timestamptz modify(:updated_at, :timestamptz)
end end
end end
def down do def down do
alter table(:events) do alter table(:events) do
modify :inserted_at, :utc_datetime modify(:inserted_at, :utc_datetime)
modify :updated_at, :utc_datetime modify(:updated_at, :utc_datetime)
end end
end end
end end

View File

@ -3,25 +3,29 @@ defmodule Mobilizon.Repo.Migrations.AddAddressType do
def up do def up do
alter table(:events) do alter table(:events) do
add :online_address, :string add(:online_address, :string)
add :phone, :string add(:phone, :string)
end end
drop constraint(:events, "events_address_id_fkey")
rename table(:events), :address_id, to: :physical_address_id drop(constraint(:events, "events_address_id_fkey"))
rename(table(:events), :address_id, to: :physical_address_id)
alter table(:events) do alter table(:events) do
modify :physical_address_id, references(:addresses, on_delete: :nothing) modify(:physical_address_id, references(:addresses, on_delete: :nothing))
end end
end end
def down do def down do
alter table(:events) do alter table(:events) do
remove :online_address remove(:online_address)
remove :phone remove(:phone)
end end
drop constraint(:events, "events_physical_address_id_fkey")
rename table(:events), :physical_address_id, to: :address_id drop(constraint(:events, "events_physical_address_id_fkey"))
rename(table(:events), :physical_address_id, to: :address_id)
alter table(:events) do alter table(:events) do
modify :address_id, references(:addresses, on_delete: :nothing) modify(:address_id, references(:addresses, on_delete: :nothing))
end end
end end
end end

View File

@ -9,7 +9,7 @@ defmodule Mobilizon.Repo.Migrations.RemoveSlugForEvent do
def down do def down do
alter table(:events) do alter table(:events) do
add :slug, :string, null: false add(:slug, :string, null: false)
end end
end end
end end

View File

@ -3,13 +3,13 @@ defmodule Mobilizon.Repo.Migrations.AlterEventsSetDescriptionAsText do
def up do def up do
alter table(:events) do alter table(:events) do
modify :description, :text modify(:description, :text)
end end
end end
def down do def down do
alter table(:events) do alter table(:events) do
modify :description, :string modify(:description, :string)
end end
end end
end end

View File

@ -3,21 +3,21 @@ defmodule Mobilizon.Repo.Migrations.AllowMultipleAccountsForUser do
def up do def up do
alter table(:actors) do alter table(:actors) do
add :user_id, references(:users, on_delete: :delete_all), null: true add(:user_id, references(:users, on_delete: :delete_all), null: true)
end end
alter table(:users) do alter table(:users) do
remove :actor_id remove(:actor_id)
end end
end end
def down do def down do
alter table(:users) do alter table(:users) do
add :actor_id, references(:actors, on_delete: :delete_all), null: false add(:actor_id, references(:actors, on_delete: :delete_all), null: false)
end end
alter table(:actors) do alter table(:actors) do
remove :user_id remove(:user_id)
end end
end end
end end

View File

@ -2,10 +2,18 @@ defmodule Mobilizon.Repo.Migrations.MakeFollowerTableUnique do
use Ecto.Migration use Ecto.Migration
def up do def up do
create unique_index(:followers, [:actor_id, :target_actor_id], name: :followers_actor_target_actor_unique_index) create(
unique_index(:followers, [:actor_id, :target_actor_id],
name: :followers_actor_target_actor_unique_index
)
)
end end
def down do def down do
drop index(:followers, [:actor_id, :target_actor_id], name: :followers_actor_target_actor_unique_index) drop(
index(:followers, [:actor_id, :target_actor_id],
name: :followers_actor_target_actor_unique_index
)
)
end end
end end

View File

@ -3,17 +3,22 @@ defmodule Mobilizon.Repo.Migrations.AddPrimaryKeyToMember do
def up do def up do
execute("ALTER TABLE members DROP CONSTRAINT IF EXISTS members_pkey") execute("ALTER TABLE members DROP CONSTRAINT IF EXISTS members_pkey")
drop_if_exists index(:members, ["members_account_id_index"]) drop_if_exists(index(:members, ["members_account_id_index"]))
create unique_index(:members, [:actor_id, :parent_id], name: :members_actor_parent_unique_index)
create(
unique_index(:members, [:actor_id, :parent_id], name: :members_actor_parent_unique_index)
)
alter table(:members) do alter table(:members) do
add :id, :serial, primary_key: true add(:id, :serial, primary_key: true)
end end
end end
def down do def down do
drop index(:members, [:actor_id, :parent_id], name: :members_actor_parent_unique_index) drop(index(:members, [:actor_id, :parent_id], name: :members_actor_parent_unique_index))
alter table(:members) do alter table(:members) do
remove :id remove(:id)
end end
end end
end end

View File

@ -3,13 +3,13 @@ defmodule Mobilizon.Repo.Migrations.AddDefaultActorUserField do
def up do def up do
alter table(:users) do alter table(:users) do
add :default_actor_id, :integer add(:default_actor_id, :integer)
end end
end end
def down do def down do
alter table(:users) do alter table(:users) do
remove :default_actor_id remove(:default_actor_id)
end end
end end
end end

View File

@ -5,22 +5,22 @@ defmodule Mobilizon.Repo.Migrations.FixCommentsReferences do
use Ecto.Migration use Ecto.Migration
def up do def up do
drop constraint(:comments, "comments_in_reply_to_comment_id_fkey") drop(constraint(:comments, "comments_in_reply_to_comment_id_fkey"))
drop constraint(:comments, "comments_origin_comment_id_fkey") drop(constraint(:comments, "comments_origin_comment_id_fkey"))
alter table(:comments) do alter table(:comments) do
modify :in_reply_to_comment_id, references(:comments, on_delete: :nothing) modify(:in_reply_to_comment_id, references(:comments, on_delete: :nothing))
modify :origin_comment_id, references(:comments, on_delete: :nothing) modify(:origin_comment_id, references(:comments, on_delete: :nothing))
end end
end end
def down do def down do
drop constraint(:comments, "comments_in_reply_to_comment_id_fkey") drop(constraint(:comments, "comments_in_reply_to_comment_id_fkey"))
drop constraint(:comments, "comments_origin_comment_id_fkey") drop(constraint(:comments, "comments_origin_comment_id_fkey"))
alter table(:comments) do alter table(:comments) do
modify :in_reply_to_comment_id, references(:categories, on_delete: :nothing) modify(:in_reply_to_comment_id, references(:categories, on_delete: :nothing))
modify :origin_comment_id, references(:addresses, on_delete: :delete_all) modify(:origin_comment_id, references(:addresses, on_delete: :delete_all))
end end
end end
end end

View File

@ -2,18 +2,28 @@ defmodule Mobilizon.Repo.Migrations.ChangeActorsIndexes do
use Ecto.Migration use Ecto.Migration
def up do def up do
drop index("actors", [:preferred_username, :domain], name: :actors_preferred_username_domain_index) drop(
drop index("actors", [:name, :domain], name: :accounts_username_domain_index) index("actors", [:preferred_username, :domain],
execute "ALTER INDEX accounts_pkey RENAME TO actors_pkey" name: :actors_preferred_username_domain_index
create index("actors", [:preferred_username, :domain, :type], unique: true) )
create index("actors", [:url], unique: true) )
drop(index("actors", [:name, :domain], name: :accounts_username_domain_index))
execute("ALTER INDEX accounts_pkey RENAME TO actors_pkey")
create(index("actors", [:preferred_username, :domain, :type], unique: true))
create(index("actors", [:url], unique: true))
end end
def down do def down do
create index("actors", [:preferred_username, :domain], name: :actors_preferred_username_domain_index) create(
create index("actors", [:name, :domain], name: :accounts_username_domain_index) index("actors", [:preferred_username, :domain],
execute "ALTER INDEX actors_pkey RENAME TO accounts_pkey" name: :actors_preferred_username_domain_index
drop index("actors", [:preferred_username, :domain, :type]) )
drop index("actors", [:url]) )
create(index("actors", [:name, :domain], name: :accounts_username_domain_index))
execute("ALTER INDEX actors_pkey RENAME TO accounts_pkey")
drop(index("actors", [:preferred_username, :domain, :type]))
drop(index("actors", [:url]))
end end
end end

View File

@ -2,9 +2,10 @@ defmodule Mobilizon.Repo.Migrations.FixEventVisibility do
use Ecto.Migration use Ecto.Migration
def up do def up do
Mobilizon.Events.EventVisibilityEnum.create_type Mobilizon.Events.EventVisibilityEnum.create_type()
Mobilizon.Events.EventStatusEnum.create_type Mobilizon.Events.EventStatusEnum.create_type()
Mobilizon.Events.CommentVisibilityEnum.create_type Mobilizon.Events.CommentVisibilityEnum.create_type()
alter table(:events) do alter table(:events) do
remove(:public) remove(:public)
remove(:status) remove(:status)
@ -26,11 +27,13 @@ defmodule Mobilizon.Repo.Migrations.FixEventVisibility do
add(:public, :boolean, null: false, default: false) add(:public, :boolean, null: false, default: false)
add(:status, :integer, null: false, default: 0) add(:status, :integer, null: false, default: 0)
end end
alter table(:comments) do alter table(:comments) do
remove(:visibility) remove(:visibility)
end end
Mobilizon.Events.EventVisibilityEnum.drop_type
Mobilizon.Events.EventStatusEnum.drop_type Mobilizon.Events.EventVisibilityEnum.drop_type()
Mobilizon.Events.CommentVisibilityEnum.drop_type Mobilizon.Events.EventStatusEnum.drop_type()
Mobilizon.Events.CommentVisibilityEnum.drop_type()
end end
end end

View File

@ -3,8 +3,8 @@ defmodule Mobilizon.Repo.Migrations.RemoveAddressType do
require Logger require Logger
def up do def up do
execute "ALTER TABLE \"events\" DROP COLUMN IF EXISTS address_type" execute("ALTER TABLE \"events\" DROP COLUMN IF EXISTS address_type")
execute "DROP TYPE IF EXISTS address_type" execute("DROP TYPE IF EXISTS address_type")
rename table(:events), :phone, to: :phone_address rename(table(:events), :phone, to: :phone_address)
end end
end end

View File

@ -2,12 +2,12 @@ defmodule Mobilizon.Repo.Migrations.GroupDeleteMembersCascade do
use Ecto.Migration use Ecto.Migration
def change do def change do
drop constraint(:members, "members_account_id_fkey") drop(constraint(:members, "members_account_id_fkey"))
drop constraint(:members, "members_parent_id_fkey") drop(constraint(:members, "members_parent_id_fkey"))
alter table(:members) do alter table(:members) do
modify :actor_id, references(:actors, on_delete: :delete_all) modify(:actor_id, references(:actors, on_delete: :delete_all))
modify :parent_id, references(:actors, on_delete: :delete_all) modify(:parent_id, references(:actors, on_delete: :delete_all))
end end
end end
end end

View File

@ -9,17 +9,21 @@ defmodule Mobilizon.Repo.Migrations.SplitEventVisibilityAndJoinOptions do
Visibility allowed nullable values previously Visibility allowed nullable values previously
""" """
def up do def up do
execute "ALTER TABLE events ALTER COLUMN visibility TYPE VARCHAR USING visibility::text" execute("ALTER TABLE events ALTER COLUMN visibility TYPE VARCHAR USING visibility::text")
EventVisibilityEnum.drop_type EventVisibilityEnum.drop_type()
EventVisibilityEnum.create_type EventVisibilityEnum.create_type()
execute "ALTER TABLE events ALTER COLUMN visibility TYPE event_visibility_type USING visibility::event_visibility_type"
execute(
"ALTER TABLE events ALTER COLUMN visibility TYPE event_visibility_type USING visibility::event_visibility_type"
)
JoinOptionsEnum.create_type()
JoinOptionsEnum.create_type
alter table(:events) do alter table(:events) do
add(:join_options, JoinOptionsEnum.type(), null: false, default: "free") add(:join_options, JoinOptionsEnum.type(), null: false, default: "free")
end end
execute "UPDATE events SET visibility = 'public' WHERE visibility IS NULL" execute("UPDATE events SET visibility = 'public' WHERE visibility IS NULL")
alter table(:events) do alter table(:events) do
modify(:visibility, EventVisibilityEnum.type(), null: false, default: "public") modify(:visibility, EventVisibilityEnum.type(), null: false, default: "public")
@ -30,11 +34,15 @@ defmodule Mobilizon.Repo.Migrations.SplitEventVisibilityAndJoinOptions do
alter table(:events) do alter table(:events) do
remove(:join_options) remove(:join_options)
end end
JoinOptionsEnum.drop_type
execute "ALTER TABLE events ALTER COLUMN visibility TYPE VARCHAR USING visibility::text" JoinOptionsEnum.drop_type()
EventVisibilityEnum.drop_type
EventVisibilityEnum.create_type execute("ALTER TABLE events ALTER COLUMN visibility TYPE VARCHAR USING visibility::text")
execute "ALTER TABLE events ALTER COLUMN visibility TYPE event_visibility_type USING visibility::event_visibility_type" EventVisibilityEnum.drop_type()
EventVisibilityEnum.create_type()
execute(
"ALTER TABLE events ALTER COLUMN visibility TYPE event_visibility_type USING visibility::event_visibility_type"
)
end end
end end

View File

@ -9,16 +9,17 @@ defmodule Mobilizon.Repo.Migrations.MoveParticipantRoleToEnum do
add(:role_tmp, ParticipantRoleEnum.type(), default: "participant") add(:role_tmp, ParticipantRoleEnum.type(), default: "participant")
end end
execute "UPDATE participants set role_tmp = 'not_approved' where role = 0" 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 = 'participant' where role = 1")
execute "UPDATE participants set role_tmp = 'moderator' where role = 2" 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 = 'administrator' where role = 3")
execute "UPDATE participants set role_tmp = 'creator' where role = 4" execute("UPDATE participants set role_tmp = 'creator' where role = 4")
alter table(:participants) do alter table(:participants) do
remove(:role) remove(:role)
end end
rename table(:participants), :role_tmp, to: :role
rename(table(:participants), :role_tmp, to: :role)
end end
def down do def down do
@ -26,17 +27,18 @@ defmodule Mobilizon.Repo.Migrations.MoveParticipantRoleToEnum do
add(:role_tmp, :integer, default: 1) add(:role_tmp, :integer, default: 1)
end end
execute "UPDATE participants set role_tmp = 0 where role = 'not_approved'" 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 = 1 where role = 'participant'")
execute "UPDATE participants set role_tmp = 2 where role = 'moderator'" 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 = 3 where role = 'administrator'")
execute "UPDATE participants set role_tmp = 4 where role = 'creator'" execute("UPDATE participants set role_tmp = 4 where role = 'creator'")
alter table(:participants) do alter table(:participants) do
remove(:role) remove(:role)
end end
ParticipantRoleEnum.drop_type() ParticipantRoleEnum.drop_type()
rename table(:participants), :role_tmp, to: :role rename(table(:participants), :role_tmp, to: :role)
end end
end end

View File

@ -3,20 +3,21 @@ defmodule Mobilizon.Repo.Migrations.TagsRelations do
def up do def up do
create table(:tag_relations, primary_key: false) do create table(:tag_relations, primary_key: false) do
add :tag_id, references(:tags, on_delete: :delete_all), null: false, primary_key: true add(:tag_id, references(:tags, on_delete: :delete_all), null: false, primary_key: true)
add :link_id, references(:tags, on_delete: :delete_all), null: false, primary_key: true add(:link_id, references(:tags, on_delete: :delete_all), null: false, primary_key: true)
add :weight, :integer, null: false, default: 1 add(:weight, :integer, null: false, default: 1)
end end
create constraint(:tag_relations, :no_self_loops_check, check: "tag_id <> link_id")
create index(:tag_relations, [:tag_id], name: :index_tag_relations_tag_id) create(constraint(:tag_relations, :no_self_loops_check, check: "tag_id <> link_id"))
create index(:tag_relations, [:link_id], name: :index_tag_relations_link_id) create(index(:tag_relations, [:tag_id], name: :index_tag_relations_tag_id))
create(index(:tag_relations, [:link_id], name: :index_tag_relations_link_id))
end end
def down do def down do
drop constraint(:tag_relations, :no_self_loops_check) drop(constraint(:tag_relations, :no_self_loops_check))
drop index(:tag_relations, [:tags_id]) drop(index(:tag_relations, [:tags_id]))
drop index(:tag_relations, [:link_id]) drop(index(:tag_relations, [:link_id]))
drop table(:tag_relations) drop(table(:tag_relations))
end end
end end

View File

@ -18,7 +18,7 @@ defmodule Mobilizon.Repo.Migrations.DropDatetimetz do
add(:ends_on, :utc_datetime) add(:ends_on, :utc_datetime)
end end
execute "DROP TYPE datetimetz" execute("DROP TYPE datetimetz")
end end
def down do def down do

View File

@ -39,4 +39,3 @@ insert(:participant, actor: actor, event: event4, role: :participant)
# Insert a group # Insert a group
group = insert(:actor, type: :Group) group = insert(:actor, type: :Group)