Skip to content
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

Open
Xanders opened this issue Nov 13, 2015 · 5 comments · May be fixed by #60
Open

Auto changing column type don't work on PostgreSQL #59

Xanders opened this issue Nov 13, 2015 · 5 comments · May be fixed by #60

Comments

@Xanders
Copy link

Xanders commented Nov 13, 2015

Hello. It's look like changing column type is not working at PostgreSQL. For example:

class Some < ActiveRecord::Base
  field :super_field, as: :integer
  auto_upgrade!
end

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.

@burnt43
Copy link
Contributor

burnt43 commented Nov 14, 2015

I can reproduce this issue. I'm using MySQL though with the mysql2 adapter.

Reproduction Steps
I created a dummy class

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    |                |
+-------+--------------+------+-----+---------+----------------+

@burnt43
Copy link
Contributor

burnt43 commented Nov 14, 2015

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 burnt43 linked a pull request Nov 14, 2015 that will close this issue
@Xanders
Copy link
Author

Xanders commented Nov 20, 2015

@burnt43, thank you very much! It's amazing responce speed! I'll wait for a new release with your PR! :)

@burnt43
Copy link
Contributor

burnt43 commented Nov 20, 2015

@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.

@Xanders
Copy link
Author

Xanders commented Nov 21, 2015

@burnt43, thank you for a tip! :) I don't need it so quickly. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants