GithubHelp home page GithubHelp logo

cristhianrodriguezmolina / seedex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from danhper/seedex

0.0 0.0 0.0 24 KB

Seed data generation for Ecto

Home Page: https://hex.pm/packages/seedex

License: MIT License

Elixir 100.00%

seedex's Introduction

Seedex

Build Status Hex.pm

Seedex is a library for Ecto to easily populate your DB with seed data. It is useful, for example, if you have some master data you need to insert in your database.

This is not meant to generate data for your tests, if this is what you need, checkout ecto_fixtures or ex_machina instead.

Installation

Add seedex to your list of dependencies in mix.exs:

def deps do
  [{:seedex, "~> 0.3.0"}]
end

Usage

First, you need to configure seedex to use your repository:

config :seedex,
  repo: YourApp.Repo,
  seeds_path: "priv/repo/seeds" # not required, but can be used to customize seeds path

Then, you just need to add files under the seeds_path, which defaults to priv/repo/seeds. All files matching seeds_path/*.exs and seeds_path/MIX_ENV/*.exs if it exists will be read. To insert the data, you need to run

mix seedex.seed

Files are loaded in alphabetic order, independently of the directory they are in. However, the files are really just plain Elixir with nothing special, so you could just use mix run priv/repo/seeds/my_seed.exs, if you needed to.

Sample seed file

Here is what a seed file looks like:

import Seedex

seed_once Group, fn group ->
  group
  |> Map.put(:id, 1)
  |> Map.put(:name, "admin")
end

seed Group, fn group ->
  %{group | id: 2, name: "user"}
end

seed User, [:name], [
  %{name: "Daniel", age: 26, group_id: 1},
  %{name: "Ai", age: 24, group_id: 2},
]

Checkout the documentation for more info.

seedex's People

Contributors

danhper avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.