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

Model Annotation Not Updated When Modifying Table Columns Using change_table. #169

Open
hatsu38 opened this issue Nov 28, 2024 · 1 comment · May be fixed by #170
Open

Model Annotation Not Updated When Modifying Table Columns Using change_table. #169

hatsu38 opened this issue Nov 28, 2024 · 1 comment · May be fixed by #170

Comments

@hatsu38
Copy link

hatsu38 commented Nov 28, 2024

Describe your problem here.

Commands

class RemoveOtherColumnsFromQuestionAnswers < ActiveRecord::Migration[7.2]
  def up
    change_table :question_answers, bulk: true do |t|
      t.remove :use_scene
      t.remove :important_point
      t.remove :remark
      t.remove :link
    end
  end

  def down
    change_table :question_answers, bulk: true do |t|
      t.text :use_scene, default: "", null: false, comment: "利用シーン"
      t.text :important_point, default: "", null: false, comment: "重要ポイント"
      t.text :remark, default: "", null: false, comment: "備考"
      t.string :link, default: "", null: false, comment: "リンク"
    end
  end
end

^ I wrote the above migration file and migrated it. bundle exec rails db:migrate

❯ ber db:migrate 
== 20241128110218 RemoveOtherColumnsFromQuestionAnswers: migrating ============
-- change_table(:question_answers, {:bulk=>true})
   -> 0.0046s
== 20241128110218 RemoveOtherColumnsFromQuestionAnswers: migrated (0.0046s) ===

Annotating models
Model files unchanged.

^ Normally, it should result in a model change, but it displayed Model files unchanged. instead. This sometimes happens when modifying a table, but it doesn't occur when creating a table.

Version

  • annotaterb version: 4.13.0
  • rails version: 7.2.2
  • ruby version: 3.3.6
  • database version: postgresql 14
  • database adapter version (if available)
@hatsu38
Copy link
Author

hatsu38 commented Dec 1, 2024

Detail

I understood what was happening. I knew why.

It doesn't seem to work when the table information contains anything other than English and numbers.

Post.rb

# == Schema Information
#
# Table name: posts
#
#  id              :uuid             not null, primary key
#  title(タイトル) :string           not null
#  content(内容)   :text             not null
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#
class Post < ApplicationRecord
end

And, I generate migration file.

class AddMemoToPost < ActiveRecord::Migration[7.2]
  def change
    add_column :posts, :memo, :text, comment: "メモ"
  end
end

I do migrate.

❯ ber db:migrate
== 20241201063248 AddMemoToPost: migrating ====================================
-- add_column(:posts, :memo, :text, {:comment=>"メモ"})
   -> 0.0159s
== 20241201063248 AddMemoToPost: migrated (0.0161s) ===========================

Annotating models
Model files unchanged.

-> Model files unchanged.

But, If I don't use Japanese, I use English comment.

class AddMemoToPost < ActiveRecord::Migration[7.2]
  def change
-    add_column :posts, :memo, :text, comment: "メモ"
+    add_column :posts, :memo, :text, comment: "memo"
  end
end

And I do migrate!

❯ ber db:migrate
== 20241201063248 AddMemoToPost: migrating ====================================
-- add_column(:posts, :memo, :text, {:comment=>"memo"})
   -> 0.0039s
== 20241201063248 AddMemoToPost: migrated (0.0039s) ===========================

Annotating models
Annotated (3): app/models/post.rb, spec/models/post_spec.rb, spec/factories/posts.rb

-> Annotated!!

# == Schema Information
#
# Table name: posts
#
#  id              :uuid             not null, primary key
#  title(タイトル) :string           not null
#  content(内容)   :text             not null
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#  memo(memo)      :text
#
class Post < ApplicationRecord
end

Reason Code

COLUMN_PATTERN = /^#[\t ]+[\w*.`\[\]():]+[\t ]+.+$/

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