Separating of Storage context
This commit is contained in:
parent
86a0630a7d
commit
fa037fd683
@ -7,7 +7,7 @@ use Mix.Config
|
||||
|
||||
# General application configuration
|
||||
config :mobilizon,
|
||||
ecto_repos: [Mobilizon.Repo]
|
||||
ecto_repos: [Mobilizon.Storage.Repo]
|
||||
|
||||
config :mobilizon, :instance,
|
||||
name: System.get_env("MOBILIZON_INSTANCE_NAME") || "Localhost",
|
||||
@ -78,7 +78,7 @@ config :mobilizon, MobilizonWeb.Guardian,
|
||||
secret_key: "ty0WM7YBE3ojvxoUQxo8AERrNpfbXnIJ82ovkPdqbUFw31T5LcK8wGjaOiReVQjo"
|
||||
|
||||
config :guardian, Guardian.DB,
|
||||
repo: Mobilizon.Repo,
|
||||
repo: Mobilizon.Storage.Repo,
|
||||
# default
|
||||
schema_name: "guardian_tokens",
|
||||
# store all token types if not set
|
||||
|
@ -61,11 +61,11 @@ config :phoenix, :stacktrace_depth, 20
|
||||
# Initialize plugs at runtime for faster development compilation
|
||||
config :phoenix, :plug_init_mode, :runtime
|
||||
|
||||
config :mobilizon, Mobilizon.Mailer, adapter: Bamboo.LocalAdapter
|
||||
config :mobilizon, Mobilizon.Email.Mailer, adapter: Bamboo.LocalAdapter
|
||||
|
||||
# Configure your database
|
||||
config :mobilizon, Mobilizon.Repo,
|
||||
types: Mobilizon.PostgresTypes,
|
||||
config :mobilizon, Mobilizon.Storage.Repo,
|
||||
types: Mobilizon.Storage.PostgresTypes,
|
||||
username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "mobilizon",
|
||||
password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "mobilizon",
|
||||
database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_dev",
|
||||
|
@ -12,8 +12,8 @@ config :mobilizon, MobilizonWeb.Endpoint,
|
||||
cache_static_manifest: "priv/static/manifest.json"
|
||||
|
||||
# Configure your database
|
||||
config :mobilizon, Mobilizon.Repo,
|
||||
types: Mobilizon.PostgresTypes,
|
||||
config :mobilizon, Mobilizon.Storage.Repo,
|
||||
types: Mobilizon.Storage.PostgresTypes,
|
||||
username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "mobilizon",
|
||||
password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "mobilizon",
|
||||
database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_prod",
|
||||
@ -21,7 +21,7 @@ config :mobilizon, Mobilizon.Repo,
|
||||
port: System.get_env("MOBILIZON_DATABASE_PORT") || "5432",
|
||||
pool_size: 15
|
||||
|
||||
config :mobilizon, Mobilizon.Mailer,
|
||||
config :mobilizon, Mobilizon.Email.Mailer,
|
||||
adapter: Bamboo.SMTPAdapter,
|
||||
server: "localhost",
|
||||
hostname: "localhost",
|
||||
|
@ -22,16 +22,15 @@ config :logger,
|
||||
level: :info
|
||||
|
||||
# Configure your database
|
||||
config :mobilizon, Mobilizon.Repo,
|
||||
types: Mobilizon.PostgresTypes,
|
||||
config :mobilizon, Mobilizon.Storage.Repo,
|
||||
types: Mobilizon.Storage.PostgresTypes,
|
||||
username: System.get_env("MOBILIZON_DATABASE_USERNAME") || "mobilizon",
|
||||
password: System.get_env("MOBILIZON_DATABASE_PASSWORD") || "mobilizon",
|
||||
database: System.get_env("MOBILIZON_DATABASE_DBNAME") || "mobilizon_test",
|
||||
hostname: System.get_env("MOBILIZON_DATABASE_HOST") || "localhost",
|
||||
pool: Ecto.Adapters.SQL.Sandbox,
|
||||
types: Mobilizon.PostgresTypes
|
||||
pool: Ecto.Adapters.SQL.Sandbox
|
||||
|
||||
config :mobilizon, Mobilizon.Mailer, adapter: Bamboo.TestAdapter
|
||||
config :mobilizon, Mobilizon.Email.Mailer, adapter: Bamboo.TestAdapter
|
||||
|
||||
config :mobilizon, MobilizonWeb.Upload, filters: [], link_name: false
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
defmodule Mobilizon do
|
||||
@moduledoc """
|
||||
Mobilizon is a decentralized and federated Meetup-like using [ActivityPub](http://activitypub.rocks/).
|
||||
Mobilizon is a decentralized and federated Meetup-like using
|
||||
[ActivityPub](http://activitypub.rocks/).
|
||||
|
||||
It consists of an API server build with [Elixir](http://elixir-lang.github.io/) and the [Phoenix Framework](https://hexdocs.pm/phoenix).
|
||||
It consists of an API server build with [Elixir](http://elixir-lang.github.io/)
|
||||
and the [Phoenix Framework](https://hexdocs.pm/phoenix).
|
||||
|
||||
Mobilizon relies on `Guardian` for auth and `Geo`/Postgis for geographical informations.
|
||||
Mobilizon relies on `Guardian` for auth and `Geo`/Postgis for geographical
|
||||
information.
|
||||
"""
|
||||
end
|
||||
|
@ -26,25 +26,24 @@ defmodule Mobilizon.Actors.Actor do
|
||||
@moduledoc """
|
||||
Represents an actor (local and remote actors)
|
||||
"""
|
||||
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.{Actor, Follower, Member}
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Events.{Event, FeedToken}
|
||||
alias Mobilizon.Media.File
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias Mobilizon.Reports.{Report, Note}
|
||||
alias Mobilizon.Storage.{Page, Repo}
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
alias MobilizonWeb.Endpoint
|
||||
|
||||
import Ecto.Query
|
||||
import Mobilizon.Ecto
|
||||
alias Mobilizon.Repo
|
||||
|
||||
require Logger
|
||||
|
||||
# @type t :: %Actor{description: String.t, id: integer(), inserted_at: DateTime.t, updated_at: DateTime.t, display_name: String.t, domain: String.t, keys: String.t, suspended: boolean(), url: String.t, username: String.t, organized_events: list(), groups: list(), group_request: list(), user: User.t, field: ActorTypeEnum.t}
|
||||
@ -383,7 +382,7 @@ defmodule Mobilizon.Actors.Actor do
|
||||
)
|
||||
|
||||
total = Task.async(fn -> Repo.aggregate(query, :count, :id) end)
|
||||
elements = Task.async(fn -> Repo.all(paginate(query, page, limit)) end)
|
||||
elements = Task.async(fn -> Repo.all(Page.paginate(query, page, limit)) end)
|
||||
|
||||
%{total: Task.await(total), elements: Task.await(elements)}
|
||||
end
|
||||
@ -428,7 +427,7 @@ defmodule Mobilizon.Actors.Actor do
|
||||
)
|
||||
|
||||
total = Task.async(fn -> Repo.aggregate(query, :count, :id) end)
|
||||
elements = Task.async(fn -> Repo.all(paginate(query, page, limit)) end)
|
||||
elements = Task.async(fn -> Repo.all(Page.paginate(query, page, limit)) end)
|
||||
|
||||
%{total: Task.await(total), elements: Task.await(elements)}
|
||||
end
|
||||
|
@ -3,16 +3,15 @@ defmodule Mobilizon.Actors do
|
||||
The Actors context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
import Mobilizon.Ecto
|
||||
import Ecto.Query
|
||||
|
||||
alias Mobilizon.Repo
|
||||
alias Ecto.Multi
|
||||
|
||||
alias Mobilizon.Actors.{Actor, Bot, Member, Follower}
|
||||
alias Mobilizon.Media.File
|
||||
alias Ecto.Multi
|
||||
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Storage.{Page, Repo}
|
||||
|
||||
require Logger
|
||||
|
||||
@doc false
|
||||
@ -203,7 +202,7 @@ defmodule Mobilizon.Actors do
|
||||
where: a.type == ^:Group,
|
||||
where: a.visibility in [^:public, ^:unlisted]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
)
|
||||
end
|
||||
|
||||
@ -586,7 +585,7 @@ defmodule Mobilizon.Actors do
|
||||
^username
|
||||
)
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
|
||||
total = Task.async(fn -> Repo.aggregate(query, :count, :id) end)
|
||||
elements = Task.async(fn -> Repo.all(query) end)
|
||||
@ -652,7 +651,7 @@ defmodule Mobilizon.Actors do
|
||||
})
|
||||
|
||||
try do
|
||||
Mobilizon.Repo.insert!(actor)
|
||||
Repo.insert!(actor)
|
||||
rescue
|
||||
e in Ecto.InvalidChangesetError ->
|
||||
{:error, e.changeset}
|
||||
|
@ -12,15 +12,14 @@ defmodule Mobilizon.Actors.Member do
|
||||
@moduledoc """
|
||||
Represents the membership of an actor to a group
|
||||
"""
|
||||
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query, warn: false
|
||||
import Mobilizon.Ecto
|
||||
import Ecto.Query
|
||||
|
||||
alias Mobilizon.Actors.Member
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Repo
|
||||
alias Mobilizon.Actors.{Actor, Member}
|
||||
alias Mobilizon.Storage.{Page, Repo}
|
||||
|
||||
schema "members" do
|
||||
field(:role, Mobilizon.Actors.MemberRoleEnum, default: :member)
|
||||
@ -64,7 +63,7 @@ defmodule Mobilizon.Actors.Member do
|
||||
where: m.parent_id == ^id and (m.role == ^:creator or m.role == ^:administrator),
|
||||
preload: [:actor]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -4,10 +4,11 @@ defmodule Mobilizon.Addresses do
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Mobilizon.Repo
|
||||
require Logger
|
||||
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
require Logger
|
||||
|
||||
@geom_types [:point]
|
||||
|
||||
|
@ -3,11 +3,10 @@ defmodule Mobilizon.Admin do
|
||||
The Admin context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Mobilizon.Repo
|
||||
import Mobilizon.Ecto
|
||||
import Ecto.Query
|
||||
|
||||
alias Mobilizon.Admin.ActionLog
|
||||
alias Mobilizon.Storage.{Page, Repo}
|
||||
|
||||
@doc """
|
||||
Returns the list of action_logs.
|
||||
@ -24,7 +23,7 @@ defmodule Mobilizon.Admin do
|
||||
r in ActionLog,
|
||||
preload: [:actor]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
|
@ -21,7 +21,7 @@ defmodule Mobilizon.Application do
|
||||
# Define workers and child supervisors to be supervised
|
||||
children = [
|
||||
# Start the Ecto repository
|
||||
supervisor(Mobilizon.Repo, []),
|
||||
supervisor(Mobilizon.Storage.Repo, []),
|
||||
# Start the endpoint when the application starts
|
||||
supervisor(MobilizonWeb.Endpoint, []),
|
||||
# Start your own worker by calling: Mobilizon.Worker.start_link(arg1, arg2, arg3)
|
||||
|
@ -1,44 +0,0 @@
|
||||
defmodule Mobilizon.Ecto do
|
||||
@moduledoc """
|
||||
Mobilizon Ecto utils
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
|
||||
@doc """
|
||||
Add limit and offset to the query
|
||||
"""
|
||||
def paginate(query, page \\ 1, size \\ 10)
|
||||
def paginate(query, page, _size) when is_nil(page), do: paginate(query)
|
||||
def paginate(query, page, size) when is_nil(size), do: paginate(query, page)
|
||||
|
||||
def paginate(query, page, size) do
|
||||
from(query,
|
||||
limit: ^size,
|
||||
offset: ^((page - 1) * size)
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Add sort to the query
|
||||
"""
|
||||
def sort(query, sort, direction) do
|
||||
from(
|
||||
query,
|
||||
order_by: [{^direction, ^sort}]
|
||||
)
|
||||
end
|
||||
|
||||
def increment_slug(slug) do
|
||||
case List.pop_at(String.split(slug, "-"), -1) do
|
||||
{nil, _} ->
|
||||
slug
|
||||
|
||||
{suffix, slug_parts} ->
|
||||
case Integer.parse(suffix) do
|
||||
{id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1)
|
||||
:error -> slug <> "-1"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,4 +1,4 @@
|
||||
defmodule Mobilizon.Mailer do
|
||||
defmodule Mobilizon.Email.Mailer do
|
||||
@moduledoc """
|
||||
Mobilizon Mailer.
|
||||
"""
|
@ -3,17 +3,18 @@ defmodule Mobilizon.Events do
|
||||
The Events context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
import Mobilizon.Ecto
|
||||
import Ecto.Query
|
||||
|
||||
import Mobilizon.Storage.Ecto
|
||||
|
||||
alias Mobilizon.Repo
|
||||
alias Mobilizon.Events.{Event, Comment, Participant}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Events.{Event, Comment, Participant}
|
||||
alias Mobilizon.Storage.{Page, Repo}
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
def data() do
|
||||
Dataloader.Ecto.new(Mobilizon.Repo, query: &query/2)
|
||||
Dataloader.Ecto.new(Repo, query: &query/2)
|
||||
end
|
||||
|
||||
def query(queryable, _params) do
|
||||
@ -36,7 +37,7 @@ defmodule Mobilizon.Events do
|
||||
:picture
|
||||
]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
|
||||
events = Repo.all(query)
|
||||
|
||||
@ -301,7 +302,7 @@ defmodule Mobilizon.Events do
|
||||
e in Event,
|
||||
preload: [:organizer_actor, :participants]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
|> sort(sort, direction)
|
||||
|> restrict_future_events(future)
|
||||
|> allow_unlisted(unlisted)
|
||||
@ -348,7 +349,7 @@ defmodule Mobilizon.Events do
|
||||
),
|
||||
preload: [:organizer_actor]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
|
||||
total = Task.async(fn -> Repo.aggregate(query, :count, :id) end)
|
||||
elements = Task.async(fn -> Repo.all(query) end)
|
||||
@ -493,7 +494,7 @@ defmodule Mobilizon.Events do
|
||||
def list_tags(page \\ nil, limit \\ nil) do
|
||||
Repo.all(
|
||||
Tag
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
)
|
||||
end
|
||||
|
||||
@ -514,7 +515,7 @@ defmodule Mobilizon.Events do
|
||||
on: t.id == e.tag_id,
|
||||
where: e.event_id == ^id
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
)
|
||||
end
|
||||
|
||||
@ -744,7 +745,7 @@ defmodule Mobilizon.Events do
|
||||
where: e.uuid == ^uuid,
|
||||
preload: [:actor]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
@ -769,7 +770,7 @@ defmodule Mobilizon.Events do
|
||||
where: a.id == ^id and p.role != ^:not_approved,
|
||||
preload: [:picture, :tags]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
)
|
||||
end
|
||||
|
||||
@ -789,7 +790,7 @@ defmodule Mobilizon.Events do
|
||||
where: p.event_id == ^id and p.role == ^:creator,
|
||||
preload: [:actor]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
)
|
||||
end
|
||||
|
||||
@ -1159,7 +1160,7 @@ defmodule Mobilizon.Events do
|
||||
:event
|
||||
]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|> Page.paginate(page, limit)
|
||||
|
||||
comments = Repo.all(query)
|
||||
|
||||
|
@ -1,36 +1,3 @@
|
||||
defmodule Mobilizon.Events.Tag.TitleSlug do
|
||||
@moduledoc """
|
||||
Generates slugs for tags
|
||||
"""
|
||||
alias Mobilizon.Events.Tag
|
||||
import Ecto.Query
|
||||
alias Mobilizon.Repo
|
||||
use EctoAutoslugField.Slug, from: :title, to: :slug
|
||||
|
||||
def build_slug(sources, changeset) do
|
||||
slug = super(sources, changeset)
|
||||
build_unique_slug(slug, changeset)
|
||||
end
|
||||
|
||||
defp build_unique_slug(slug, changeset) do
|
||||
query =
|
||||
from(
|
||||
t in Tag,
|
||||
where: t.slug == ^slug
|
||||
)
|
||||
|
||||
case Repo.one(query) do
|
||||
nil ->
|
||||
slug
|
||||
|
||||
_tag ->
|
||||
slug
|
||||
|> Mobilizon.Ecto.increment_slug()
|
||||
|> build_unique_slug(changeset)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Mobilizon.Events.Tag do
|
||||
@moduledoc """
|
||||
Represents a tag for events
|
||||
@ -57,4 +24,17 @@ defmodule Mobilizon.Events.Tag do
|
||||
|> validate_required([:title, :slug])
|
||||
|> TitleSlug.unique_constraint()
|
||||
end
|
||||
|
||||
def increment_slug(slug) do
|
||||
case List.pop_at(String.split(slug, "-"), -1) do
|
||||
{nil, _} ->
|
||||
slug
|
||||
|
||||
{suffix, slug_parts} ->
|
||||
case Integer.parse(suffix) do
|
||||
{id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1)
|
||||
:error -> slug <> "-1"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
33
lib/mobilizon/events/tag/title_slug.ex
Normal file
33
lib/mobilizon/events/tag/title_slug.ex
Normal file
@ -0,0 +1,33 @@
|
||||
defmodule Mobilizon.Events.Tag.TitleSlug do
|
||||
@moduledoc """
|
||||
Generates slugs for tags
|
||||
"""
|
||||
|
||||
alias Mobilizon.Events.Tag
|
||||
import Ecto.Query
|
||||
alias Mobilizon.Storage.Repo
|
||||
use EctoAutoslugField.Slug, from: :title, to: :slug
|
||||
|
||||
def build_slug(sources, changeset) do
|
||||
slug = super(sources, changeset)
|
||||
build_unique_slug(slug, changeset)
|
||||
end
|
||||
|
||||
defp build_unique_slug(slug, changeset) do
|
||||
query =
|
||||
from(
|
||||
t in Tag,
|
||||
where: t.slug == ^slug
|
||||
)
|
||||
|
||||
case Repo.one(query) do
|
||||
nil ->
|
||||
slug
|
||||
|
||||
_tag ->
|
||||
slug
|
||||
|> Tag.increment_slug()
|
||||
|> build_unique_slug(changeset)
|
||||
end
|
||||
end
|
||||
end
|
@ -8,11 +8,11 @@ defmodule Mobilizon.Media do
|
||||
alias Ecto.Multi
|
||||
|
||||
alias Mobilizon.Media.{File, Picture}
|
||||
alias Mobilizon.Repo
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
@doc false
|
||||
@spec data :: Dataloader.Ecto.t()
|
||||
def data, do: Dataloader.Ecto.new(Mobilizon.Repo, query: &query/2)
|
||||
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
|
||||
|
||||
@doc false
|
||||
@spec query(Ecto.Query.t(), map) :: Ecto.Query.t()
|
||||
|
@ -1,5 +0,0 @@
|
||||
Postgrex.Types.define(
|
||||
Mobilizon.PostgresTypes,
|
||||
[Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
|
||||
json: Jason
|
||||
)
|
@ -6,16 +6,16 @@ defmodule Mobilizon.Reports do
|
||||
import Ecto.Query
|
||||
import EctoEnum
|
||||
|
||||
import Mobilizon.Ecto
|
||||
import Mobilizon.Storage.Ecto
|
||||
|
||||
alias Mobilizon.{Page, Repo}
|
||||
alias Mobilizon.Reports.{Note, Report}
|
||||
alias Mobilizon.Storage.{Page, Repo}
|
||||
|
||||
defenum(ReportStatus, :report_status, [:open, :closed, :resolved])
|
||||
|
||||
@doc false
|
||||
@spec data :: Dataloader.Ecto.t()
|
||||
def data, do: Dataloader.Ecto.new(Mobilizon.Repo, query: &query/2)
|
||||
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
|
||||
|
||||
@doc false
|
||||
@spec query(Ecto.Query.t(), map) :: Ecto.Query.t()
|
||||
|
15
lib/mobilizon/storage/ecto.ex
Normal file
15
lib/mobilizon/storage/ecto.ex
Normal file
@ -0,0 +1,15 @@
|
||||
defmodule Mobilizon.Storage.Ecto do
|
||||
@moduledoc """
|
||||
Mobilizon Ecto utils
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
|
||||
@doc """
|
||||
Adds sort to the query.
|
||||
"""
|
||||
@spec sort(Ecto.Query.t(), atom, atom) :: Ecto.Query.t()
|
||||
def sort(query, sort, direction) do
|
||||
from(query, order_by: [{^direction, ^sort}])
|
||||
end
|
||||
end
|
@ -1,11 +1,11 @@
|
||||
defmodule Mobilizon.Page do
|
||||
defmodule Mobilizon.Storage.Page do
|
||||
@moduledoc """
|
||||
Module for pagination of queries.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
import Ecto.Query
|
||||
|
||||
alias Mobilizon.Repo
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
defstruct [
|
||||
:total,
|
||||
@ -36,7 +36,7 @@ defmodule Mobilizon.Page do
|
||||
@doc """
|
||||
Add limit and offset to the query.
|
||||
"""
|
||||
@spec paginate(Ecto.Query.t(), integer | nil, integer | nil) :: Ecto.Query.t()
|
||||
@spec paginate(Ecto.Query.t() | struct, integer | nil, integer | nil) :: Ecto.Query.t()
|
||||
def paginate(query, page \\ 1, size \\ 10)
|
||||
|
||||
def paginate(query, page, _size) when is_nil(page), do: paginate(query)
|
5
lib/mobilizon/storage/postgrex_types.ex
Normal file
5
lib/mobilizon/storage/postgrex_types.ex
Normal file
@ -0,0 +1,5 @@
|
||||
Postgrex.Types.define(
|
||||
Mobilizon.Storage.PostgresTypes,
|
||||
[Geo.PostGIS.Extension | Ecto.Adapters.Postgres.extensions()],
|
||||
json: Jason
|
||||
)
|
@ -1,14 +1,14 @@
|
||||
defmodule Mobilizon.Repo do
|
||||
defmodule Mobilizon.Storage.Repo do
|
||||
@moduledoc """
|
||||
Mobilizon Repo
|
||||
Mobilizon Repo.
|
||||
"""
|
||||
|
||||
use Ecto.Repo,
|
||||
otp_app: :mobilizon,
|
||||
adapter: Ecto.Adapters.Postgres
|
||||
|
||||
@doc """
|
||||
Dynamically loads the repository url from the
|
||||
DATABASE_URL environment variable.
|
||||
Dynamically loads the repository url from the DATABASE_URL environment variable.
|
||||
"""
|
||||
def init(_, opts) do
|
||||
{:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))}
|
@ -6,11 +6,11 @@ defmodule Mobilizon.Users do
|
||||
import Ecto.Query
|
||||
import EctoEnum
|
||||
|
||||
import Mobilizon.Ecto
|
||||
import Mobilizon.Storage.Ecto
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.{Page, Repo}
|
||||
alias Mobilizon.Storage.{Page, Repo}
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
@type tokens :: %{
|
||||
@ -22,7 +22,7 @@ defmodule Mobilizon.Users do
|
||||
|
||||
@doc false
|
||||
@spec data :: Dataloader.Ecto.t()
|
||||
def data, do: Dataloader.Ecto.new(Mobilizon.Repo, query: &query/2)
|
||||
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
|
||||
|
||||
@doc false
|
||||
@spec query(Ecto.Query.t(), map) :: Ecto.Query.t()
|
||||
|
@ -10,7 +10,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
Various utils
|
||||
"""
|
||||
|
||||
alias Mobilizon.Repo
|
||||
alias Mobilizon.Storage.Repo
|
||||
alias Mobilizon.Addresses
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Actors
|
||||
@ -165,7 +165,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
|
||||
Enum.each(Users.list_moderators(), fn moderator ->
|
||||
moderator
|
||||
|> Mobilizon.Email.Admin.report(moderator, report)
|
||||
|> Mobilizon.Mailer.deliver_later()
|
||||
|> Mobilizon.Email.Mailer.deliver_later()
|
||||
end)
|
||||
|
||||
{:ok, report}
|
||||
|
@ -1,9 +1,10 @@
|
||||
defmodule Mobilizon.Service.Users.Activation do
|
||||
@moduledoc false
|
||||
|
||||
alias Mobilizon.{Mailer, Users}
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Email.Mailer
|
||||
alias Mobilizon.Email.User, as: UserEmail
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Service.Users.Tools
|
||||
|
||||
require Logger
|
||||
|
@ -1,12 +1,14 @@
|
||||
defmodule Mobilizon.Service.Users.ResetPassword do
|
||||
@moduledoc false
|
||||
|
||||
require Logger
|
||||
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.{Mailer, Repo, Users}
|
||||
alias Mobilizon.Email.Mailer
|
||||
alias Mobilizon.Email.User, as: UserEmail
|
||||
alias Mobilizon.Service.Users.Tools
|
||||
alias Mobilizon.Storage.Repo
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
Check that the provided token is correct and update provided password
|
||||
|
6
mix.exs
6
mix.exs
@ -203,8 +203,8 @@ defmodule Mobilizon.Mixfile do
|
||||
Mobilizon.Users.UserRole,
|
||||
Mobilizon.Users.Guards,
|
||||
Mobilizon.Activity,
|
||||
Mobilizon.Ecto,
|
||||
Mobilizon.Repo
|
||||
Mobilizon.Storage.Ecto,
|
||||
Mobilizon.Storage.Repo
|
||||
],
|
||||
APIs: [
|
||||
MobilizonWeb.API.Comments,
|
||||
@ -299,7 +299,7 @@ defmodule Mobilizon.Mixfile do
|
||||
Tools: [
|
||||
Mobilizon.Application,
|
||||
Mobilizon.Factory,
|
||||
Mobilizon.Mailer,
|
||||
Mobilizon.Email.Mailer,
|
||||
Mobilizon.EmailView,
|
||||
Mobilizon.Email.User
|
||||
]
|
||||
|
@ -5,7 +5,7 @@
|
||||
# Inside the script, you can read and write to any of your
|
||||
# repositories directly:
|
||||
#
|
||||
# Mobilizon.Repo.insert!(%Mobilizon.SomeSchema{})
|
||||
# Mobilizon.Storage.Repo.insert!(%Mobilizon.SomeSchema{})
|
||||
#
|
||||
# We recommend using the bang functions (`insert!`, `update!`
|
||||
# and so on) as they will fail if something goes wrong.
|
||||
|
@ -26,10 +26,10 @@ defmodule MobilizonWeb.ChannelCase do
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Mobilizon.Repo)
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Mobilizon.Storage.Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Mobilizon.Repo, {:shared, self()})
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Mobilizon.Storage.Repo, {:shared, self()})
|
||||
end
|
||||
|
||||
:ok
|
||||
|
@ -35,10 +35,10 @@ defmodule MobilizonWeb.ConnCase do
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Mobilizon.Repo)
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Mobilizon.Storage.Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Mobilizon.Repo, {:shared, self()})
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Mobilizon.Storage.Repo, {:shared, self()})
|
||||
end
|
||||
|
||||
{:ok, conn: Phoenix.ConnTest.build_conn()}
|
||||
|
@ -18,7 +18,7 @@ defmodule Mobilizon.DataCase do
|
||||
|
||||
using do
|
||||
quote do
|
||||
alias Mobilizon.Repo
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
import Ecto
|
||||
import Ecto.Changeset
|
||||
@ -28,10 +28,10 @@ defmodule Mobilizon.DataCase do
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Mobilizon.Repo)
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Mobilizon.Storage.Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Mobilizon.Repo, {:shared, self()})
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Mobilizon.Storage.Repo, {:shared, self()})
|
||||
end
|
||||
|
||||
:ok
|
||||
|
@ -3,7 +3,7 @@ defmodule Mobilizon.Factory do
|
||||
Factory for fixtures with ExMachina
|
||||
"""
|
||||
# with Ecto
|
||||
use ExMachina.Ecto, repo: Mobilizon.Repo
|
||||
use ExMachina.Ecto, repo: Mobilizon.Storage.Repo
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias MobilizonWeb.Router.Helpers, as: Routes
|
||||
alias MobilizonWeb.Endpoint
|
||||
|
@ -3,4 +3,4 @@ ExUnit.configure(formatters: [ExUnit.CLIFormatter, ExUnitNotifier])
|
||||
|
||||
ExUnit.start()
|
||||
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Mobilizon.Repo, :manual)
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Mobilizon.Storage.Repo, :manual)
|
||||
|
Loading…
Reference in New Issue
Block a user