88use Cake \Console \TestSuite \StubConsoleOutput ;
99use Cake \Database \Connection ;
1010use Cake \Datasource \ConnectionManager ;
11+ use Exception ;
1112use InvalidArgumentException ;
1213use Migrations \Db \Adapter \AdapterInterface ;
1314use Migrations \Db \Adapter \PostgresAdapter ;
@@ -1495,16 +1496,15 @@ public function testDropIndexByNameWithSchema()
14951496
14961497 public function testAddGistIndex (): void
14971498 {
1498- // GiST indexes on text columns require an operator class.
1499- // We use inet type which has built-in GiST support.
1500- $ table = new Table ('table1 ' , [], $ this ->adapter );
1501- $ table ->addColumn ('ip_range ' , 'inet ' )
1502- ->save ();
1499+ // GiST indexes require specific data types with GiST support.
1500+ // We use int4range which has built-in GiST support in PostgreSQL.
1501+ $ this ->adapter ->execute ('CREATE TABLE table1 (id SERIAL PRIMARY KEY, int_range int4range) ' );
15031502
1504- $ table ->addIndex ('ip_range ' , ['type ' => 'gist ' ])
1503+ $ table = new Table ('table1 ' , [], $ this ->adapter );
1504+ $ table ->addIndex ('int_range ' , ['type ' => 'gist ' ])
15051505 ->save ();
15061506
1507- $ this ->assertTrue ($ table ->hasIndex ('ip_range ' ));
1507+ $ this ->assertTrue ($ table ->hasIndex ('int_range ' ));
15081508
15091509 // Verify the index uses the GIST access method
15101510 $ rows = $ this ->adapter ->fetchAll (
@@ -1513,7 +1513,7 @@ public function testAddGistIndex(): void
15131513 JOIN pg_class c ON c.oid = i.indexrelid
15141514 JOIN pg_am am ON am.oid = c.relam
15151515 JOIN pg_class t ON t.oid = i.indrelid
1516- WHERE t.relname = 'table1' AND c.relname = 'table1_ip_range ' " ,
1516+ WHERE t.relname = 'table1' AND c.relname = 'table1_int_range ' " ,
15171517 );
15181518 $ this ->assertCount (1 , $ rows );
15191519 $ this ->assertEquals ('gist ' , $ rows [0 ]['access_method ' ]);
@@ -1622,7 +1622,7 @@ public function testAddIndexWithOpclass(): void
16221622 // Skip if extension is not available
16231623 try {
16241624 $ this ->adapter ->execute ('CREATE EXTENSION IF NOT EXISTS pg_trgm ' );
1625- } catch (\ Exception $ e ) {
1625+ } catch (Exception $ e ) {
16261626 $ this ->markTestSkipped ('pg_trgm extension is not available ' );
16271627 }
16281628
0 commit comments