gpt4 book ai didi

ruby-on-rails - 为什么我在 structure.sql 中看到 `SET xmloption = content;`?

转载 作者:数据小太阳 更新时间:2023-10-29 07:31:25 24 4
gpt4 key购买 nike

我正在使用 Rails 6,并且最近编写了一个小型迁移程序来向表中添加一列。简单的东西:

class AddInstagramUsernameToUsers < ActiveRecord::Migration[6.0]
def change
add_column :users, :instagram_username, :string
end
end

但注意到在运行迁移时我看到以下行添加到我的 structure.sql 中:

SET xmloption = content;

我并不是特别担心它,(诚然 documentation 描述了这个选项,这让它看起来很无害)但是我不想让这么小的迁移改变任何 meta postgres 的东西。我尝试降级到 Rails 5 以摆脱这条线,但没有成功。我使用的是 postgres 版本 10.8,最近没有升级。

目前我不知道是什么添加了这一行,如果可能的话我想去掉它。任何人都知道是什么原因造成的/如何预防?

最佳答案

Rails 不会生成 structure.sql——它会生成 PostgreSQL 内置的 pg_dump 工具。根据 Active Record Migrations Rails Guide :

When the schema format is set to :sql, the database structure will be dumped using a tool specific to the database into db/structure.sql. For example, for PostgreSQL, the pg_dump utility is used.

在您的 structure.sql 中生成该行的是 pg_dump。

据我所知,它这样做的原因是,当从 pg_dump 文件恢复时,不能假定目标数据库具有与源数据库相同的 xmloption 设置.如果没有这一行,用户可能会遇到 this bug report 中描述的问题。 .该更改包含在 PostgreSQL 9.4.22 中——特别是 commit 8ba48542 .

没有办法禁用它,也没有理由这样做。

关于ruby-on-rails - 为什么我在 structure.sql 中看到 `SET xmloption = content;`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56673822/

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