Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
ah-sequelize-plugin
Advanced tools
This plugin will use the sequelize orm to create api.models
which contain your sequelize models
npm install ah-sequelize-plugin --save
config/plugins.js
)npm install sequelize --save
) to your package.jsonnpm install sequelize-fixtures --save
) to your package.jsonnpm install mysql --save
) to your package.json
npm install sequelize-cli
) to your package.json
npm install -g sequelize-cli
)A ./config/sequelize.js
file will be created which will store your database configuration
Use the exports form of sequelize models in ./models
with the file name matching that of the model, IE:
module.exports = function(sequelize, DataTypes) {
return sequelize.define("Project", {
name: DataTypes.STRING,
description: DataTypes.TEXT
})
}
Models are loaded into api.models
, so the example above would be api.models.Project
.
This plugin does not condone the use of Sequelize.sync()
in favor of migrations. Keep you migrations in ./migrations
and use the sequelize-cli to execute them.
An example migration to create a users
table would look like:
// from ./migrations/20140101000001-create-users.js
module.exports = {
up: function(migration, DataTypes, done) {
migration.createTable('users', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: DataTypes.STRING,
email: DataTypes.STRING,
phone: DataTypes.STRING,
passwordHash: DataTypes.TEXT,
passwordSalt: DataTypes.TEXT,
createdAt: DataTypes.DATE
updatedAt: DataTypes.DATE
}).complete(function(){
migration.addIndex('users', ['email'], {
indexName: 'email_index',
indicesType: 'UNIQUE'
}).complete(function(){
migration.addIndex('users', ['name'], {
indexName: 'name_index',
indicesType: 'UNIQUE'
}).complete(function(){
migration.addIndex('users', ['phone'], {
indexName: 'phone_index',
indicesType: 'UNIQUE'
}).complete(function(){
done();
});
});
});
});
},
down: function(migration, DataTypes, done) {
migration.dropTable('users').complete(done);
}
}
You can use the sequelize-cli to create and execute migrations.
Using the migrator
class on api.sequelize
is deprecated, as Sequelize
now recommends using Umzug to manage database schemas.
If you want to sync, you can api.sequelize.sync()
or api.models.yourModel.sync()
;
By default, ah-sequelize-plugin
will automatically execute any pending migrations when Actionhero starts up. You can disable this behaviour by adding autoMigrate: false
to your sequelize config.
If you want to declare associations, best practice has you create an associations.js
initializer within your project which might look like this:
module.exports = {
loadPriority: 1000,
startPriority: 1002, // priority has to be after models have been loaded
stopPriority: 1000,
associations: {},
initialize: function (api, next) {
next();
},
start: function (api, next) {
api.models.user.hasMany(api.models.posts);
api.models.posts.hasMany(api.models.comments);
api.models.comments.belongsTo(api.models.posts);
api.models.posts.belongsTo(api.models.user);
next();
},
stop: function (api, next) {
next();
}
};
We use the sequelize-fixtures
package to load in JSON-defined fixtures in the test NODE_ENV. Store your fixtures in ./test/fixtures/*.json
or ./test/fixtures/*.yml
.
By default, ah-sequelize-plugin
will not automatically load your fixtures when Actionhero starts up. You can enable this behaviour by adding loadFixtures: true
to your sequelize config.
FAQs
Use Sequelize in ActionHero
The npm package ah-sequelize-plugin receives a total of 1,228 weekly downloads. As such, ah-sequelize-plugin popularity was classified as popular.
We found that ah-sequelize-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.