Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

willcosgrove
Copy link
Contributor

Description

This PR fixes issue #397 where the upgrade generator produces invalid table names for namespaced models.

Problem

When using custom model names with namespaces (like Assistant::Chat, Assistant::Message, etc.) and running the upgrade generator:

rails g ruby_llm:upgrade_to_v1_7 chat:Assistant::Chat message:Assistant::Message

The migration would generate invalid table names like :assistant/chats instead of :assistant_chats.

Solution

The issue was that the generator was using .tableize which produces forward slashes for namespaced models. This has been fixed by using .underscore.pluralize.tr('/', '_') which properly converts namespaced model names to valid table names.

Changes:

  • Added table_name_for helper method that correctly handles namespaced models
  • Added helper methods for each model type (chat_table_name, message_table_name, etc.)
  • Updated migration template to use the new helper methods instead of .tableize

Testing

Tested with namespaced models to confirm:

  • Assistant::Chatassistant_chats
  • Assistant::Messageassistant_messages
  • Assistant::ToolCallassistant_tool_calls
  • Assistant::Modelassistant_models

Regular models continue to work as expected:

  • Chatchats
  • Messagemessages

Fixes #397

The upgrade generator was using .tableize which produces invalid table
names for namespaced models (e.g., 'assistant/chats' instead of
'assistant_chats'). This fix uses .underscore.pluralize.tr('/', '_')
to properly convert namespaced model names to valid table names.

Fixes crmne#397
@crmne
Copy link
Owner

crmne commented Sep 10, 2025

That was quick! Awesome!

@crmne crmne merged commit ad036e1 into crmne:main Sep 10, 2025
12 checks passed
@willcosgrove willcosgrove deleted the fix-namespaced-models-migration-397 branch September 10, 2025 17:25
Copy link

codecov bot commented Sep 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.17%. Comparing base (7f00d26) to head (818ac62).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #398   +/-   ##
=======================================
  Coverage   84.17%   84.17%           
=======================================
  Files          35       35           
  Lines        1889     1889           
  Branches      506      506           
=======================================
  Hits         1590     1590           
  Misses        299      299           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 this pull request may close these issues.

[BUG] 1.7 migration does not handle namespaced models
2 participants