@@ -1499,14 +1499,16 @@ public function testDropIndexByNameWithSchema(): void
14991499
15001500 public function testAddGistIndex (): void
15011501 {
1502+ // GiST indexes on text columns require an operator class.
1503+ // We use inet type which has built-in GiST support.
15021504 $ table = new Table ('table1 ' , [], $ this ->adapter );
1503- $ table ->addColumn ('data ' , 'text ' )
1505+ $ table ->addColumn ('ip_range ' , 'inet ' )
15041506 ->save ();
15051507
1506- $ table ->addIndex ('data ' , ['type ' => 'gist ' , ' opclass ' => [ ' data ' => ' gist_trgm_ops ' ] ])
1508+ $ table ->addIndex ('ip_range ' , ['type ' => 'gist ' ])
15071509 ->save ();
15081510
1509- $ this ->assertTrue ($ table ->hasIndex ('data ' ));
1511+ $ this ->assertTrue ($ table ->hasIndex ('ip_range ' ));
15101512
15111513 // Verify the index uses the GIST access method
15121514 $ rows = $ this ->adapter ->fetchAll (
@@ -1515,7 +1517,7 @@ public function testAddGistIndex(): void
15151517 JOIN pg_class c ON c.oid = i.indexrelid
15161518 JOIN pg_am am ON am.oid = c.relam
15171519 JOIN pg_class t ON t.oid = i.indrelid
1518- WHERE t.relname = 'table1' AND c.relname = 'table1_data' "
1520+ WHERE t.relname = 'table1' AND c.relname = 'table1_ip_range' " ,
15191521 );
15201522 $ this ->assertCount (1 , $ rows );
15211523 $ this ->assertEquals ('gist ' , $ rows [0 ]['access_method ' ]);
@@ -1539,7 +1541,7 @@ public function testAddGinIndex(): void
15391541 JOIN pg_class c ON c.oid = i.indexrelid
15401542 JOIN pg_am am ON am.oid = c.relam
15411543 JOIN pg_class t ON t.oid = i.indrelid
1542- WHERE t.relname = 'table1' AND c.relname = 'table1_tags' "
1544+ WHERE t.relname = 'table1' AND c.relname = 'table1_tags' ",
15431545 );
15441546 $ this ->assertCount (1 , $ rows );
15451547 $ this ->assertEquals ('gin ' , $ rows [0 ]['access_method ' ]);
@@ -1563,7 +1565,7 @@ public function testAddBrinIndex(): void
15631565 JOIN pg_class c ON c.oid = i.indexrelid
15641566 JOIN pg_am am ON am.oid = c.relam
15651567 JOIN pg_class t ON t.oid = i.indrelid
1566- WHERE t.relname = 'table1' AND c.relname = 'table1_created_at' "
1568+ WHERE t.relname = 'table1' AND c.relname = 'table1_created_at' ",
15671569 );
15681570 $ this ->assertCount (1 , $ rows );
15691571 $ this ->assertEquals ('brin ' , $ rows [0 ]['access_method ' ]);
@@ -1587,14 +1589,15 @@ public function testAddHashIndex(): void
15871589 JOIN pg_class c ON c.oid = i.indexrelid
15881590 JOIN pg_am am ON am.oid = c.relam
15891591 JOIN pg_class t ON t.oid = i.indrelid
1590- WHERE t.relname = 'table1' AND c.relname = 'table1_session_id' "
1592+ WHERE t.relname = 'table1' AND c.relname = 'table1_session_id' ",
15911593 );
15921594 $ this ->assertCount (1 , $ rows );
15931595 $ this ->assertEquals ('hash ' , $ rows [0 ]['access_method ' ]);
15941596 }
15951597
15961598 public function testAddSpgistIndex (): void
15971599 {
1600+ // SP-GiST indexes on text require the text_ops operator class
15981601 $ table = new Table ('table1 ' , [], $ this ->adapter );
15991602 $ table ->addColumn ('data ' , 'text ' )
16001603 ->save ();
@@ -1611,14 +1614,22 @@ public function testAddSpgistIndex(): void
16111614 JOIN pg_class c ON c.oid = i.indexrelid
16121615 JOIN pg_am am ON am.oid = c.relam
16131616 JOIN pg_class t ON t.oid = i.indrelid
1614- WHERE t.relname = 'table1' AND c.relname = 'table1_data' "
1617+ WHERE t.relname = 'table1' AND c.relname = 'table1_data' ",
16151618 );
16161619 $ this ->assertCount (1 , $ rows );
16171620 $ this ->assertEquals ('spgist ' , $ rows [0 ]['access_method ' ]);
16181621 }
16191622
16201623 public function testAddIndexWithOpclass (): void
16211624 {
1625+ // Test opclass with GiST using pg_trgm extension
1626+ // Skip if extension is not available
1627+ try {
1628+ $ this ->adapter ->execute ('CREATE EXTENSION IF NOT EXISTS pg_trgm ' );
1629+ } catch (\Exception $ e ) {
1630+ $ this ->markTestSkipped ('pg_trgm extension is not available ' );
1631+ }
1632+
16221633 $ table = new Table ('table1 ' , [], $ this ->adapter );
16231634 $ table ->addColumn ('name ' , 'string ' )
16241635 ->save ();
@@ -1637,7 +1648,7 @@ public function testAddIndexWithOpclass(): void
16371648 JOIN pg_class c ON c.oid = i.indexrelid
16381649 JOIN pg_am am ON am.oid = c.relam
16391650 JOIN pg_class t ON t.oid = i.indrelid
1640- WHERE t.relname = 'table1' AND c.relname = 'table1_name' "
1651+ WHERE t.relname = 'table1' AND c.relname = 'table1_name' ",
16411652 );
16421653 $ this ->assertCount (1 , $ rows );
16431654 $ this ->assertEquals ('gist ' , $ rows [0 ]['access_method ' ]);
0 commit comments