MCPcopy
hub / github.com/drizzle-team/drizzle-orm / changeIndexFields

Function changeIndexFields

drizzle-kit/tests/push/pg.test.ts:569–634  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

567 },
568
569 async changeIndexFields() {
570 const client = new PGlite();
571
572 const schema1 = {
573 users: pgTable(
574 'users',
575 {
576 id: serial('id').primaryKey(),
577 name: text('name'),
578 },
579 (t) => ({
580 removeColumn: index('removeColumn').on(t.name, t.id),
581 addColumn: index('addColumn').on(t.name.desc()).with({ fillfactor: 70 }),
582 removeExpression: index('removeExpression')
583 .on(t.name.desc(), sql`name`)
584 .concurrently(),
585 addExpression: index('addExpression').on(t.id.desc()),
586 changeExpression: index('changeExpression').on(t.id.desc(), sql`name`),
587 changeName: index('changeName').on(t.name.desc(), t.id.asc().nullsLast()).with({ fillfactor: 70 }),
588 changeWith: index('changeWith').on(t.name).with({ fillfactor: 70 }),
589 changeUsing: index('changeUsing').on(t.name),
590 }),
591 ),
592 };
593
594 const schema2 = {
595 users: pgTable(
596 'users',
597 {
598 id: serial('id').primaryKey(),
599 name: text('name'),
600 },
601 (t) => ({
602 removeColumn: index('removeColumn').on(t.name),
603 addColumn: index('addColumn').on(t.name.desc(), t.id.nullsLast()).with({ fillfactor: 70 }),
604 removeExpression: index('removeExpression').on(t.name.desc()).concurrently(),
605 addExpression: index('addExpression').on(t.id.desc()),
606 changeExpression: index('changeExpression').on(t.id.desc(), sql`name desc`),
607 changeName: index('newName')
608 .on(t.name.desc(), sql`name`)
609 .with({ fillfactor: 70 }),
610 changeWith: index('changeWith').on(t.name).with({ fillfactor: 90 }),
611 changeUsing: index('changeUsing').using('hash', t.name),
612 }),
613 ),
614 };
615
616 const { statements, sqlStatements } = await diffTestSchemasPush(client, schema1, schema2, [], false, ['public']);
617
618 expect(sqlStatements).toStrictEqual([
619 'DROP INDEX "changeName";',
620 'DROP INDEX "addColumn";',
621 'DROP INDEX "changeExpression";',
622 'DROP INDEX "changeUsing";',
623 'DROP INDEX "changeWith";',
624 'DROP INDEX "removeColumn";',
625 'DROP INDEX "removeExpression";',
626 'CREATE INDEX "newName" ON "users" USING btree ("name" DESC NULLS LAST,name) WITH (fillfactor=70);',

Callers

nothing calls this directly

Calls 13

pgTableFunction · 0.90
serialFunction · 0.90
textFunction · 0.90
indexFunction · 0.90
sqlFunction · 0.90
diffTestSchemasPushFunction · 0.90
onMethod · 0.45
withMethod · 0.45
descMethod · 0.45
concurrentlyMethod · 0.45
nullsLastMethod · 0.45
ascMethod · 0.45

Tested by

no test coverage detected