> On Friday, June 23, 2017 at 7:33:56 PM UTC-4, Jeremy Evans wrote:
> 
> In order to troubleshoot this, you need to prepare a minimal, self contained 
> example migration file that shows the issue.

This shows the issue:

Sequel.migration do
  change do
    create_table(:stuff, ignore_index_errors: true) do
      Integer :id, null: false

      index [:id], name: :idx_by_id
    end

    create_table(:things, ignore_index_errors: true) do
      Integer :id, null: false

      index [:id], name: :idx_by_id
    end
  end
end

> In general, the error you are seeing should only happen if you are rescuing 
> an earlier exception that caused the transaction to abort.

Indeed, I was inadvertently rescuing an earlier exception via the option 
`ignore_index_errors: true` being passed to `create_table`.

It took me some time to figure that out and I think it was partly because I 
didn’t personally decide to specify that option; the migration at hand was 
generated by the `schema_dumper` extension; it appears that 
`dump_schema_migration` includes that option, set to true, by default. Because 
the option was included in the default output of `dump_schema_migration` I 
assumed that it was a best practice for some reason.

So that’s why the root cause was being occluded. The root cause itself was 
revealed immediately once I removed the `ignore_index_errors` option: ERROR: 
relation "idx_by_id" already exists.

So, the schema dumped by `dump_schema_migration` included duplicate index 
names. The source database was a SQL Server DB, and the target database 
PostgreSQL; it would appear that in SQL Server index names need be unique only 
within a given table, whereas apparently in PostgreSQL they must be unique 
within the schema. Good to know!

I’m still curious why `dump_schema_migration` includes `ignore_index_errors: 
true` by default in `create_table` — given my experience, it would seem to be 
at least somewhat problematic. Is this something that should possibly be 
changed?

Thanks!
Avi


————
Software Architect @ Park Assist » http://tech.parkassist.com/

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to