Reviewed-on: https://git.nikos.gg/prymn/prymn/pulls/9 Co-authored-by: Nikos Papadakis <nikos@papadakis.xyz> Co-committed-by: Nikos Papadakis <nikos@papadakis.xyz>
49 lines
1.3 KiB
Elixir
49 lines
1.3 KiB
Elixir
defmodule Prymn.Servers.Server do
|
|
@moduledoc false
|
|
|
|
use Ecto.Schema
|
|
import Ecto.Changeset
|
|
|
|
@typedoc """
|
|
A `Server` describes a server resource that was created in the application.
|
|
|
|
Its status can be one of:
|
|
|
|
- `:unregistered`: when the resource was just created and the `Prymn Agent`
|
|
is not yet installed or active.
|
|
- `:registered`: the Agent was installed, and now the resource MUST have a
|
|
`public_ip` that we can connect to.
|
|
"""
|
|
@type t :: %__MODULE__{
|
|
id: integer(),
|
|
name: String.t(),
|
|
public_ip: String.t(),
|
|
provider: term(),
|
|
registration_token: binary(),
|
|
status: term()
|
|
}
|
|
|
|
schema "servers" do
|
|
field :name, :string
|
|
field :public_ip, :string
|
|
field :provider, Ecto.Enum, values: [:Hetzner, :Custom]
|
|
field :registration_token, :binary, redact: true
|
|
|
|
field :status, Ecto.Enum,
|
|
values: [:unregistered, :registered],
|
|
default: :unregistered
|
|
|
|
has_many :apps, Prymn.Apps.App
|
|
|
|
timestamps()
|
|
end
|
|
|
|
@doc false
|
|
def changeset(server, attrs) do
|
|
server
|
|
|> cast(attrs, [:name, :public_ip, :provider, :registration_token, :status])
|
|
|> validate_required([:name, :provider])
|
|
|> validate_inclusion(:provider, [:Custom], message: "Provider not available (yet)")
|
|
|> unique_constraint([:public_ip])
|
|
end
|
|
end
|