Migration, BigInts, and string lengths

Howdy Y’all,

I was thrilled to recently discover migrations, as that framework
addresses a common problem in an elegant way. I have, however, gotten
tripped up a bit as I’ve worked with them.

The first problem I encountered was that, though I was using a BigInt
data type in a field in my dev database, my unit tests were failing
because when I copied the schema from the dev to the testing DB, it was
copied as a plain int. This caused the large values in my unit tests to
fail. I understand why the Migration framework doesn’t support this,
since not all database engines might support BigInts, but it did catch
me by surprise.

So, my next idea was to convert the field to text. While I only need 13
characters in this field, using the change_column command with a :string
type resulted in a varchar with a length of 255. I tried adding a :size
=> 13 option (and a :length => 13 option), but it didn’t make any
difference. So, my actual question: is there any way to specify the
length of a field, or does one just take whatever the framework gives
you by default?

Thanks in advance for any info!

Sean

Sean McMains wrote:

So, my next idea was to convert the field to text. While I only need 13
characters in this field, using the change_column command with a :string
type resulted in a varchar with a length of 255. I tried adding a :size
=> 13 option (and a :length => 13 option), but it didn’t make any
difference. So, my actual question: is there any way to specify the
length of a field, or does one just take whatever the framework gives
you by default?

What you want is the somewhat unintuitive :limit => 13

Regards,
Victor G.

What you want is the somewhat unintuitive :limit => 13

Regards,
Victor G.

You’re absolutely right, Victor. Thank you!

Sean

Guest wrote:

Sean McMains wrote:

So, my next idea was to convert the field to text. While I only need 13
characters in this field, using the change_column command with a :string
type resulted in a varchar with a length of 255. I tried adding a :size
=> 13 option (and a :length => 13 option), but it didn’t make any
difference. So, my actual question: is there any way to specify the
length of a field, or does one just take whatever the framework gives
you by default?

What you want is the somewhat unintuitive :limit => 13

I was looking for this too and I am glad I found this reply.

However – where in the documentation can I find this information. Or
information about what other things are possible in the options field?

[email protected] wrote:

I was looking for this too and I am glad I found this reply.

However – where in the documentation can I find this information. Or
information about what other things are possible in the options field?

http://api.rubyonrails.com/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#M000659

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs