The problem with changing columns in a database is downtime. When you deploy and migrate it on production it will lock the entire table while changing this column. If it's a large table it might be noticeable downtime.
Longer explanation:
You didn't specify which SQL (Postgres/MySQL?) you are using. But most of the time changing the type of the column means:
- creating a new column
- copying all the data from the old column
- deleting the old column
To make sure everything is copied correctly the entire table will be locked for this time. Locked means no reading or writing. Hence, the downtime.
As for why this happened, can you provide the Ruby, Rails, and SQL versions? Maybe you updated one of them recently?
Also, are you absolutely sure you had integer
in your database before the migration? I mean in the database, not in the schema (these are not always the same).
The schema can come from two places:
- It's something that rails generated the last time you run the migration. If since then, you made some changes to your database in some other way it will not be visible in the schema. But the next time you run a migration rails will update the schema to match the current db state.
- It's something you downloaded from git. Maybe another developer has a database that uses
integers
, they run a migration that changed the values to integer
and pushed it. But your local database uses bigint
, so now you run the migration it was updated again.
If you are working with other people check the git blame on the schema file to see if these fields were always an integer
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…