grunt-sequelize-fixtures

Grunt task for loading some JSON fixtures with Sequelize

grunt-sequelize-fixtures

Grunt task for loading some JSON fixtures with Sequelize

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.loadNpmTasks('grunt-sequelize-fixtures');

In your project's Gruntfile, add a section named sequelize_fixtures to the data object passed into grunt.initConfig().

grunt.initConfig({
  sequelize_fixtures: {
    options: {
      // Task-specific options go here. 
    },
    your_target: {
      // Target-specific file lists and/or options go here. 
    },
  },
});

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.

Type: Array Default value: []

The array of all the model names that should be loaded.

Type: Array Default value: []

The array of all the JSON files containing the fixtures.

grunt.initConfig({
    sequelize_fixtures: {
        options: {
            // Common options 
        },
        dev: {
            options: {
                dbfunction() { return require('./lib/models'); },
                models: ['Customer', 'Order'],
                files: [
                    require('path').join(__dirname, 'lib', 'fixtures', 'Customers.json'),
                    require('path').join(__dirname, 'lib', 'fixtures', 'Orders.json')
                ]
            }
        }
    }
})

If like me your Sequelize connection requires some ENV variables, create the following Grunt task at the end of your Gruntfile:

grunt.initConfig({
    ...
    grunt.registerTask('fixtures', function(target) {
            if (target == 'test') {
                    return grunt.task.run(['env:test', 'sequelize_fixtures:test']);
            }
            grunt.task.run(['env:dev', 'sequelize_fixtures:dev']);
        });
})

And then use the task grunt fixtures.

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.

(Nothing yet)