![]() This lets us do on-the-fly data migration from older versions. It's easy to create this in our migration: Let's see what it would look like for our GameSave to use a :map field. The Ecto.Schema docs on the :map field type are very helpful if you plan to go in this direction. Other databases will vary, so we need to understand how it works in our particular database. In Postgres, this is stored as a jsonb field. The easiest and first thought might be to use an Ecto :map field type. How can we do this using Postgres and Ecto? Path One: Store Data as a map The structure and details of the GameData are defined by the game itself. For example, our saved Tic-Tac-Toe game will be stored very differently from a chess game or a memory game. It looks something like this:Įvery game needs to store its data in a different way. Instead of creating a table for each game type, we created a single table that records a saved game of any game type. We are continually adding new games and occasionally retiring old ones that didn't catch on. ![]() We didn't want to create a database table for every type of game that could be saved. The games can be saved in various states of play and be resumed later. In our scenario, we have a service that offers many games that members can play. Let's talk about the kind of data being stored. If you are familiar with Robert Frost's poem The Road Not Taken, then you may know that it's actually about indecision, the desire to take both paths because deciding things can be scary! In this article, we will venture a little way down each path before finally deciding which to take.īefore we discuss the choice of paths, we need to cover the problem being solved. This article is intended to be a sign posted at the fork in the road to let travelers know a bit more about what lies beyond in the paths before them.īoth in life and in programming, we can be presented with a choice of two directions to go. This choice doesn't come along that often for me and I had to re-discover the pros and cons for each option. Recently I was confronted with this choice again. This article explores two paths and discusses some of the pros and cons for each approach. ![]() When the data is stored using Ecto there are several ways we can do it. Your Elixir app could be one of them! Check us out: you can deploy in minutes.Įver wanted to store a blob of custom data on a database record? The data we want to store might be complex too, made up of multiple fields and even lists. 12 min Share this post on Twitter Share this post on Hacker News Share this post on Reddit Exploring Options for Storing Custom Data in Ecto Author Name Mark Ericksen Social Media View Twitter Profile Image by Annie Ruygtįly.io runs applications by transmogrifying Docker containers into Firecracker micro-VMs running on our hardware around the world, connected with WireGuard to a global Anycast network. ![]()
0 Comments
Leave a Reply. |