zoukankan      html  css  js  c++  java
  • Node+TS+Koa+vue 商城全栈(三) sequelize 创建种子文件

    1.用户表种子文件(示例):

    seeders/20200204173530-user.js

    const md5 = require('md5');
    const moment = require('moment');
    
    module.exports = {
      up: (queryInterface, Sequelize) => {
        /*
          Add altering commands here.
          Return a promise to correctly handle asynchronicity.
    
          Example:
          return queryInterface.bulkInert('Person', [{
            name: 'John Doe',
            isBetaMember: false
          }], {});
        */
        return queryInterface.bulkInsert('user', [
          {
            id: 1,
            username: 'mt',
            password: md5('123456'),
            disabled: false,
            mobile: '13000000000',
            email: 'mt@meishi.com',
            created_ip_at: '127.0.0.1',
            updated_ip_at: '127.0.0.1',
            created_at: moment().format('YYYY-MM-DD HH:mm:ss'),
            updated_at: moment().format('YYYY-MM-DD HH:mm:ss')
          },
          {
            id: 2,
            username: 'zmouse',
            password: md5('123456'),
            disabled: false,
            mobile: '13000000000',
            email: 'zmouse@meishi.com',
            created_ip_at: '127.0.0.1',
            updated_ip_at: '127.0.0.1',
            created_at: moment().format('YYYY-MM-DD HH:mm:ss'),
            updated_at: moment().format('YYYY-MM-DD HH:mm:ss')
          },
          {
            id: 3,
            username: 'reci',
            password: md5('123456'),
            disabled: false,
            mobile: '13000000000',
            email: 'reci@meishi.com',
            created_ip_at: '127.0.0.1',
            updated_ip_at: '127.0.0.1',
            created_at: moment().format('YYYY-MM-DD HH:mm:ss'),
            updated_at: moment().format('YYYY-MM-DD HH:mm:ss')
          },
          {
            id: 4,
            username: 'kimoo',
            password: md5('123456'),
            disabled: false,
            mobile: '13000000000',
            email: 'kimoo@meishi.com',
            created_ip_at: '127.0.0.1',
            updated_ip_at: '127.0.0.1',
            created_at: moment().format('YYYY-MM-DD HH:mm:ss'),
            updated_at: moment().format('YYYY-MM-DD HH:mm:ss')
          }
        ]);
      },
    
      down: (queryInterface, Sequelize) => {
        /*
          Add reverting commands here.
          Return a promise to correctly handle asynchronicity.
    
          Example:
          return queryInterface.bulkDelete('Person', null, {});
        */
        return queryInterface.bulkDelete('user', null, {});
      }
    };
    
    根据种子文件添加数据
    . ode_modules.binsequelize db:seed:all
    根据种子文件清空数据
    . ode_modules.binsequelize db:seed:undo:all

    2.项目目录:

  • 相关阅读:
    这算什么?兴许是公告栏罢
    [考试总结]ZROI-21-NOIP冲刺-TEST1 总结
    [考试总结]ZROI-21-NOIP-CSP7连-DAY6 总结
    [考试总结]ZROI-21-十一集训-赠送赛 总结
    [考试总结]ZROI-21-CSP7连-DAY5 总结
    [考试总结]ZROI-21-CSP7连-DAY4 总结
    [考试总结]ZROI-21-CSP7连-EXTRA1 总结
    [考试总结]ZROI-21-CSP7连-DAY3 总结
    [题解]HDU6606 Distribution of books
    [题解]HDU6315 Naive Operations
  • 原文地址:https://www.cnblogs.com/crazycode2/p/12238412.html
Copyright © 2011-2022 走看看