gooseberry
TypeScript icon, indicating that this package has built-in type declarations

0.1.7 • Public • Published

oclif Version Downloads/week License

Setup

Install via yarn or npm

yarn add gooseberry
OR
npm install gooseberry

Create a gooseberry config in package.json

{
  //...,
  "gooseberry": {
    "modelDir": "path/to/mongooseModels",
    "mongoURI": "mongodb://localhost:27017/{TARGET_DB_NAME}",
    "dataDir": "path/to/seedData",
    "dropDatabase": true (optional)
  }
}

Create a data file for each collection you want to seed

Data files can be written in json, yaml, ts or js but must return an array of data.

// seeds/users.json
[{
  "_id": "Jane",
  "firstName": "Jane",
  "lastName": "Doe"
}]
// seeds/posts.json
[{
  "title": "My new post",
  "author": "Jane" // use _id from seeded user
}]

_Note: if you don't specify an id or id field, gooseberry will assign it a smartID based on collection name and position in array. (e.g. above example will have post1 as its ID)

Gooseberry will recursively transform these into ObjectIDs

// seeds/users.json
[{
  "_id": ObjectID("5d6e80622037da89a22195f7"),
  "firstName": "Jane",
  "lastName": "Doe"
}]
// seeds/posts.json
[{
  "_id": ObjectID("5d6e80622037da89a22195f8"),
  "title": "My new post",
  "author": ObjectID("5d6e80622037da89a22195f7")
}]

Development

This package is new and under active development. PRs are welcome.

Check the 1.0 Roadmap for more.

Methodology

Gooseberry uses placeholder IDs to reference raw seeding data. It makes 2 passes over the data first to setup the initial data and assign IDs and then to replace the placeholder IDs with the real IDs based on your mongoose schemae.

The transformed data is then fed to mongoose.create as per usual running the validation and methods.

Usage

$ npm install -g gooseberry
$ gooseberry COMMAND
running command...
$ gooseberry (-v|--version|version)
gooseberry/0.1.7 darwin-x64 node-v12.11.1
$ gooseberry --help [COMMAND]
USAGE
  $ gooseberry COMMAND
...

Commands

gooseberry help [COMMAND]

display help for gooseberry

USAGE
  $ gooseberry help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

See code: @oclif/plugin-help

gooseberry seed

describe the command here

USAGE
  $ gooseberry seed

OPTIONS
  -h, --help     show CLI help
  -v, --verbose

EXAMPLES
  $ gooseberry seed
  $ gooseberry seed [collection]

See code: src/commands/seed.ts

Credits

The brilliant idea for the smart IDs comes from seedgoose. Gooseberry builds on that idea and adds mongoose validation et al. to that idea.

Readme

Keywords

none

Package Sidebar

Install

npm i gooseberry

Weekly Downloads

8

Version

0.1.7

License

MIT

Unpacked Size

31.5 kB

Total Files

47

Last publish

Collaborators

  • hennessyevan