@@ -23,6 +23,7 @@ import {
2323 vector ,
2424 year ,
2525} from 'drizzle-orm/singlestore-core' ;
26+ import { vectorIndex } from 'drizzle-orm/singlestore-core/indexes/vector' ;
2627import getPort from 'get-port' ;
2728import { Connection , createConnection } from 'mysql2/promise' ;
2829import { diffTestSchemasPushSingleStore , diffTestSchemasSingleStore } from 'tests/schemaDiffer' ;
@@ -264,7 +265,6 @@ const singlestoreSuite: DialectSuite = {
264265 'drizzle' ,
265266 false ,
266267 ) ;
267- console . log ( statements ) ;
268268 expect ( statements . length ) . toBe ( 0 ) ;
269269 expect ( statements ) . toEqual ( [ ] ) ;
270270
@@ -279,14 +279,96 @@ const singlestoreSuite: DialectSuite = {
279279 await context . client . query ( st ) ;
280280 }
281281 } ,
282- addBasicIndexes : function ( context ?: any ) : Promise < void > {
283- return { } as any ;
282+ addBasicIndexes : async function ( context ?: any ) : Promise < void > {
283+ const schema1 = {
284+ vectorIndex : singlestoreTable ( 'vector_table' , {
285+ v : vector ( 'v' , { dimensions : 10 } ) ,
286+ } ) ,
287+ } ;
288+
289+ const schema2 = {
290+ vectorIndex : singlestoreTable ( 'vector_table' , {
291+ v : vector ( 'v' , { dimensions : 10 } ) ,
292+ } , ( table ) => [
293+ vectorIndex ( 'vector_index' ) . on ( table . v ) ,
294+ ] ) ,
295+ } ;
296+
297+ const { statements, sqlStatements } = await diffTestSchemasPushSingleStore (
298+ context . client as Connection ,
299+ schema1 ,
300+ schema2 ,
301+ [ ] ,
302+ 'drizzle' ,
303+ false ,
304+ ) ;
305+ expect ( statements . length ) . toBe ( 1 ) ;
306+ expect ( statements [ 0 ] ) . toStrictEqual ( {
307+ schema : '' ,
308+ tableName : 'vector_table' ,
309+ type : 'create_vector_index' ,
310+ data : 'vector_index;v;AUTO;;;;;;;;' ,
311+ internal : {
312+ tables : { } ,
313+ indexes : { } ,
314+ } ,
315+ } ) ;
316+ expect ( sqlStatements . length ) . toBe ( 1 ) ;
317+ expect ( sqlStatements [ 0 ] ) . toBe (
318+ `ALTER TABLE \`vector_table\` ADD VECTOR INDEX \`vector_index\` (\`v\`) INDEX_OPTIONS '{"index_type":"AUTO"}';` ,
319+ ) ;
320+
321+ const { sqlStatements : dropStatements } = await diffTestSchemasSingleStore (
322+ schema2 ,
323+ { } ,
324+ [ ] ,
325+ false ,
326+ ) ;
327+
328+ for ( const st of dropStatements ) {
329+ await context . client . query ( st ) ;
330+ }
284331 } ,
285332 changeIndexFields : function ( context ?: any ) : Promise < void > {
286333 return { } as any ;
287334 } ,
288- dropIndex : function ( context ?: any ) : Promise < void > {
289- return { } as any ;
335+ dropIndex : async function ( context ?: any ) : Promise < void > {
336+ const schema1 = {
337+ vectorIndex : singlestoreTable ( 'vector_table' , {
338+ v : vector ( 'v' , { dimensions : 10 } ) ,
339+ } , ( table ) => [
340+ vectorIndex ( 'vector_index' ) . on ( table . v ) ,
341+ ] ) ,
342+ } ;
343+
344+ const schema2 = {
345+ vectorIndex : singlestoreTable ( 'vector_table' , {
346+ v : vector ( 'v' , { dimensions : 10 } ) ,
347+ } ) ,
348+ } ;
349+
350+ const { statements, sqlStatements } = await diffTestSchemasPushSingleStore (
351+ context . client as Connection ,
352+ schema1 ,
353+ schema2 ,
354+ [ ] ,
355+ 'drizzle' ,
356+ false ,
357+ ) ;
358+ console . log ( statements ) ;
359+ console . log ( sqlStatements ) ;
360+ expect ( statements . length ) . toBe ( 1 ) ;
361+
362+ const { sqlStatements : dropStatements } = await diffTestSchemasSingleStore (
363+ schema2 ,
364+ { } ,
365+ [ ] ,
366+ false ,
367+ ) ;
368+
369+ for ( const st of dropStatements ) {
370+ await context . client . query ( st ) ;
371+ }
290372 } ,
291373 indexesToBeNotTriggered : function ( context ?: any ) : Promise < void > {
292374 return { } as any ;
0 commit comments