summaryrefslogtreecommitdiff
path: root/lib/chessh/schema/node.ex
diff options
context:
space:
mode:
authorSimponic <loganhunt@simponic.xyz>2022-12-29 17:21:20 -0700
committerSimponic <loganhunt@simponic.xyz>2022-12-29 17:21:20 -0700
commit1a2bdccf124de6207899f59538cc0ed2efc97b5a (patch)
tree5b582023531c8df637881899ab64d5f5eddd7f3f /lib/chessh/schema/node.ex
parent10bc34245e8e1e3ba63fb0720d3bcfb1119db921 (diff)
downloadchessh-1a2bdccf124de6207899f59538cc0ed2efc97b5a.tar.gz
chessh-1a2bdccf124de6207899f59538cc0ed2efc97b5a.zip
Add scalable nodes and user sessions
Diffstat (limited to 'lib/chessh/schema/node.ex')
-rw-r--r--lib/chessh/schema/node.ex24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/chessh/schema/node.ex b/lib/chessh/schema/node.ex
new file mode 100644
index 0000000..867a6e2
--- /dev/null
+++ b/lib/chessh/schema/node.ex
@@ -0,0 +1,24 @@
+defmodule Chessh.Node do
+ alias Chessh.Repo
+ import Ecto.Changeset
+ use Ecto.Schema
+
+ @primary_key {:id, :string, []}
+ schema "nodes" do
+ field(:last_start, :utc_datetime)
+ end
+
+ def changeset(node, attrs) do
+ node
+ |> cast(attrs, [:last_start])
+ end
+
+ def boot(node_id) do
+ case Repo.get(Chessh.Node, node_id) do
+ nil -> %Chessh.Node{id: node_id}
+ node -> node
+ end
+ |> Chessh.Node.changeset(%{last_start: DateTime.utc_now()})
+ |> Repo.insert_or_update()
+ end
+end