Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forked #37

Open
lewismoten opened this issue Jun 4, 2024 · 2 comments
Open

Forked #37

lewismoten opened this issue Jun 4, 2024 · 2 comments

Comments

@lewismoten
Copy link

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
Copy link
Owner

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
Copy link
Author

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:

  • Added ability to export/load data.sql for lookup data (excludes migration table)
  • ad-hoc migration by timestamp only migration run 1716831766170 up
  • record run <timestamp> in migration table
  • Reducing the noise in the schema.sql file:
    • Add --skip-dump-date Since we have a repository that tracks dates. Otherwise every up command kept showing the schema.sql file changed when only the date changed. -- Dump completed on 2024-05-29 22:04:07
    • Add --skip-comments
      • Removes header that may change between developers/servers
      • Also removed table/procedure headers (leaner, but wasn't what I was after)
      • Removes dump status
-- MariaDB dump 10.19-11.3.2-MariaDB, for osx10.19 (arm64)
--
-- Host: localhost    Database: local_test
-- ------------------------------------------------------
-- Server version	11.3.2-MariaDB
--
-- Table structure for table `mysql_migrations_347ertt3e`
--
-- Dump completed
  • Remove version specific queries
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
  • Remove definer when creating procedures and functions since a different user exists on the develop database
CREATE DEFINER=`root`@`localhost` FUNCTION `uuid4`() RETURNS char(36) CHARSET utf8mb4 COLLATE utf8mb4_general_ci
  • Format all code blocks in readme.md as bash or JavaScript for syntax highlighting
  • Ability to pass --argv option to override process.argv for testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants