diff --git a/migrations/1735033489808-create-todo.js b/migrations/1735033489808-create-todo.js new file mode 100644 index 0000000..b6b3ff6 --- /dev/null +++ b/migrations/1735033489808-create-todo.js @@ -0,0 +1,28 @@ +'use strict'; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.createTable('todos', { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + created_at: { + allowNull: false, + type: Sequelize.DATE, + defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') + }, + updated_at: { + allowNull: false, + type: Sequelize.DATE, + defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') + } + }); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.dropTable('todos'); + } +}; \ No newline at end of file diff --git a/models/todo.js b/models/todo.js new file mode 100644 index 0000000..342909b --- /dev/null +++ b/models/todo.js @@ -0,0 +1,33 @@ +const { Model, DataTypes } = require('sequelize'); + +module.exports = (sequelize) => { + class Todo extends Model {} + + Todo.init({ + id: { + type: DataTypes.INTEGER, + allowNull: false, + primaryKey: true, + autoIncrement: true + }, + created_at: { + type: DataTypes.DATE, + allowNull: false, + defaultValue: DataTypes.NOW + }, + updated_at: { + type: DataTypes.DATE, + allowNull: false, + defaultValue: DataTypes.NOW + } + }, { + sequelize, + modelName: 'Todo', + tableName: 'todos', + timestamps: true, + createdAt: 'created_at', + updatedAt: 'updated_at' + }); + + return Todo; +}; \ No newline at end of file