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

  • 相关阅读:
    Drupal Coder 模块远程命令执行分析(SA-CONTRIB-2016-039)
    Python 实现 ZoomEye API SDK
    程序员互动联盟第一届编码大赛第二题解题分享
    python中各进制之间的转换
    记一次ctf比赛解密题的解决(可逆加密基本破解之暴力破解)
    使用JsonConfig控制JSON lib序列化
    openMRS项目
    Harmonic Number(调和级数+欧拉常数)
    Pairs Forming LCM(素因子分解)
    Uva 11395 Sigma Function (因子和)
  • 原文地址:https://www.cnblogs.com/crazycode2/p/12238412.html
Copyright © 2020-2023  润新知