chore: 自动转换mysql表格engine

This commit is contained in:
xiaojunnuo
2026-02-09 18:40:15 +08:00
parent ad22244388
commit b16f92314b
4 changed files with 56 additions and 2 deletions
+18 -2
View File
@@ -75,8 +75,24 @@ function transformMysql() {
pgSql = pgSql.replaceAll(/text/g, 'longtext');
//双引号 替换成反引号
pgSql = pgSql.replaceAll(/"/g, '`');
//create table if not exists
pgSql = pgSql.replaceAll(/CREATE TABLE ([ ]+)`/g, 'CREATE TABLE IF NOT EXISTS `');
//提取所有的 create table 的表格name
const tableNames = pgSql.match(/CREATE TABLE `([^`]*)`/g);
if (tableNames && tableNames.length > 0) {
for (const item of tableNames) {
/**
* CREATE TABLE `cd_project`
CREATE TABLE `cd_project_member`
CREATE TABLE `cd_audit_log`
*/
//提取表名
const tableName = item.match(/`([^`]*)`/)[1];
pgSql += `\nALTER TABLE \`${tableName}\` ENGINE = InnoDB;`
}
}
fs.writeFileSync(`./migration-mysql/${notFile}`, pgSql);
}