Fix mix format and format migrations too

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Fix credo warnings

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Show elixir version

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Also lint migrations

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Reset allow failure to false

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2019-02-22 14:18:52 +01:00
parent 5024dfbbef
commit 7dd7e8fc36
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
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:
- mix deps.get
script:
- mix format --check-formatted --dry-run
- mix credo list
- mix format --check-formatted --dry-run
- mix hex.outdated
cache:
paths:
- deps

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,14 +3,13 @@ defmodule Mobilizon.Repo.Migrations.CreateTracks do
def change do
create table(:tracks) do
add :name, :string
add :description, :text
add :color, :string
add(:name, :string)
add(:description, :text)
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()
end
end
end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,101 +2,106 @@ defmodule Mobilizon.Repo.Migrations.MoveFromAccountToActor do
use Ecto.Migration
def up do
drop table("event_requests")
drop table("group_requests")
drop(table("event_requests"))
drop(table("group_requests"))
alter table("events") do
remove :organizer_group_id
remove(:organizer_group_id)
end
rename table("members"), :account_id, to: :actor_id
rename(table("members"), :account_id, to: :actor_id)
alter table("members") do
remove :group_id
add :parent_id, references(:accounts, on_delete: :nothing)
remove(:group_id)
add(:parent_id, references(:accounts, on_delete: :nothing))
end
drop table("groups")
rename table("accounts"), to: table("actors")
Mobilizon.Actors.ActorTypeEnum.create_type
rename table("actors"), :username, to: :name
rename table("actors"), :description, to: :summary
rename table("actors"), :display_name, to: :preferred_username
drop(table("groups"))
rename(table("accounts"), to: table("actors"))
Mobilizon.Actors.ActorTypeEnum.create_type()
rename(table("actors"), :username, to: :name)
rename(table("actors"), :description, to: :summary)
rename(table("actors"), :display_name, to: :preferred_username)
alter table("actors") do
add :inbox_url, :string
add :outbox_url, :string
add :following_url, :string, null: true
add :followers_url, :string, null: true
add :shared_inbox_url, :string, null: false, default: ""
add :type, :actor_type
add :manually_approves_followers, :boolean, default: false
modify :name, :string, null: true
modify :preferred_username, :string, null: false
add(:inbox_url, :string)
add(:outbox_url, :string)
add(:following_url, :string, null: true)
add(:followers_url, :string, null: true)
add(:shared_inbox_url, :string, null: false, default: "")
add(:type, :actor_type)
add(:manually_approves_followers, :boolean, default: false)
modify(:name, :string, null: true)
modify(:preferred_username, :string, null: false)
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
add :approved, :boolean, default: false
add :score, :integer, default: 1000
add :actor_id, references(:actors, on_delete: :nothing)
add :target_actor_id, references(:actors, on_delete: :nothing)
add(:approved, :boolean, default: false)
add(:score, :integer, default: 1000)
add(:actor_id, references(:actors, on_delete: :nothing))
add(:target_actor_id, references(:actors, on_delete: :nothing))
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
def down do
create table("event_requests")
create table("group_requests")
create(table("event_requests"))
create(table("group_requests"))
alter table("events") do
add :organizer_group_id, :integer
add(:organizer_group_id, :integer)
end
rename table("members"), :actor_id, to: :account_id
rename(table("members"), :actor_id, to: :account_id)
alter table("members") do
add :group_id, :integer
remove :parent_id
add(:group_id, :integer)
remove(:parent_id)
end
create table("groups")
rename table("actors"), to: table("accounts")
rename table("accounts"), :name, to: :username
rename table("accounts"), :summary, to: :description
rename table("accounts"), :preferred_username, to: :display_name
create(table("groups"))
rename(table("actors"), to: table("accounts"))
rename(table("accounts"), :name, to: :username)
rename(table("accounts"), :summary, to: :description)
rename(table("accounts"), :preferred_username, to: :display_name)
alter table("accounts") do
remove :inbox_url
remove :outbox_url
remove :following_url
remove :followers_url
remove :shared_inbox_url
remove :type
remove :manually_approves_followers
modify :username, :string, null: false
modify :display_name, :string, null: true
remove(:inbox_url)
remove(:outbox_url)
remove(:following_url)
remove(:followers_url)
remove(:shared_inbox_url)
remove(:type)
remove(:manually_approves_followers)
modify(:username, :string, null: false)
modify(:display_name, :string, null: true)
end
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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,13 +3,13 @@ defmodule Mobilizon.Repo.Migrations.MakeSharedInboxUrlNullable do
def up 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
def down do
alter table(:actors) do
add :shared_inbox_url, :string, null: false, default: ""
add(:shared_inbox_url, :string, null: false, default: "")
end
end
end

View file

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

View file

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

View file

@ -3,18 +3,21 @@ defmodule :"Elixir.Mobilizon.Repo.Migrations.Add-user-confirm-email-fields" do
def up do
alter table(:users) do
add :confirmed_at, :utc_datetime
add :confirmation_sent_at, :utc_datetime
add :confirmation_token, :string
add(:confirmed_at, :utc_datetime)
add(:confirmation_sent_at, :utc_datetime)
add(:confirmation_token, :string)
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
def down do
alter table(:users) do
remove :confirmed_at
remove :confirmation_sent_at
remove :confirmation_token
remove(:confirmed_at)
remove(:confirmation_sent_at)
remove(:confirmation_token)
end
end
end

