kawadhiya21 / mysql-migrations

A tool to use with mysql package to maintain migrations
MIT License
31 stars 25 forks source link

Forked #37

Open lewismoten opened 4 months ago

lewismoten commented 4 months ago

Given that this project hasn't had any activity over the past few years, I'm under the impression that it has been abandoned. If this is not the case, let me know. In the meantime, I've made several changes and bug fixes (hanging, processing non-js files, etc) on my own fork and published it. Many of the changes have been opened as PR's to merge back into this repository as well.

Here is an example of some of the configuration changes that lets you save your seed data, procedures, functions, events, log threshold, and a custom logger. I also added the ability to override the process.argv via the options array.

If @kawadhiya21 would prefer, I'd like to get these changes back into the original mysql-migrations repository here.

const { createPool } = require('mysql');
const { init } = require('@lewismoten/mysql-migrations');
const path = require('path');

var connection = createPool({
  connectionLimit: 10,
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  multipleStatements: true
});

init(connection, path.join(__dirname, '../migrations'), () => {
  console.log('Done.');
}, [
  '--update-schema',
  '--update-data',
  `--template .template.js`,
  '--log-level INFO',
  // '--logger',
  // customLogger
  // '--argv'
  // ['', '', 'up']
]);

Here is an example of .templatejs. I wanted a custom template so I could get highlighting of SQL queries to show up properly in my IDE.

const sql = require('../sql');

module.exports = {
  up: (conn, cb) => {
    conn.query(sql`${{ args.up }}`, (err, res) => {
      if (err) throw err;
      cb();
    });
  },
  down: sql``
};
kawadhiya21 commented 4 months ago

Thanks for all the work you have done @lewismoten . I will review each of the PRs and merge them one by one. I had made this package while I was working on something and felt the need to make a mysql migration package. Never thought it would go this far :)

lewismoten commented 4 months ago

I didn't realize you were still maintaining the project. Thank you for making this available. I'm more familiar with Active Record with Ruby on Rails, and this is similar to how it managed database changes over time. I've got a separate project that is dedicated to the architecture of the database only. It migrates the development database any time changes are pushed to the develop branch via GitHub Actions, and this works well with it.

I've made a few more changes outside of the PR's on my own fork along with starting to do some refactoring.

The main updates were: