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

✨ [Feature]: 建议使用 umzug 管理数据库的 migration 和 seeds #234

Open
jserfun opened this issue Dec 13, 2024 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@jserfun
Copy link

jserfun commented Dec 13, 2024

What problem does this feature solve

umzug: https://github.com/sequelize/umzug

umzug 管理数据库的 migration 和 seeds 的优势

  • 不局限于 orm 框架
  • 数据路径: 可自由选定
  • 操作记录: 存储可以放在数据库,也可以本地 json 文件保存
  • 文件格式: 可以是 sql 文件,也可以是 js, ts 文件
  • 精细管理: 可以是 一直 up, 或者 down, 也可以是 up / down 任意一个,也可以是任意范围
  • 日志管理: 清晰管理和记录日志,日志库可以选定任意 logger, 可以是 log4js, winston 或者 pino, 也可以自定义

What does the proposed API look like

umzug migrate 例子: https://github.com/sequelize/umzug/blob/main/examples

普通形式的 migration

源码路径: https://github.com/sequelize/umzug/blob/main/examples/0-vanilla/migrate.js

migrate.js

const { Umzug, JSONStorage } = require('umzug');

exports.migrator = new Umzug({
	migrations: {
		glob: 'migrations/*.js',
	},
	context: { directory: __dirname + '/ignoreme' },
	storage: new JSONStorage({ path: __dirname + '/ignoreme/storage.json' }),
	logger: console,
});

if (require.main === module) {
	exports.migrator.runAsCLI();
}

node 直接运行 migrate.js

node migrate --help # show CLI help

node migrate up # apply migrations
node migrate down # revert the last migration
node migrate create --name new-migration.js # create a new migration file

node migrate up # apply migrations again
node migrate down --to 0 # revert all migrations
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: ✨ [Feature]: It is recommended to use umzug to manage database migration and seeds

@kagol kagol added the enhancement New feature or request label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants