7

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?

Glyoko
  • 2,071
  • 1
  • 14
  • 28

1 Answers1

11

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.

Jordan Running
  • 102,619
  • 17
  • 182
  • 182