Schema dump does not reflect column size limit

Hi,

Everything is in the title.
With Rails 2.3.4 and MySQL 5.0.41:

If have a table like this:

±---------------±-----------±-----±----±--------±---------------+
| Field | Type | Null | Key | Default | Extra |
±---------------±-----------±-----±----±--------±---------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| author_id | int(11) | YES | | NULL | |
| author_bet_id | int(11) | YES | | NULL | |
| author_comment | text | YES | | NULL | |
| created_at | datetime | YES | | NULL | |
| confirmed | tinyint(1) | YES | | NULL | |
| admin_comment | text | YES | | NULL | |
| confirmed_at | datetime | YES | | NULL | |
| bet_id | int(11) | YES | MUL | NULL | |
| user_id | int(11) | YES | MUL | NULL | |
±---------------±-----------±-----±----±--------±---------------+

But in schema.rb, I have this:

create_table “abuses”, :force => true do |t|
t.integer “author_id”
t.integer “author_bet_id”
t.text “author_comment”
t.datetime “created_at”
t.boolean “confirmed”
t.text “admin_comment”
t.datetime “confirmed_at”
t.integer “bet_id”
t.integer “user_id”
end

Why the hell is the size limit lost?

On Nov 11, 2009, at 4:55 AM, Thomas Gendulphe wrote:

| Field | Type | Null | Key | Default |
| |
| user_id | int(11) | YES | MUL | NULL
t.datetime “created_at”
t.boolean “confirmed”
t.text “admin_comment”
t.datetime “confirmed_at”
t.integer “bet_id”
t.integer “user_id”
end

Why the hell is the size limit lost?

What size limit is that? Did you mean to show the migration that
created the table? Since MySQL has no boolean type, it gets
implemented as tinyint(1) and the default for integer is int(11). Do
you still thing that there is a problem?

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Rob B. wrote:

On Nov 11, 2009, at 4:55 AM, Thomas Gendulphe wrote:

| Field | Type | Null | Key | Default |
| |
| user_id | int(11) | YES | MUL | NULL
t.datetime “created_at”
t.boolean “confirmed”
t.text “admin_comment”
t.datetime “confirmed_at”
t.integer “bet_id”
t.integer “user_id”
end

Why the hell is the size limit lost?

What size limit is that? Did you mean to show the migration that
created the table? Since MySQL has no boolean type, it gets
implemented as tinyint(1) and the default for integer is int(11). Do
you still thing that there is a problem?

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Actually, the source database, from which schema.rb is created has
columns, like user_id, with a type of integer(11).
In schema.rb, it is dumped as t.integer “user_id”.
When I load the schema in another databse, it creates a column user_id
with a type of integer(4).

So I am wondering why schema dump is not t.integer “user_id”, :limit =>
11

On Wed, Nov 11, 2009 at 1:55 AM, Thomas Gendulphe
[email protected] wrote:

With Rails 2.3.4 and MySQL 5.0.41:

| id | int(11) | NO | PRI | NULL | auto_increment |
| author_id | int(11) | YES | | NULL | |

t.integer “author_id”
t.integer “author_bet_id”

Why the hell is the size limit lost?

Because it’s basically meaningless? :slight_smile:

via http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html :

Another extension is supported by MySQL for optionally specifying the
display width of integer data types in parentheses following the base
keyword for the type (for example, INT(4)). This optional display
width may be used by applications to display integer values having a
width less than the width specified for the column by left-padding
them with spaces. (That is, this width is present in the metadata
returned with result sets. Whether it is used or not is up to the
application.)

The display width does not constrain the range of values that can be
stored in the column, nor the number of digits that are displayed for
values having a width exceeding that specified for the column. For
example, a column specified as SMALLINT(3) has the usual SMALLINT
range of -32768 to 32767, and values outside the range allowed by
three characters are displayed using more than three characters.

Reading The Fine Manual – priceless :slight_smile:


Hassan S. ------------------------ [email protected]
twitter: @hassan

On Nov 12, 2009, at 4:16 PM, Thomas Gendulphe wrote:

t.integer “bet_id”

So I am wondering why schema dump is not t.integer “user_id”, :limit
=>
11

Ah! Do those mean an equivalent thing? For example, is one database’s
“int(11)” a type to hold integers of up to 11 decimal digits and
another database’s “integer(4)” a type that holds integers in 4
bytes? Those are the same thing! And you probably wouldn’t want to
suddenly have 11 BYTE integers in the other (or 4 DIGIT integers in
the first).

-Rob

(Notwithstanding Hassan’s pointer to the meaning of MySQL’s use of 11
to indicate the display width.)

Rob B. http://agileconsultingllc.com
[email protected]