Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I seeing `SET xmloption = content;` in my structure.sql?

I'm using Rails 6 and recently wrote a small migration to add a column to a table. Simple stuff:

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

But noticed that I see the following line added to my structure.sql when I run the migration:

SET xmloption = content;

I'm not especially worried about it, (admittedly the documentation describing the option makes it seem pretty innocuous) but would like not to have such a small migration change any meta postgres stuff. I tried downgrading to Rails 5 to get rid of this line but no luck. I am using postgres version 10.8 and haven't upgraded recently.

Currently I have no idea what's adding this line, and would like to get rid of it if possible. Anyone know what's causing this/how to prevent it?

like image 934
Glyoko Avatar asked Jun 19 '19 18:06

Glyoko


1 Answers

Rails doesn't generate structure.sql—it farms that work out to PostgreSQL's built-in pg_dump tool. Per the 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.

It's pg_dump that generates that line in your structure.sql.

The reason it does that, as far as I can tell, is that when restoring from a pg_dump file it can't be assumed that the target database has the same xmloption set as the source database. Without this line, the user could run into a problem as described in this bug report. The change was included in PostgreSQL 9.4.22—specifically commit 8ba48542.

There's no way to disable this, and no reason to do so.

like image 135
Jordan Running Avatar answered Nov 02 '22 07:11

Jordan Running