Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4751 (closed defect: untested)

Opened 2 years ago

Last modified 2 years ago

rake db:schema:dump misses customized id and table options

Reported by: dudupy@gmail.com Assigned to: David
Priority: normal Milestone: 1.2
Component: ActiveRecord Version: edge
Severity: normal Keywords: migration primary key
Cc: rails@bencurtis.com

Description (Last modified by bitsweat)

SW Versions: Rails 1.1.2, Ruby 1.8.4, and MySQL 5.0.18

To reproduce, (1) create a table into the development datbase by invoking the command rake db:migrate given the following db/migrate/001_create_news_items.rb

class CreateNewsItems < ActiveRecord::Migration
  def self.up
    create_table(
      :news_items,
      :options => "engine=InnoDB default charset=utf8") do |t|
        t.column :title, :string
        t.column :excerpt, :string
        t.column :body, :text
        t.column :lock_version, :integer, :default => 0
        t.column :user_id, :integer
        t.column :updated_at, :datetime
        t.column :created_at, :datetime
      end
    # Customize the id column
    change_column(:news_items, :id, :string, :limit => 32, :null => false)
  end

  def self.down
    drop_table(:news_items)
  end
end

(2) rake db:schema:dump gets an incomplete db/schema.rb

  create_table "news_items", :force => true do |t|
    t.column "title", :string
    t.column "excerpt", :string
    t.column "body", :text
    t.column "lock_version", :integer, :default => 0
    t.column "user_id", :integer
    t.column "updated_at", :datetime
    t.column "created_at", :datetime
  end

Both id and charset are misconfigured in a resulting table:

CREATE TABLE `news_items` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) default NULL,
  `excerpt` varchar(255) default NULL,
  `body` text,
  `lock_version` int(11) default '0',
  `user_id` int(11) default NULL,
  `updated_at` datetime default NULL,
  `created_at` datetime default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Attachments

schema_dump_non_integer_pk.patch (1.1 kB) - added by ctm on 01/11/07 03:02:27.
require column type to be :integer as well as have maching name before using as pk

Change History

(follow-up: ↓ 2 ) 04/17/06 16:15:16 changed by Ben Curtis <rails@bencurtis.com>

  • cc set to rails@bencurtis.com.

This is also a problem when using a non-default setting for config.active_record.primary_key_prefix_type. I have patched my local copy, and sent email to rails-core about the best place to put the code to handle this case (since it also affects fixtures), but got no response. I'd be happy to submit a patch for this based on my work.

(in reply to: ↑ 1 ; follow-up: ↓ 7 ) 09/12/06 18:31:58 changed by rpotter@anl.gov

Replying to Ben Curtis <rails@bencurtis.com>: I'm having a similar problem when trying to run my test suite. I'd be interested in seeing your patch.

09/12/06 21:41:24 changed by bitsweat

  • description changed.
  • milestone set to 1.2.

01/11/07 03:02:27 changed by ctm

  • attachment schema_dump_non_integer_pk.patch added.

require column type to be :integer as well as have maching name before using as pk

01/11/07 03:10:24 changed by ctm

Attached patch may address the non-integer primary key bug. It seems to work with the Postgresql adapter, but I can't easily test the other adapters. I won't blame people in Rails core for ignoring the patch since it doesn't come with test cases, but it still may be useful to end-users until a proper fix arrives.

01/11/07 03:28:41 changed by bitsweat

  • keywords set to migration primary key.
  • status changed from new to closed.
  • version set to edge.
  • resolution set to untested.

Thanks for pitching in, ctm!

01/16/07 09:18:06 changed by smeade

ctm's patch worked for me with mysql

I ran dudupy's migration above and here's my schema.rb before

  create_table "news_items", :force => true do |t|
    t.column "title",        :string
    t.column "excerpt",      :string
    t.column "body",         :text
    t.column "lock_version", :integer,  :default => 0
    t.column "user_id",      :integer
    t.column "updated_at",   :datetime
    t.column "created_at",   :datetime
  end

and schema.rb with ctm's patch

  create_table "news_items", :id => false, :force => true do |t|
    t.column "id",           :string,   :limit => 32, :default => "", :null => false
    t.column "title",        :string
    t.column "excerpt",      :string
    t.column "body",         :text
    t.column "lock_version", :integer,                :default => 0
    t.column "user_id",      :integer
    t.column "updated_at",   :datetime
    t.column "created_at",   :datetime
  end

Note that charset is not writing out, is it supposed to?

Sorry that unfortunately my local database configuration is not working happily right now with the test connections to execute schema_dumper_test.rb

(in reply to: ↑ 2 ) 01/16/07 13:35:46 changed by ben

Replying to rpotter@anl.gov:

Replying to Ben Curtis <rails@bencurtis.com>: I'm having a similar problem when trying to run my test suite. I'd be interested in seeing your patch.

See #7085 for my patch to fix the problem I mentioned.