View file

@ -3,16 +3,21 @@ defmodule :"Elixir.Mobilizon.Repo.Migrations.Add-user-password-reset-fields" do
def up do
alter table(:users) do
add :reset_password_sent_at, :utc_datetime
add :reset_password_token, :string
add(:reset_password_sent_at, :utc_datetime)
add(:reset_password_token, :string)
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
def down do
alter table(:users) do
remove :reset_password_sent_at
remove :reset_password_token
remove(:reset_password_sent_at)
remove(:reset_password_token)
end
end
end

View file

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

View file

@ -3,25 +3,29 @@ defmodule Mobilizon.Repo.Migrations.AddAddressType do
def up do
alter table(:events) do
add :online_address, :string
add :phone, :string
add(:online_address, :string)
add(:phone, :string)
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
modify :physical_address_id, references(:addresses, on_delete: :nothing)
modify(:physical_address_id, references(:addresses, on_delete: :nothing))
end
end
def down do
alter table(:events) do
remove :online_address
remove :phone
remove(:online_address)
remove(:phone)
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
modify :address_id, references(:addresses, on_delete: :nothing)
modify(:address_id, references(:addresses, on_delete: :nothing))
end
end
end

View file

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

View file

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

View file

@ -3,21 +3,21 @@ defmodule Mobilizon.Repo.Migrations.AllowMultipleAccountsForUser do
def up 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
alter table(:users) do
remove :actor_id
remove(:actor_id)
end
end
def down 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
alter table(:actors) do
remove :user_id
remove(:user_id)
end
end
end

View file

@ -2,10 +2,18 @@ defmodule Mobilizon.Repo.Migrations.MakeFollowerTableUnique do
use Ecto.Migration
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
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

View file

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

View file

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

View file

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

View file

@ -2,18 +2,28 @@ defmodule Mobilizon.Repo.Migrations.ChangeActorsIndexes do
use Ecto.Migration
def up do
drop index("actors", [:preferred_username, :domain], name: :actors_preferred_username_domain_index)
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)
drop(
index("actors", [:preferred_username, :domain],
name: :actors_preferred_username_domain_index
)
)
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
def down do
create index("actors", [:preferred_username, :domain], name: :actors_preferred_username_domain_index)
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])
create(
index("actors", [:preferred_username, :domain],
name: :actors_preferred_username_domain_index
)
)
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

View file

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

View file

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

View file

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

View file

@ -9,17 +9,21 @@ defmodule Mobilizon.Repo.Migrations.SplitEventVisibilityAndJoinOptions do
Visibility allowed nullable values previously
"""
def up do
execute "ALTER TABLE events ALTER COLUMN visibility TYPE VARCHAR USING visibility::text"
EventVisibilityEnum.drop_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 VARCHAR USING visibility::text")
EventVisibilityEnum.drop_type()
EventVisibilityEnum.create_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
add(:join_options, JoinOptionsEnum.type(), null: false, default: "free")
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
modify(:visibility, EventVisibilityEnum.type(), null: false, default: "public")
@ -30,11 +34,15 @@ defmodule Mobilizon.Repo.Migrations.SplitEventVisibilityAndJoinOptions do
alter table(:events) do
remove(:join_options)
end
JoinOptionsEnum.drop_type
execute "ALTER TABLE events ALTER COLUMN visibility TYPE VARCHAR USING visibility::text"
EventVisibilityEnum.drop_type
EventVisibilityEnum.create_type
execute "ALTER TABLE events ALTER COLUMN visibility TYPE event_visibility_type USING visibility::event_visibility_type"
JoinOptionsEnum.drop_type()
execute("ALTER TABLE events ALTER COLUMN visibility TYPE VARCHAR USING visibility::text")
EventVisibilityEnum.drop_type()
EventVisibilityEnum.create_type()
execute(
"ALTER TABLE events ALTER COLUMN visibility TYPE event_visibility_type USING visibility::event_visibility_type"
)
end
end

View file

@ -9,16 +9,17 @@ defmodule Mobilizon.Repo.Migrations.MoveParticipantRoleToEnum do
add(:role_tmp, ParticipantRoleEnum.type(), default: "participant")
end
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"
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")
alter table(:participants) do
remove(:role)
end
rename table(:participants), :role_tmp, to: :role
rename(table(:participants), :role_tmp, to: :role)
end
def down do
@ -26,17 +27,18 @@ defmodule Mobilizon.Repo.Migrations.MoveParticipantRoleToEnum do
add(:role_tmp, :integer, default: 1)
end
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'"
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'")
alter table(:participants) do
remove(:role)
end
ParticipantRoleEnum.drop_type()
rename table(:participants), :role_tmp, to: :role
rename(table(:participants), :role_tmp, to: :role)
end
end

View file

@ -3,20 +3,21 @@ defmodule Mobilizon.Repo.Migrations.TagsRelations do
def up do
create table(:tag_relations, primary_key: false) do
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 :weight, :integer, null: false, default: 1
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(:weight, :integer, null: false, default: 1)
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 index(:tag_relations, [:link_id], name: :index_tag_relations_link_id)
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(index(:tag_relations, [:link_id], name: :index_tag_relations_link_id))
end
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, [:link_id])
drop table(:tag_relations)
drop(index(:tag_relations, [:tags_id]))
drop(index(:tag_relations, [:link_id]))
drop(table(:tag_relations))
end
end

View file

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

View file

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