All Projects → codica2 → rails-multi-environment-seeding

codica2 / rails-multi-environment-seeding

Licence: other
Example of using seeds in rails app

Labels

Projects that are alternatives of or similar to rails-multi-environment-seeding

Generator Ngx Rocket
🚀 Extensible Angular 11+ enterprise-grade project generator
Stars: ✭ 1,329 (+10123.08%)
Mutual labels:  seed
Gofakeit
Random fake data generator written in go
Stars: ✭ 2,193 (+16769.23%)
Mutual labels:  seed
Angular Library Seed
🌾 Seed project for Angular libraries that are AOT/JIT compatible and that use external SCSS-styles and HTML-templates
Stars: ✭ 197 (+1415.38%)
Mutual labels:  seed
Awesome Seed Rs
A curated list of awesome things related to Seed
Stars: ✭ 101 (+676.92%)
Mutual labels:  seed
Fusebox Angular Universal Starter
Angular Universal seed project featuring Server-Side Rendering, @fuse-box bundling, material, firebase, Jest, Nightmare, and more
Stars: ✭ 132 (+915.38%)
Mutual labels:  seed
Express Typescript Boilerplate
A delightful way to building a RESTful API with NodeJs & TypeScript by @w3tecch
Stars: ✭ 2,293 (+17538.46%)
Mutual labels:  seed
Hdwallet
Simple Swift library for creating HD cryptocurrencies wallets and working with crypto Coins/ERC20 tokens.
Stars: ✭ 80 (+515.38%)
Mutual labels:  seed
Electron React Webpack
Electron + React 16 + Webpack 4 template with ES6, JSX and hot reloading.
Stars: ✭ 231 (+1676.92%)
Mutual labels:  seed
Generator Jekyll Starter Kit
🚀 Jekyll Progressive Web App Generator.
Stars: ✭ 139 (+969.23%)
Mutual labels:  seed
Go Ethereum Hdwallet
Ethereum HD Wallet derivations in Go (golang)
Stars: ✭ 178 (+1269.23%)
Mutual labels:  seed
Angular Seed Express
[DEPRECATED, Please use https://github.com/vyakymenko/angular-express] Extensible, reliable and modular starter project for Angular 7 with statically typed build AoT compilation, Express server and PM2 Daemon.
Stars: ✭ 107 (+723.08%)
Mutual labels:  seed
Angular Electron Seed
An Angular (4+) seed with Electron, Live-reload, AngularCLI, etc.
Stars: ✭ 118 (+807.69%)
Mutual labels:  seed
Seedsearcherstandalonetool
Minecraft, searching numeric seeds for specific features/biomes
Stars: ✭ 165 (+1169.23%)
Mutual labels:  seed
Seed Labs
SEED Labs developed in the last 20 years.
Stars: ✭ 102 (+684.62%)
Mutual labels:  seed
Angular Seed Advanced
Advanced Angular seed project with support for ngrx/store, ngrx/effects, ngx-translate, angulartics2, lodash, NativeScript (*native* mobile), Electron (Mac, Windows and Linux desktop) and more.
Stars: ✭ 2,279 (+17430.77%)
Mutual labels:  seed
Reactjs Crud Boilerplate
Live Demo
Stars: ✭ 83 (+538.46%)
Mutual labels:  seed
Polluter
The easiest solution to seed database with Go
Stars: ✭ 146 (+1023.08%)
Mutual labels:  seed
jsrand
A seeded pseudo-random number generator for JavaScript.
Stars: ✭ 19 (+46.15%)
Mutual labels:  seed
Elm Examples
📖 Practical examples in Elm
Stars: ✭ 208 (+1500%)
Mutual labels:  seed
Tsmean
Typescript-mysql-express-angular-node seed for your next web-app!
Stars: ✭ 173 (+1230.77%)
Mutual labels:  seed

Seed examples

Seeding is a process when you automatically fill in a database with data. What's the business idea of this? Imagine that you have a lot of databases, and you have to fill each of them with your common initial data. It takes too much time resources to do it manually. Create Initial dump is not a good idea, because it is not agile. Seeding is a very helpful tool in this case.

File structure

Using SeedBank we can separate logic for production and development environments.

db/
  └── seeds/
    ├── development/
    |   └── *.seeds.rb
    ├── production/
    |   └── *.seeds.rb
    ├── seeds.rb
    └── modules/

Now you can run seeds in the scope of your environment; it's also a good idea to move common logic to modules and to include them to seeds files.

Development environment

Commonly for populating development DB we use Faker gem because in this case, we may ignore the data integrity.

  10.times do
    User.create(name: Faker::FunnyName.two_word_name, email: Faker::Internet.email, password: 'password')
  end

  10.times do
    category = Category.create(name: Faker::Coffee.variety)
    5.times do
      category.tags << Tag.create(name: Faker::Cat.name)
    end
  end

  100.times do
    Post.create!(title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph)
  end

Production environment

For production mode you need real data, we store them in CSV files on Google Docs and follow common structure for them

CSV file example

In a Header, we write attributes names, and each row is an object with attribute values. In this case, it is really easy to add, remove or change data.

    def categories
      file = 'path_to_categories_csv'
      Category.create(extracted_params(file))
    end

    def brands
      file = 'path_to_brands_csv'
      Brand.create(extracted_params(file))
    end

And inside of our extracted_params method we will parse CSV and create an array with params.

  def extracted_params(file)
    parsed_csv(file).map { |row| row.to_h }
  end

  def parsed_csv(file)
    data_csv = URI.open(file).read
    CSV.parse(data_csv, headers: true)
  end

Now we have DB with all the necessary data.

Useful Gems

SeedBank - Seedbank gives your seed data a little structure. Create seeds for each environment, share seeds between environments and specify dependencies to load your seeds in order.

Faker gem - A library for generating fake data such as names, addresses, and phone numbers

Seed Dump - It allows you to create seed data files from the existing data in your database

seed-fu - Advanced seed data handling for Rails, combining the best practices of several methods together

License

rails-multi-environment-seeding is Copyright © 2015-2019 Codica. It is released under the MIT License.

About Codica

Codica logo

We love open source software! See our other projects or hire us to design, develop, and grow your product.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].