gpt4 book ai didi

mysql - 我应该使用 Rails 迁移来更新生产数据吗?

转载 作者:太空宇宙 更新时间:2023-11-03 18:17:49 25 4
gpt4 key购买 nike

在旧的 Rails 应用程序中,我需要更新生产数据库中一组记录中的一列。我不会以任何方式改变数据库的结构。我可以只编写一个针对数据库运行的 SQL 脚本,或者我可以编写一个 Rails 迁移来更新所有需要更改的模型。但是,这就是感觉不对。

仅修改生产数据而不更改结构的一次性数据库更新的最佳实践是什么?

最佳答案

作为 rubyonrails guide :

Migrations are a convenient way to alter your database schema over time in a consistent and easy way.

我认为您应该有用于数据修复的脚本,因为这些是一次性修复,如果有人在其他迁移上或每次在本地运行迁移时测试等,您不希望这些运行。迁移应该只包含以任何方式而不是数据更改数据库模式的代码。

已编辑

看来 rails 已经随着时间的推移而发展,现在它建议可以使用迁移来添加/修改数据,来自 edgeguides :

The main purpose of Rails' migration feature is to issue commands that modify the schema using a consistent process. Migrations can also be used to add or modify data. This is useful in an existing database that can't be destroyed and recreated, such as a production database.

关于mysql - 我应该使用 Rails 迁移来更新生产数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23367247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com