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.项目目录:

  • 相关阅读:
    概率期望,数学,贪心策略——2020-camp-day1-A
    k染色——2020-camp-day3-C
    树形dp——2020-camp-day3-G
    欧拉回路/路径——2020-camp-day2-H
    dsu on tree——2020-camp-day2-E
    Nim博弈,异或性质——2020-camp-day2-C
    一些视频资料
    开发人员收藏的网站
    各行公认的好书
    资料库链接
  • 原文地址:https://www.cnblogs.com/crazycode2/p/12238412.html
Copyright © 2011-2022 走看看