Giter VIP home page Giter VIP logo

Comments (5)

burnt43 avatar burnt43 commented on August 18, 2024

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

from mini_record.

burnt43 avatar burnt43 commented on August 18, 2024

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

from mini_record.

Xanders avatar Xanders commented on August 18, 2024

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

from mini_record.

burnt43 avatar burnt43 commented on August 18, 2024

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

from mini_record.

Xanders avatar Xanders commented on August 18, 2024

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

from mini_record.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.