Skip to content

Commit

Permalink
chore: sequelize migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadlaiq committed Apr 18, 2024
1 parent 857ada9 commit b6b300f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
33 changes: 33 additions & 0 deletions migrations/20240418022931-create-category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('Categories', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING,
allowNull: false,
unique: true
},
description: {
type: Sequelize.TEXT
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('Categories');
}
};
24 changes: 24 additions & 0 deletions models/category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Category extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
}
}
Category.init({
name: DataTypes.STRING,
description: DataTypes.TEXT
}, {
sequelize,
modelName: 'Category',
});
return Category;
};

0 comments on commit b6b300f

Please sign in to comment.