grunt-sequelize-fixtures
Grunt task for loading some JSON fixtures with Sequelize
Getting Started
This plugin requires Grunt ~0.4.5
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-sequelize-fixtures --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt;
The "sequelize_fixtures" task
Overview
In your project's Gruntfile, add a section named sequelize_fixtures
to the data object passed into grunt.initConfig()
.
grunt;
Options
options.db
Type: Function
Default value: 'function() { return {}; }'
A function returning an object with all the Sequelize models as keys. This object is wrapped by a function to avoid problems caused by circular references when Grunt compiles the options. I used the pattern described here to autoload models with Sequelize.
options.models
Type: Array
Default value: []
The array of all the model names that should be loaded.
options.files
Type: Array
Default value: []
The array of all the JSON files containing the fixtures.
Usage Examples
Basic example
grunt
Combined with the "env" task
If like me your Sequelize connection requires some ENV variables, create the following Grunt task at the end of your Gruntfile:
grunt
And then use the task grunt fixtures
.
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Release History
(Nothing yet)