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

  • 相关阅读:
    ASP.NET ZERO 学习 JTable的ChildTable用法
    ASP.NET ZERO Core Application 学习笔记
    uploadify ASP.net 使用笔记
    金额的加减乘除运算
    利用autoit自动关闭指定标题窗口
    Struts2源代码解读之Action调用
    利用btrace工具监控在线运行java程序
    自己实现的简单MVC框架(类似Struts2+Spring)
    简单实用后台任务执行框架(Struts2+Spring+AJAX前端web界面可以获取进度)
    mybatis源代码分析:mybatis延迟加载机制改进
  • 原文地址:https://www.cnblogs.com/crazycode2/p/12238412.html
Copyright © 2011-2022 走看看