@@ -1495,14 +1495,16 @@ public function testDropIndexByNameWithSchema()
14951495
14961496 public function testAddGistIndex (): void
14971497 {
1498+ // GiST indexes on text columns require an operator class.
1499+ // We use inet type which has built-in GiST support.
14981500 $ table = new Table ('table1 ' , [], $ this ->adapter );
1499- $ table ->addColumn ('data ' , 'text ' )
1501+ $ table ->addColumn ('ip_range ' , 'inet ' )
15001502 ->save ();
15011503
1502- $ table ->addIndex ('data ' , ['type ' => 'gist ' , ' opclass ' => [ ' data ' => ' gist_trgm_ops ' ] ])
1504+ $ table ->addIndex ('ip_range ' , ['type ' => 'gist ' ])
15031505 ->save ();
15041506
1505- $ this ->assertTrue ($ table ->hasIndex ('data ' ));
1507+ $ this ->assertTrue ($ table ->hasIndex ('ip_range ' ));
15061508
15071509 // Verify the index uses the GIST access method
15081510 $ rows = $ this ->adapter ->fetchAll (
@@ -1511,7 +1513,7 @@ public function testAddGistIndex(): void
15111513 JOIN pg_class c ON c.oid = i.indexrelid
15121514 JOIN pg_am am ON am.oid = c.relam
15131515 JOIN pg_class t ON t.oid = i.indrelid
1514- WHERE t.relname = 'table1' AND c.relname = 'table1_data' "
1516+ WHERE t.relname = 'table1' AND c.relname = 'table1_ip_range' " ,
15151517 );
15161518 $ this ->assertCount (1 , $ rows );
15171519 $ this ->assertEquals ('gist ' , $ rows [0 ]['access_method ' ]);
@@ -1535,7 +1537,7 @@ public function testAddGinIndex(): void
15351537 JOIN pg_class c ON c.oid = i.indexrelid
15361538 JOIN pg_am am ON am.oid = c.relam
15371539 JOIN pg_class t ON t.oid = i.indrelid
1538- WHERE t.relname = 'table1' AND c.relname = 'table1_tags' "
1540+ WHERE t.relname = 'table1' AND c.relname = 'table1_tags' ",
15391541 );
15401542 $ this ->assertCount (1 , $ rows );
15411543 $ this ->assertEquals ('gin ' , $ rows [0 ]['access_method ' ]);
@@ -1559,7 +1561,7 @@ public function testAddBrinIndex(): void
15591561 JOIN pg_class c ON c.oid = i.indexrelid
15601562 JOIN pg_am am ON am.oid = c.relam
15611563 JOIN pg_class t ON t.oid = i.indrelid
1562- WHERE t.relname = 'table1' AND c.relname = 'table1_created_at' "
1564+ WHERE t.relname = 'table1' AND c.relname = 'table1_created_at' ",
15631565 );
15641566 $ this ->assertCount (1 , $ rows );
15651567 $ this ->assertEquals ('brin ' , $ rows [0 ]['access_method ' ]);
@@ -1583,14 +1585,15 @@ public function testAddHashIndex(): void
15831585 JOIN pg_class c ON c.oid = i.indexrelid
15841586 JOIN pg_am am ON am.oid = c.relam
15851587 JOIN pg_class t ON t.oid = i.indrelid
1586- WHERE t.relname = 'table1' AND c.relname = 'table1_session_id' "
1588+ WHERE t.relname = 'table1' AND c.relname = 'table1_session_id' ",
15871589 );
15881590 $ this ->assertCount (1 , $ rows );
15891591 $ this ->assertEquals ('hash ' , $ rows [0 ]['access_method ' ]);
15901592 }
15911593
15921594 public function testAddSpgistIndex (): void
15931595 {
1596+ // SP-GiST indexes on text require the text_ops operator class
15941597 $ table = new Table ('table1 ' , [], $ this ->adapter );
15951598 $ table ->addColumn ('data ' , 'text ' )
15961599 ->save ();
@@ -1607,14 +1610,22 @@ public function testAddSpgistIndex(): void
16071610 JOIN pg_class c ON c.oid = i.indexrelid
16081611 JOIN pg_am am ON am.oid = c.relam
16091612 JOIN pg_class t ON t.oid = i.indrelid
1610- WHERE t.relname = 'table1' AND c.relname = 'table1_data' "
1613+ WHERE t.relname = 'table1' AND c.relname = 'table1_data' ",
16111614 );
16121615 $ this ->assertCount (1 , $ rows );
16131616 $ this ->assertEquals ('spgist ' , $ rows [0 ]['access_method ' ]);
16141617 }
16151618
16161619 public function testAddIndexWithOpclass (): void
16171620 {
1621+ // Test opclass with GiST using pg_trgm extension
1622+ // Skip if extension is not available
1623+ try {
1624+ $ this ->adapter ->execute ('CREATE EXTENSION IF NOT EXISTS pg_trgm ' );
1625+ } catch (\Exception $ e ) {
1626+ $ this ->markTestSkipped ('pg_trgm extension is not available ' );
1627+ }
1628+
16181629 $ table = new Table ('table1 ' , [], $ this ->adapter );
16191630 $ table ->addColumn ('name ' , 'string ' )
16201631 ->save ();
@@ -1633,7 +1644,7 @@ public function testAddIndexWithOpclass(): void
16331644 JOIN pg_class c ON c.oid = i.indexrelid
16341645 JOIN pg_am am ON am.oid = c.relam
16351646 JOIN pg_class t ON t.oid = i.indrelid
1636- WHERE t.relname = 'table1' AND c.relname = 'table1_name' "
1647+ WHERE t.relname = 'table1' AND c.relname = 'table1_name' ",
16371648 );
16381649 $ this ->assertCount (1 , $ rows );
16391650 $ this ->assertEquals ('gist ' , $ rows [0 ]['access_method ' ]);
0 commit comments