View Source DBCluster (DB Cluster v0.0.2)
DBCluster provides a database backed method of clustering your nodes. At startup, each node will query the database for other nodes and try to connect to them (while adding themselves to the database). In this manner you can add new nodes without having to update lists or use things like kubernetes.
Aside from the initial setup it is not expected you will need to interface with the DBCluster app, the majority of functions exported are related to querying the database table used by the app.
Installation
def deps do
[
{:db_cluster, "~> 0.0.1"}
]
end
Now add a migration
mix ecto.gen.migration add_db_cluster_tables
Open the generated migration and add the below code:
defmodule MyApp.Repo.Migrations.AddDBClusterTables do
use Ecto.Migration
def up do
DBCluster.Migration.up()
end
# We specify `version: 1` in `down`, ensuring that we'll roll all the way back down if
# necessary, regardless of which version we've migrated `up` to.
def down do
DBCluster.Migration.down(version: 1)
end
end
Finally, update your config to link the repo:
config :db_cluster,
repo: MyApp.Repo
Summary
Functions
@spec change_cluster_member(ClusterMember.t(), map()) :: Ecto.Changeset.t()
@spec create_cluster_member(map()) :: {:ok, ClusterMember.t()} | {:error, Ecto.Changeset.t()}
@spec delete_cluster_member(ClusterMember.t()) :: {:ok, ClusterMember.t()} | {:error, Ecto.Changeset.t()}
@spec get_cluster_member(Teiserver.cluster_member_id()) :: ClusterMember.t() | nil
@spec get_cluster_member!(Teiserver.cluster_member_id()) :: ClusterMember.t()
@spec list_cluster_members(list()) :: [ClusterMember.t()]
@spec update_cluster_member(ClusterMember, map()) :: {:ok, ClusterMember.t()} | {:error, Ecto.Changeset.t()}