处理续集迁移和初始化的工作流程?

编程入门 行业动态 更新时间:2024-10-12 08:27:11
本文介绍了处理续集迁移和初始化的工作流程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不明白 sequelize 迁移工作流程的工作原理.我有一个新建项目,数据库是使用 SQL 脚本设计的.之后我们使用 sequelize auto 生成模型.

我现在需要生成一个迁移文件,这样我就可以运行 CLI 来运行 SQL 查询,从而为本地配置的数据库创建带有列等的新表.

没有第三方工具 afaik 可以将我拥有的 SQL 脚本转换为 Sequelize 迁移文件.我必须为 60 个表手动执行此操作.有一种自动创建它的脚本方法,但它使用了一种单独的格式,该格式不具有用于撤消迁移的向后兼容性(sequelize-auto-migrations).

当我在我的文件中更新 sequelize 模型架构时,没有一个单独的命令可以通过基于上次迁移执行运行的差异机制使迁移文件与这些更改同步.

这意味着我必须修改模型,并修改迁移文件,从而导致潜在的人为错误和重复的冗余工作.

所以我的问题是

  • sequelize 有办法初始化第一个迁移文件吗?
  • 当我在 sequelize 中修改模型并根据一些差异机制自动生成新的迁移文件时,是否有可以使用的工具?
  • 解决方案

    好吧我知道了

    对于第 1 步,您可以运行 queryInterface.sequelize.query(<query>) 并获取 SQL 脚本/在 sequelize 中直接运行它们以进行初始化.

    对于第 2 步,您可以手动修改文件并更新迁移,然后运行 ​​sequelize-auto 从远程/本地数据库中提取最新更改

    I don’t get how sequelize migrations workflow works. I have a greenfield project, the database is designed using SQL scripts. We used sequelize auto to generate the models thereafter.

    I need to now generate a migrations file starting out, so I can run the CLI to run SQL queries to create new tables with columns etc for locally provisioned databases.

    There’s no 3rd party tools afaik to convert the SQL script I have into a Sequelize migrations file. I have to do this manually for 60 tables. There is a script method of auto-creating it, but it uses a seperate format that doesn’t have backward compatability for undoing migrations (sequelize-auto-migrations).

    When I update the sequelize model schema in my file, there’s not a one off way command to have migrations file synchronize to those changes, via a diffing mechanisms based off the last migration execution ran.

    This means I have to modify the model, AND modify the migrations file, leading to potential human error and duplicate redundant work.

    so my issues are

  • does sequelize have a way to initialize the first migrations file?
  • is there a tool I can use when I modify models in sequelize, and generate the new migrations file automatically based off some diffing mechanism?
  • 解决方案

    okay I found out

    For step 1, you can run a queryInterface.sequelize.query(<query>) and take the SQL scripts / run them right in sequelize for initialization. sequelize/master/class/lib/query-interface.js~QueryInterface.html. This short code references the sql script as the first migration

    For step 2, you can modify the file and update the migrations manually, and run sequelize-auto to pull the latest changes from the remote/local db

    更多推荐

    处理续集迁移和初始化的工作流程?

    本文发布于:2023-10-26 07:09:02,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1529430.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:续集   初始化   工作流程

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!