|
15 | 15 | 'create_chats_migration.rb.tt', |
16 | 16 | 'create_messages_migration.rb.tt', |
17 | 17 | 'create_tool_calls_migration.rb.tt', |
18 | | - 'create_models_migration.rb.tt' |
| 18 | + 'create_models_migration.rb.tt', |
| 19 | + 'add_references_to_chats_tool_calls_and_messages_migration.rb.tt' |
19 | 20 | ] |
20 | 21 | end |
21 | 22 |
|
|
31 | 32 | it 'defines chats table' do |
32 | 33 | expect(chat_migration).to include('create_table :<%= chat_table_name %>') |
33 | 34 | end |
34 | | - |
35 | | - it 'includes model reference' do |
36 | | - expect(chat_migration).to include('t.references :<%= model_table_name.singularize %>') |
37 | | - end |
38 | 35 | end |
39 | 36 |
|
40 | 37 | describe 'messages migration' do |
|
44 | 41 | expect(message_migration).to include('create_table :<%= message_table_name %>') |
45 | 42 | end |
46 | 43 |
|
47 | | - it 'includes chat reference' do |
48 | | - expect(message_migration).to include('t.references :<%= chat_table_name.singularize %>, null: false, foreign_key: true') # rubocop:disable Layout/LineLength |
49 | | - end |
50 | | - |
51 | 44 | it 'includes role field' do |
52 | 45 | expect(message_migration).to include('t.string :role') |
53 | 46 | end |
|
72 | 65 | expect(tool_call_migration).to include('t.string :name') |
73 | 66 | end |
74 | 67 | end |
| 68 | + |
| 69 | + describe 'add references migration' do |
| 70 | + let(:add_references_migration) do |
| 71 | + File.read(File.join(template_dir, 'add_references_to_chats_tool_calls_and_messages_migration.rb.tt')) |
| 72 | + end |
| 73 | + |
| 74 | + it 'adds model reference to chats' do |
| 75 | + expect(add_references_migration).to include('add_reference :<%= chat_table_name %>, ' \ |
| 76 | + ':<%= model_table_name.singularize %>, foreign_key: true') |
| 77 | + end |
| 78 | + |
| 79 | + it 'adds message reference to tool_calls' do |
| 80 | + expect(add_references_migration).to include('add_reference :<%= tool_call_table_name %>, ' \ |
| 81 | + ':<%= message_table_name.singularize %>, ' \ |
| 82 | + 'null: false, foreign_key: true') |
| 83 | + end |
| 84 | + |
| 85 | + it 'adds chat reference to messages' do |
| 86 | + expect(add_references_migration).to include('add_reference :<%= message_table_name %>, ' \ |
| 87 | + ':<%= chat_table_name.singularize %>, ' \ |
| 88 | + 'null: false, foreign_key: true') |
| 89 | + end |
| 90 | + |
| 91 | + it 'adds model reference to messages' do |
| 92 | + expect(add_references_migration).to include('add_reference :<%= message_table_name %>, ' \ |
| 93 | + ':<%= model_table_name.singularize %>, foreign_key: true') |
| 94 | + end |
| 95 | + |
| 96 | + it 'adds tool_call reference to messages' do |
| 97 | + expect(add_references_migration).to include('add_reference :<%= message_table_name %>, ' \ |
| 98 | + ':<%= tool_call_table_name.singularize %>, foreign_key: true') |
| 99 | + end |
| 100 | + end |
75 | 101 | end |
76 | 102 |
|
77 | 103 | describe 'JSON handling in migrations' do |
|
257 | 283 | expect(models_position).to be > tool_calls_position if models_position |
258 | 284 | end |
259 | 285 |
|
260 | | - it 'has comments explaining the order' do |
| 286 | + it 'adds references after creating all tables' do |
261 | 287 | migration_section = generator_content[/def create_migration_files.*?\n end/m] |
262 | | - expect(migration_section).to include('must come before tool_calls due to foreign key') |
263 | | - expect(migration_section).to include('references messages') |
| 288 | + |
| 289 | + add_references_position = migration_section.index( |
| 290 | + 'add_references_to_chats_tool_calls_and_messages_migration.rb.tt' |
| 291 | + ) |
| 292 | + models_position = migration_section.index('model_table_name') |
| 293 | + |
| 294 | + expect(add_references_position).not_to be_nil |
| 295 | + expect(models_position).not_to be_nil |
| 296 | + |
| 297 | + expect(add_references_position).to be > models_position |
264 | 298 | end |
265 | 299 | end |
266 | 300 |
|
|
0 commit comments