Giter Club home page Giter Club logo

Comments (3)

KSDaemon avatar KSDaemon commented on May 27, 2024

Well, actually i'm planning to have tests agains sqlite too :)
One reason for using PostgreSQL is that it has schemas, which is not available in other DBs. So to have tests against migrating and creating schemas — we use PostgreSQL

from sails-hook-sequelize.

mrded avatar mrded commented on May 27, 2024

I see. I can explain how do I do that with mysql. Hopefully it will help you implementing it.

I have a db/migrations/1234567890-init-models.js file to init all database tables from models:

var glob = require('glob');
var path = require('path');
var models = {};

glob.sync('./api/models/*.js').forEach(function(file) {
  var modelName = path.basename(file, '.js');
  var model = require(path.resolve(file));

  models[modelName] = model;
});

module.exports = {
  up: function(queryInterface, Sequelize) {
    var Project = queryInterface.sequelize;

    for (var modelName in models) {
      Project.define(modelName, models[modelName].attributes, models[modelName].options);
    }

    return Project.sync({force: true});
  },
};

Then I have pretest in package.json like following sequelize db:drop; sequelize db:create; sequelize db:migrate to init database.

Then before each test case I truncate all tables:

beforeEach(function(done) {
  var models = Object.keys(sails.models).map(function(key) {
    return sails.models[key];
  }); 

  var destroyPromises = models.map(function(model) {
    return model.destroy({ truncate: true });
  });

  Promise.all(destroyPromises).then(function() {
    done();
  }).catch(done);
});

from sails-hook-sequelize.

KSDaemon avatar KSDaemon commented on May 27, 2024

I've added some tests against sqlite db. It was helpful to test some cases.

from sails-hook-sequelize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.