Commit ad036e1
authored
Fix namespaced model table names in upgrade generator (#398)
## 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:
```bash
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::Chat` → `assistant_chats` ✓
- `Assistant::Message` → `assistant_messages` ✓
- `Assistant::ToolCall` → `assistant_tool_calls` ✓
- `Assistant::Model` → `assistant_models` ✓
Regular models continue to work as expected:
- `Chat` → `chats` ✓
- `Message` → `messages` ✓
Fixes #3971 parent 3d57b9e commit ad036e1
File tree
2 files changed
+25
-15
lines changed- lib/generators/ruby_llm
- upgrade_to_v1_7/templates
2 files changed
+25
-15
lines changedLines changed: 13 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
| 9 | + | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
| 30 | + | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
| 137 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
48 | 54 | | |
49 | 55 | | |
50 | 56 | | |
51 | 57 | | |
52 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
53 | 63 | | |
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
57 | | - | |
| 67 | + | |
58 | 68 | | |
59 | | - | |
| 69 | + | |
60 | 70 | | |
61 | 71 | | |
62 | 72 | | |
| |||
0 commit comments