package sihl
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=49fe887d05083b37523cd6e7ca35239822c561fe7109dd383c30aeb4259a7b98
sha512=4135ad42a75fb9adc3e853a466b696d9ee6d7a9d8acf0cee9fd5f5485679a517f524ce704e2d153df4a7c4f1d14df9f94ab2a8fbe5b36e744b505daab1d40f3d
doc/sihl.seed/Seed/index.html
Module Seed
Source
A seed is a sequence of service calls that set a system state. Seeds are typically used before integration testing to set the initial state.
Introduction
A seed is a function that takes a Core.Ctx.t
and returns unit Lwt.t
. It has also a name that identifies it uniquely. This means, that no two seeds are allowed to have the same name.
Seeds can be used to set some system state. This can be useful for integration tests or to add data to a live system in a controlled way.
Many other seeding systems allow for export and import of pure data. Sihl's seeding system is just a function that does several service calls. One major advantage is, that there is no seed data that needs to be migrated and the seeding is statically typed. A disadvantage of this approach is, that seed data generation requires a Sihl app with services.
Installation
module Log = Sihl.Log.Service.Make ()
module Cmd = Sihl.Cmd.Service.Make ()
module Seed = Sihl.Seed.Service.Make (Log) (Cmd)
Usage
...
let dev_seed ctx = ... in
let seed =
Sihl.Seed.make ~name:"development"
~description:
"Seed minimal data so project can be tested locally"
~fn:dev_seed in
let () = Service.Seed.register_seed seed in
let* () = Service.Seed.run_seed ctx "development" in
...