activeuuid icon indicating copy to clipboard operation
activeuuid copied to clipboard

schema.rb not being generated correctly after migration

Open cameronbourgeois opened this issue 8 years ago • 4 comments

My migrations are not creating the correct entires in my schema.rb file.

See my example migration:

create_table :my_table, { id: false } do |t|
      t.uuid :id, primary_key: true

      t.timestamps
end

And this generates an entry in my schema.rb, without my uuid primary key

create_table "my_table", force: :cascade do |t|
    t.datetime "created_at"
    t.datetime "updated_at"
  end

I then need to manually change my shema.rb to the following in order for it to work correctly:

create_table "my_table", id: false, force: :cascade do |t|
    t.uuid        "id",                limit: 16, primary_key: true
    t.datetime "created_at"
    t.datetime "updated_at"
end

Is there something existing I can enter into my migrations to get this to work?

cameronbourgeois avatar Mar 20 '16 00:03 cameronbourgeois

@cameronbourgeois what version of Rails are you using?

We just upgraded from Rails 4.0 to Rails 4.2, and now every time we run a migration, in the schema file every table that had a uuid 'id' column loses its id column entirely, even if the migration itself is for something completely unrelated.

If our problem is the same thing as yours, that suggests the problem isn't with your migration syntax, it's with how this gem interacts with ActiveRecord in Rails 4.2.

@jashmenn, this repo hasn't had any commits in 10 months - is it still being maintained by anyone and is there a reasonably chance that anyone will be able to look into this?

patrick-gleeson avatar Jul 05 '16 08:07 patrick-gleeson

@patrick-gleeson I've had this issue in both Rails 4.2.5 and 4.2.6. It does makes sense that this may be a compatibility issue with newer versions of ActiveRecord since this gem seems to have fallen out of maintenance.

My work-around was to use structure.sql instead of schema.rb by adding the following line to config/application.rb:

config.active_record.schema_format = :sql

See http://edgeguides.rubyonrails.org/active_record_migrations.html#schema-dumping-and-you

cameronbourgeois avatar Jul 05 '16 08:07 cameronbourgeois

Ah nice one! Yep, that's working for us too as a workaround.

patrick-gleeson avatar Jul 05 '16 10:07 patrick-gleeson

@patrick-gleeson - I've added you as a contributor! Feel free to make commits directly!

jashmenn avatar Jun 22 '17 19:06 jashmenn