Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Sequelize = require('sequelize');
- const { exec } = require('child_process');
- const execAsync = function(command) {
- return new Promise((resolve, reject) => {
- exec(command, (err, stdout, stderr) => {
- if (err) {
- reject(err);
- }
- resolve(stdout)
- });
- });
- }
- const sequelize = new Sequelize('sequelize-fiddle', 'root', 'asdqwe123', {
- host: 'localhost',
- dialect: 'mysql',
- operatorsAliases: false,
- logging: false,
- pool: {
- max: 5,
- min: 0,
- acquire: 30000,
- idle: 10000
- },
- retry: {
- match: [
- /SequelizeConnectionError/,
- /SequelizeConnectionRefusedError/,
- /SequelizeHostNotFoundError/,
- /SequelizeHostNotReachableError/,
- /SequelizeInvalidConnectionError/,
- /SequelizeConnectionTimedOutError/,
- /SequelizeDatabaseError/
- ],
- name: 'query',
- backoffBase: 100,
- backoffExponent: 1.1,
- timeout: 60000,
- max: Infinity
- }
- });
- const matchSchema = {
- id: {
- type: Sequelize.INTEGER,
- autoIncrement: true,
- primaryKey: true
- },
- name: {
- type: Sequelize.STRING
- }
- };
- // const playerSchema = {
- // id: {
- // type: Sequelize.INTEGER,
- // autoIncrement: true,
- // primaryKey: true
- // },
- // name: {
- // type: Sequelize.STRING,
- // allowNull: false
- // },
- // };
- // const matchPlayerSchema = {
- // order: {
- // type: Sequelize.INTEGER,
- // allowNull: false
- // },
- // };
- const Match = sequelize.define('match', matchSchema);
- // const Player = sequelize.define('player', playerSchema);
- // const MatchPlayer = sequelize.define('match_player', matchPlayerSchema);
- // Match.belongsToMany(Player, { through: MatchPlayer });
- // Player.belongsToMany(Match, { through: MatchPlayer });
- (async () => {
- await Match.sync();
- // await Player.sync();
- // await MatchPlayer.sync();
- await Match.destroy({
- where: {},
- truncate: true
- });
- setTimeout(async () => {
- console.log('Stopping mysql service..');
- await execAsync('sudo service mysql stop');
- console.log('..done!');
- }, 5000);
- setTimeout(async () => {
- console.log('Starting mysql service..');
- await execAsync('sudo service mysql start');
- console.log('..done!');
- }, 10000);
- for (let i = 1; i < 10000; i++) {
- console.log('Storing:', i);
- const match = new Match();
- match.name = String(i);
- await match.save();
- await sleep(100);
- }
- })();
- function sleep(delay) {
- return new Promise((resolve) => {
- setTimeout(resolve, delay);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement