When a user has a game in progress and leaves the page, the only way for them to get back to the game session is by knowing the game session link. I want to add a list of active game sessions to a user’s root login page. I add a feature test for the case when user has no games in progress. This test already passes since I haven’t updated the HTML template yet.

Stash State Cleanup

- 1 min read
When game processes recover stashed game state from the CRDT store, the state is not removed. This is not ideal as this stash will continue to grow over time and use up memory. I need to make a simple change to clean up stashed state once it’s been handed off to a new process. I add a new test case to assert the desired behavior. describe "pickup/1 when state is stashed for key" do setup [:stash_state] test "should return stashed value", ctx do assert ctx.
I have a few LiveView pages used to inspect games in progress which are currently available to all users. I want to protect these routes so only users designated as admin have access. If an unauthenticated or unauthorized user visits an admin route, I want to return a 404 to not acknowledge the route even exists. I first write a test that I know will fail since I haven’t written the code for the desired behavior.
Create table migration It’s time to implement database-backed persistence for Minotaur user records. I generate a migration file with mix ecto.gen.migration add_users_table and update the change callback with the logic generated by phx.gen.auth in my demo auth project. defmodule Minotaur.Repo.Migrations.AddUsersTable do use Ecto.Migration def change do execute "CREATE EXTENSION IF NOT EXISTS citext", "" create table(:users) do add :email, :citext, null: false add :hashed_password, :string, null: false add :username, :string, null: false timestamps(type: :utc_datetime) end create unique_index(:users, [:email]) create unique_index(:users, [:username]) end end I run the migration locally for dev and test environments which complete successfully.
I continue to implement the new authentication live views based on the generated files from running mix phx.gen.auth in a demo project. I need to update the create function in UserSesssionController to authenticate with email instead of username, but this function is used by the existing login page. I rename the existing create function to create_with_username which will be a temporary change until the old login page can be deleted. I add a new create function which is an alias of the original.
I’m looking through the files generated by mix phx.gen.auth and see the entire browser interface for authentication uses live views except for the session management which can’t be done with web sockets alone. The current authentication system for Minotaur uses controllers and “dead” views for all pages. I will copy the generated live views to my application to replace the existing authentication interface. I start with the registration live view by copying the first test case from the generated user_registration_live_test.
Ecto is configured, but I don’t have any records that are stored in a database. User records are currently stored in memory so every deployment will dump the user store. These ephemeral records will be the first to be migrated to database persistence. Phoenix comes with a generator for creating an initial authentication system complete with web forms, session tokens, and an Ecto migration file. Since I already have an existing authentication system, I create a separate Phoenix application (mix phx.
Migrations with Elixir Releases Since I’m using releases for the production environment, I won’t have the Mix tool to run migrations. I didn’t have Ecto included with my original Phoenix project so the files generated for releases did not include anything for running Ecto migrations from a release. I generate these missing migration files by running mix phx.gen.release again which adds the Minotaur.Release module and a migrate script. # lib/minotaur/release.ex defmodule Minotaur.
Troubleshooting Postgrex My container application is not connecting to PostgreSQL on the host machine. To troubleshoot the issue, I want to rule out some variables such as the container networking. I add postgresql-client to the Dockerfile and build a new temporary image for troubleshooting. I launch a container with this new image and attempt to connect to the PostgreSQL server: $ docker run -it --entrypoint /bin/bash --add-host=host.docker.internal:host-gateway minotaur:tmp $ psql -h host.
I’ve added Ecto to my Minotaur project and confirmed it works locally in development and test environments. I have a production PostgreSQL server running on the same VPS that runs Minotaur in Docker Swarm. I want to merge the latest code changes to ensure the Repo module is starting correctly in production. Running containers outside of Swarm I connect to my VPS and pull the latest changes from the main branch and build a new Docker image tagged as minotaur:ecto.