@@ -274,6 +274,71 @@ class IndexMigrationBookByNameIndex < ParadeDB::Index
274274 assert_not index_exists? ( "books_custom_bm25_idx" )
275275 end
276276
277+ it "supports the paradedb-named alias helpers end-to-end" do
278+ conn = ActiveRecord ::Base . connection
279+ conn . remove_paradedb_index ( :books , if_exists : true )
280+ conn . remove_paradedb_index ( :books , name : :books_alias_idx , if_exists : true )
281+
282+ conn . add_paradedb_index (
283+ :books ,
284+ fields : {
285+ id : { } ,
286+ title : { tokenizer : ParadeDB ::Tokenizer . simple ( ) }
287+ } ,
288+ key_field : :id ,
289+ name : :books_alias_idx ,
290+ am : paradedb_test_am
291+ )
292+ assert index_exists? ( "books_alias_idx" )
293+
294+ conn . reindex_paradedb_index ( :books , name : :books_alias_idx )
295+
296+ conn . remove_paradedb_index ( :books , name : :books_alias_idx )
297+ assert_not index_exists? ( "books_alias_idx" )
298+ end
299+
300+ it "rolls back add_paradedb_index in change migrations" do
301+ conn = ActiveRecord ::Base . connection
302+ conn . remove_paradedb_index ( :books , if_exists : true )
303+ conn . remove_paradedb_index ( :books , name : :books_alias_idx , if_exists : true )
304+
305+ migration = build_change_migration do
306+ add_paradedb_index (
307+ :books ,
308+ fields : {
309+ id : { } ,
310+ title : { tokenizer : ParadeDB ::Tokenizer . simple ( ) }
311+ } ,
312+ key_field : :id ,
313+ name : :books_alias_idx ,
314+ am : paradedb_test_am ,
315+ if_not_exists : true
316+ )
317+ end
318+
319+ run_migration ( migration , :up , connection : conn )
320+ assert index_exists? ( "books_alias_idx" )
321+
322+ run_migration ( migration , :down , connection : conn )
323+ assert_not index_exists? ( "books_alias_idx" )
324+ end
325+
326+ it "raises for remove_paradedb_index in change migrations" do
327+ conn = ActiveRecord ::Base . connection
328+
329+ migration = build_change_migration do
330+ remove_paradedb_index ( :books , if_exists : true )
331+ end
332+
333+ run_migration ( migration , :up , connection : conn )
334+ assert_not index_exists? ( "books_bm25_idx" )
335+
336+ error = assert_raises ( ActiveRecord ::IrreversibleMigration ) do
337+ run_migration ( migration , :down , connection : conn )
338+ end
339+ assert_includes error . message , "remove_paradedb_index"
340+ end
341+
277342 it "raises for remove_bm25_index in change migrations" do
278343 conn = ActiveRecord ::Base . connection
279344
@@ -399,13 +464,13 @@ class IndexMigrationBookByNameIndex < ParadeDB::Index
399464 schema = stream . string
400465
401466 add_stmt = schema . each_line . find do |line |
402- line . include? ( "add_bm25_index :books" ) &&
467+ line . include? ( "add_paradedb_index :books" ) &&
403468 line . include? ( "title_simple" ) &&
404469 line . include? ( "target_segment_count" )
405470 end
406471
407472 assert_equal <<~RUBY . strip , add_stmt . to_s . strip
408- add_bm25_index :books, fields: { id: {}, title: { tokenizer: ParadeDB::Tokenizer.simple(options: { :alias => "title_simple" }) } }, key_field: :id, name: "books_bm25_idx", index_options: { :target_segment_count => 17 }#{ paradedb_test_am_dump_suffix }
473+ add_paradedb_index :books, fields: { id: {}, title: { tokenizer: ParadeDB::Tokenizer.simple(options: { :alias => "title_simple" }) } }, key_field: :id, name: "books_bm25_idx", index_options: { :target_segment_count => 17 }#{ paradedb_test_am_dump_suffix }
409474 RUBY
410475 expect ( schema ) . not_to match ( /add_index.*books_bm25_idx/ )
411476 expect ( schema ) . not_to match ( /t\. index.*books_bm25_idx/ )
@@ -497,13 +562,13 @@ class IndexMigrationBookByNameIndex < ParadeDB::Index
497562 ActiveRecord ::SchemaDumper . dump ( ActiveRecord ::Base . connection_pool , stream )
498563 schema = stream . string
499564 add_stmt = schema . each_line . find do |line |
500- line . include? ( "add_bm25_index :books" ) &&
565+ line . include? ( "add_paradedb_index :books" ) &&
501566 line . include? ( "title_simple" ) &&
502567 line . include? ( "target_segment_count" )
503568 end
504569
505570 assert_equal <<~RUBY . strip , add_stmt . to_s . strip
506- add_bm25_index :books, fields: { id: {}, title: { tokenizers: [ParadeDB::Tokenizer.literal(), ParadeDB::Tokenizer.simple(options: { :alias => "title_simple" })] } }, key_field: :id, name: "books_bm25_idx", index_options: { :target_segment_count => 17 }#{ paradedb_test_am_dump_suffix }
571+ add_paradedb_index :books, fields: { id: {}, title: { tokenizers: [ParadeDB::Tokenizer.literal(), ParadeDB::Tokenizer.simple(options: { :alias => "title_simple" })] } }, key_field: :id, name: "books_bm25_idx", index_options: { :target_segment_count => 17 }#{ paradedb_test_am_dump_suffix }
507572 RUBY
508573
509574 conn . remove_bm25_index ( :books , if_exists : true )
@@ -532,11 +597,11 @@ class IndexMigrationBookByNameIndex < ParadeDB::Index
532597 ActiveRecord ::SchemaDumper . dump ( ActiveRecord ::Base . connection_pool , stream )
533598 schema = stream . string
534599 add_stmt = schema . each_line . find do |line |
535- line . include? ( "add_bm25_index :books" ) && line . include? ( "metadata_title_text" )
600+ line . include? ( "add_paradedb_index :books" ) && line . include? ( "metadata_title_text" )
536601 end
537602
538603 assert_equal <<~RUBY . strip , add_stmt . to_s . strip
539- add_bm25_index :books, fields: { id: {}, "metadata ->> 'title'::text" => { tokenizer: ParadeDB::Tokenizer.simple(options: { :lowercase => true, :alias => "metadata_title_text" }) } }, key_field: :id, name: "books_bm25_idx"#{ paradedb_test_am_dump_suffix }
604+ add_paradedb_index :books, fields: { id: {}, "metadata ->> 'title'::text" => { tokenizer: ParadeDB::Tokenizer.simple(options: { :lowercase => true, :alias => "metadata_title_text" }) } }, key_field: :id, name: "books_bm25_idx"#{ paradedb_test_am_dump_suffix }
540605 RUBY
541606
542607 conn . remove_bm25_index ( :books , if_exists : true )
@@ -564,13 +629,13 @@ class IndexMigrationBookByNameIndex < ParadeDB::Index
564629 ActiveRecord ::SchemaDumper . dump ( ActiveRecord ::Base . connection_pool , stream )
565630 schema = stream . string
566631 add_stmt = schema . each_line . find do |line |
567- line . include? ( "add_bm25_index :books" ) &&
632+ line . include? ( "add_paradedb_index :books" ) &&
568633 line . include? ( "title_simple" ) &&
569634 line . include? ( "where:" )
570635 end
571636
572637 assert_equal <<~RUBY . strip , add_stmt . to_s . strip
573- add_bm25_index :books, fields: { id: {}, title: { tokenizer: ParadeDB::Tokenizer.simple(options: { :alias => "title_simple" }) } }, key_field: :id, name: "books_bm25_idx", where: "author IS NOT NULL"#{ paradedb_test_am_dump_suffix }
638+ add_paradedb_index :books, fields: { id: {}, title: { tokenizer: ParadeDB::Tokenizer.simple(options: { :alias => "title_simple" }) } }, key_field: :id, name: "books_bm25_idx", where: "author IS NOT NULL"#{ paradedb_test_am_dump_suffix }
574639 RUBY
575640
576641 conn . remove_bm25_index ( :books , if_exists : true )
0 commit comments