-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto changing column type don't work on PostgreSQL #59
Comments
I can reproduce this issue. I'm using MySQL though with the mysql2 adapter. Reproduction Steps class Foobar < ActiveRecord::Base
field :name, as: :string
field :data, as: :integer
end I ran auto_upgrade! irb(main):001:0> Foobar => Foobar(Table doesn't exist) irb(main):002:0> Foobar.auto_upgrade! [MiniRecord] Creating Table foobars (542.8ms) CREATE TABLE `foobars` (`id` int(11) auto_increment PRIMARY KEY) ENGINE=InnoDB [MiniRecord] Adding column foobars.name (514.5ms) ALTER TABLE `foobars` ADD `name` varchar(255) [MiniRecord] Adding column foobars.data (444.6ms) ALTER TABLE `foobars` ADD `data` int(11) => nil I changed the type to text class Foobar < ActiveRecord::Base
field :name, as: :string
field :data, as: :text
end I ran auto_upgrade! again irb(main):003:0> Foobar.auto_upgrade! => nil I double check column type in MySQL and it is still an integer. MariaDB [test_app_development]> describe foobars; +-------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(255) | YES | | NULL | | | data | int(11) | YES | | NULL | | +-------+--------------+------+-----+---------+----------------+ |
I found the issue and I am able to get it to change the column type. I will submit a PR soon. You can ignore my puts statements prefaced with "[JAMES]". irb(main):024:0> Foobar.auto_upgrade! [JAMES] ---- TEST [JAMES] id [JAMES] name [JAMES] new_attr: {}, changed: false [JAMES] new_type: string [JAMES] data [MiniRecord] Detected schema change for foobars.data#type from :integer to :text [JAMES] new_attr: {:type=>:text}, changed: true [JAMES] new_type: text [MiniRecord] Changing column foobars.data to new type text (721.5ms) ALTER TABLE `foobars` CHANGE `data` `data` text DEFAULT NULL => nil Now I look at my DB and the column is text now! MariaDB [test_app_development]> describe foobars; +-------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(255) | YES | | NULL | | | data | text | YES | | NULL | | +-------+--------------+------+-----+---------+----------------+ |
@burnt43, thank you very much! It's amazing responce speed! I'll wait for a new release with your PR! :) |
@Xanders, if you need this quickly you can update your Gemfile and point it to my github burnt43/mini_record until the PR is fix and accepted. |
@burnt43, thank you for a tip! :) I don't need it so quickly. :) |
Hello. It's look like changing column type is not working at PostgreSQL. For example:
Works well. Then I change :integer to :text, reload app and Some class... And nothing happend. :( Is it for me only or it's a bug?
Any other changings (adding, removing columns etc.) works perfectly.
The text was updated successfully, but these errors were encountered: