Versioning v0.2.0 Versioning View Source
Versionings allow data to be manipulated to different versions of itself.
A the heart of our versioning is the Versioning
struct. A Versioning
struct
contains the following fields:
:current
- The current version that our data represents.:target
- The version that we want our data to be changed into.:type
- The type of data we are working with. If we are working with structs, this will typically be the struct name, eg:Post
:data
- The underlying data that we want to change. For structs, like ourPost
, be aware that we typically have our data as a bare map since it is easier to transform.:changed
- A boolean representing whether a change operation has occured.:assigns
- A map of arbitrary data we can use to store additonal information in.
Example
Versioning.new(%Post{}, "2.0.0", "1.0.0")
With the above, we have created a versioning of a Post
struct. This represents
us wanting to transform our post from a version “2.0.0” to an older “1.0.0”
version.
Schemas
The versioning struct is used in combination with a Versioning.Schema
, which
allows us to map out the changes that should occur through versions. Please see
the Versioning.Schema
documentation for more details.
Link to this section Summary
Functions
Assigns a value to a key in the versioning
Creates a new versioning using the data provided
Returns and removes the value associated with key
within the data
of versioning
Puts the current version that the data represents
Puts the full data in the versioning
Puts the given value
under key
within the data
of versioning
Puts the target version that the data will be transformed to
Puts the type of the versioning data
Link to this section Types
Link to this section Functions
assign(Versioning.t(), atom(), any()) :: Versioning.t()
Assigns a value to a key in the versioning.
The “assigns” storage is meant to be used to store values in the versioning so that change modules in your schema can access them. The assigns storage is a map.
Examples
iex> versioning.assigns[:hello]
nil
iex> versioning = Versioning.assign(versioning, :hello, :world)
iex> versioning.assigns[:hello]
:world
Creates a new versioning using the data provided.
If a struct is the data, and no type is provided, the struct module is set as
the versioning :type
, and the struct is turned into a map that is used for
the :data
.
Examples
Versioning.new(%{}, "2.0.0", "1.0.0", SomeData)
Versioning.new(%SomeData{}, "2.0.0", "1.0.0")
Returns and removes the value associated with key
within the data
of versioning
.
If key
is present in data
with value value
, {value, new_versioning}
is
returned where new_versioning
is the result of removing key
from data
. If key
is not present in data
, {default, new_versioning}
is returned.
Examples
iex> Versioning.pop_data(versioning, :a)
{1, versioning}
iex> Versioning.pop_data(versioning, :a)
{nil, versioning}
Puts the current version that the data represents.
The version should be represented somewhere within your Versioning.Schema
.
This will become the “starting” point from which change modules will be run.
Examples
Versioning.put_current(versioning, "0.1.0")
put_data(Versioning.t(), map()) :: Versioning.t()
Puts the full data in the versioning.
The data represents what will be modified when a versioning is run through a schema.
Data must be a map. If a struct is provided, the struct will be turned into a basic map - though its type information will not be inferred.
Examples
iex> versioning = Versioning.put_data(versioning, %{foo: :bar})
iex> versioning.data
%{foo: :bar}
put_data(Versioning.t(), atom(), any()) :: Versioning.t()
Puts the given value
under key
within the data
of versioning
.
Examples
iex> Versioning.put_data(versioning, :a, 1)
iex> versioning.data.a
1
put_target(Versioning.t(), version()) :: Versioning.t()
Puts the target version that the data will be transformed to.
The version should be represented somewhere within your Versioning.Schema
.
Once the change modules in the target version are run, no more changes will
be made.
Examples
Versioning.put_target(versioning, "0.1.0")
put_type(Versioning.t(), type()) :: Versioning.t()
Puts the type of the versioning data.
Typically, if working with data that is associated with a struct, this will be the struct module name.
When running a versioning through a schema, only the changes that match the type set on the versioning will be run.
Examples
Versioning.put_type(versioning, Article)