question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for seeding a database

See original GitHub issue

I am opening this ticket as a place for discussion around possible ways to implement command line seed support (ala rails db:seed) This need is coming up in a few tickets #58 #48.

So to start, in my situation I was porting an older small app of mine that was backed by mongo. I have a command line node tool to pump in seed data when I stood up new instances. During my port to nodal, which I was doing as a public example of a nodal app, I really wanted a single db cli command (see #50) to prepare, migrate and seed the sample data so that someone could fork the repo and use the built in deploy to heroku button and have a running app with real data

So my first thought is do we have a large json doc that can be used to seed models (like schema.json) or do we actually generate a real module that can be required and run to allow for model validations, model relations etc (ala rails)

so for a quick and dirty comparison of the thoughts (excuse errors, thinking as a I go here)

a seed.json (which has to have proper ordering)

{
  "user": {
    "id": 1,
    "username": "mark",
    "email": "mlussier@gmail.com"
  },
  "tweet": {
    "id": 1,
    "body": "Hey There",
    "user_id": 1
  }
}

or in js (remember, just a rough idea)

  'use strict';

  const Nodal = require('nodal');
  const User = Nodal.require('app/models/user.js');
  const Tweet = Nodal.require('app/models/user.js');

  let markUser;
  User.create({ username: "mark", email: "mlussier@gmail.com"}, (err, model) => {
    markUser = model;
  });

  Tweet.create({ body: "Hey There", user_id: markUser.id}, (err, model) => {

  });

or even

  'use strict';

  const Nodal = require('nodal');
  const User = Nodal.require('app/models/user.js');
  const Tweet = Nodal.require('app/models/user.js');

  User.create({ username: "mark", email: "mlussier@gmail.com"}, (err, model) => {

      Tweet.create({ body: "Hey There", user_id: model.id}, (err, model) => {
      });

  });

Okay seed (no pun intended) laid, thoughts?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
intabulascommented, Jan 11, 2016

Was thinking in the shower it would be good to either have the seed.json support env’s (like db.json)

{
  "development": {
    "User": [
    ]
  },
  "production": {
    "User": [
    ]
  }
}

or if we want to be crazy, make the seed a js file so that we can do nutty stuff like generating fake test data

"use strict";

let faker = require('faker');

module.exports = {
  development: {
  },
  production: {  
  },

  test: { 
    "User": function() {
      let data = []
      for(let i = 0, i < 30, i++) {
        data.push({ name: faker.name.findName()});
      }
      return data;  

    }
  }
};

obviously that js example could be way better, but it illustrates…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Seeding your database - Prisma
This guide describes how to seed your database using Prisma Client and Prisma's integrated seeding functionality. Seeding allows you to consistently ...
Read more >
Applying Seed Data To The Database
Seed data is data that you populate the database with at the time it is created. You use seeding to provide initial values...
Read more >
Data Seeding - EF Core - Microsoft Learn
Using data seeding to populate a database with an initial set of data using Entity Framework Core.
Read more >
Database: Seeding - The PHP Framework For Web Artisans
This method is called when the db:seed Artisan command is executed. Within the run method, you may insert data into your database however...
Read more >
Add support for seeding the database with test data #259
I can see there being a seed data file for every migration file. The migration updates the structure, or adds new structure, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found