Skip to content

Commit 2e06f5b

Browse files
Merge branch 'issues' of https://github.com/drizzle-team/drizzle-orm into issues
2 parents 8cff5be + d65fe4b commit 2e06f5b

File tree

6 files changed

+197
-5
lines changed

6 files changed

+197
-5
lines changed

drizzle-kit/tests/cockroach/indexes.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { sql } from 'drizzle-orm';
2-
import { boolean, cockroachTable, index, int4, text, uuid } from 'drizzle-orm/cockroach-core';
2+
import { boolean, cockroachTable, index, int4, text, uniqueIndex, uuid } from 'drizzle-orm/cockroach-core';
33
import { expect } from 'vitest';
44
import { diff, push, test } from './mocks';
55

@@ -426,3 +426,45 @@ test.concurrent('index #3_1', async ({ dbc: db }) => {
426426
expect(st).toStrictEqual(st0);
427427
expect(pst).toStrictEqual(st0);
428428
});
429+
430+
// https://github.com/drizzle-team/drizzle-orm/issues/3255
431+
test('index #4', async ({ dbc: db }) => {
432+
const table1 = cockroachTable('table1', {
433+
col1: int4(),
434+
col2: int4(),
435+
}, () => [
436+
index1,
437+
index2,
438+
index3,
439+
index4,
440+
index5,
441+
index6,
442+
]);
443+
444+
const index1 = uniqueIndex('index1').on(table1.col1);
445+
const index2 = uniqueIndex('index2').on(table1.col1, table1.col2);
446+
const index3 = index('index3').on(table1.col1);
447+
const index4 = index('index4').on(table1.col1, table1.col2);
448+
const index5 = index('index5').on(sql`${table1.col1} asc`);
449+
const index6 = index('index6').on(sql`${table1.col1} asc`, sql`${table1.col2} desc`);
450+
451+
const schema1 = { table1 };
452+
453+
const { sqlStatements: st1 } = await diff({}, schema1, []);
454+
const { sqlStatements: pst1 } = await push({ db, to: schema1 });
455+
456+
const expectedSt1 = [
457+
'CREATE TABLE "table1" (\n'
458+
+ '\t"col1" int4,\n'
459+
+ '\t"col2" int4,\n'
460+
+ '\tCONSTRAINT "index1" UNIQUE("col1"),\n'
461+
+ '\tCONSTRAINT "index2" UNIQUE("col1","col2")\n'
462+
+ ');\n',
463+
'CREATE INDEX "index3" ON "table1" ("col1");',
464+
'CREATE INDEX "index4" ON "table1" ("col1","col2");',
465+
'CREATE INDEX "index5" ON "table1" ("col1" asc);',
466+
'CREATE INDEX "index6" ON "table1" ("col1" asc,"col2" desc);',
467+
];
468+
expect(st1).toStrictEqual(expectedSt1);
469+
expect(pst1).toStrictEqual(expectedSt1);
470+
});

drizzle-kit/tests/mssql/indexes.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { sql } from 'drizzle-orm';
2-
import { bit, index, int, mssqlTable, text, varchar } from 'drizzle-orm/mssql-core';
2+
import { bit, index, int, mssqlTable, text, uniqueIndex, varchar } from 'drizzle-orm/mssql-core';
33
import { DB } from 'src/utils';
44
import { afterAll, beforeAll, beforeEach, expect, test } from 'vitest';
55
import { diff, prepareTestDatabase, push, TestDatabase } from './mocks';
@@ -89,6 +89,48 @@ test('indexes #0', async (t) => {
8989
]);
9090
});
9191

92+
// https://github.com/drizzle-team/drizzle-orm/issues/3255
93+
test('indexes #2', async () => {
94+
const table1 = mssqlTable('table1', {
95+
col1: int(),
96+
col2: int(),
97+
}, () => [
98+
index1,
99+
index2,
100+
index3,
101+
index4,
102+
index5,
103+
index6,
104+
]);
105+
106+
const index1 = uniqueIndex('index1').on(table1.col1);
107+
const index2 = uniqueIndex('index2').on(table1.col1, table1.col2);
108+
const index3 = index('index3').on(table1.col1);
109+
const index4 = index('index4').on(table1.col1, table1.col2);
110+
const index5 = index('index5').on(sql`${table1.col1} asc`);
111+
const index6 = index('index6').on(sql`${table1.col1} asc`, sql`${table1.col2} desc`);
112+
113+
const schema1 = { table1 };
114+
115+
const { sqlStatements: st1 } = await diff({}, schema1, []);
116+
const { sqlStatements: pst1 } = await push({ db, to: schema1 });
117+
118+
const expectedSt1 = [
119+
'CREATE TABLE `table1` (\n'
120+
+ '\t`col1` int,\n'
121+
+ '\t`col2` int,\n'
122+
+ '\tCONSTRAINT `index1` UNIQUE INDEX(`col1`),\n'
123+
+ '\tCONSTRAINT `index2` UNIQUE INDEX(`col1`,`col2`)\n'
124+
+ ');\n',
125+
'CREATE INDEX `index3` ON `table1` (`col1`);',
126+
'CREATE INDEX `index4` ON `table1` (`col1`,`col2`);',
127+
'CREATE INDEX `index5` ON `table1` (`col1` asc);',
128+
'CREATE INDEX `index6` ON `table1` (`col1` asc,`col2` desc);',
129+
];
130+
expect(st1).toStrictEqual(expectedSt1);
131+
expect(pst1).toStrictEqual(expectedSt1);
132+
});
133+
92134
test('adding basic indexes', async () => {
93135
const schema1 = {
94136
users: mssqlTable('users', {

drizzle-kit/tests/mysql/constraints.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,8 @@ test('index #1', async () => {
553553
const index5 = index('index5').on(sql`${table1.col1} asc`);
554554
const index6 = index('index6').on(sql`${table1.col1} asc`, sql`${table1.col2} desc`);
555555

556-
const schema1 = { table1, index1, index2, index3, index4, index5, index6 };
556+
const schema1 = { table1 };
557557

558-
throw new Error(`it's needed to fix ts error below`);
559558
const { sqlStatements: st1 } = await diff({}, schema1, []);
560559
const { sqlStatements: pst1 } = await push({ db, to: schema1 });
561560

drizzle-kit/tests/postgres/pull.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ test('basic policy with "using" and "with"', async () => {
887887
expect(sqlStatements.length).toBe(0);
888888
});
889889

890-
test('multiple policies', async () => {
890+
test('multiple policies #1', async () => {
891891
const schema = {
892892
users: pgTable('users', {
893893
id: integer('id').primaryKey(),
@@ -904,6 +904,30 @@ test('multiple policies', async () => {
904904
expect(sqlStatements.length).toBe(0);
905905
});
906906

907+
// https://github.com/drizzle-team/drizzle-orm/issues/4407
908+
test('multiple policies #2', async () => {
909+
const users = pgTable('users', {
910+
id: integer(),
911+
}, (table) => [
912+
pgPolicy('insert_policy_for_users', { for: 'insert', withCheck: sql`true` }),
913+
pgPolicy('update_policy_for_users', { for: 'update', using: sql`true`, withCheck: sql`true` }),
914+
]);
915+
const schema = {
916+
users: pgTable('users', {
917+
id: integer('id').primaryKey(),
918+
}, () => [pgPolicy('test', { using: sql`true`, withCheck: sql`true` }), pgPolicy('newRls')]),
919+
};
920+
921+
const { statements, sqlStatements } = await diffIntrospect(
922+
db,
923+
schema,
924+
'multiple-policies-2',
925+
);
926+
927+
expect(statements.length).toBe(0);
928+
expect(sqlStatements.length).toBe(0);
929+
});
930+
907931
test('multiple policies with roles', async () => {
908932
db.query(`CREATE ROLE manager;`);
909933

drizzle-kit/tests/singlestore/singlestore.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,46 @@ test('add table with indexes', async () => {
419419
]);
420420
});
421421

422+
// https://github.com/drizzle-team/drizzle-orm/issues/3255
423+
test('index #1', async () => {
424+
const table1 = singlestoreTable('table1', {
425+
col1: int(),
426+
col2: int(),
427+
}, () => [
428+
index1,
429+
index2,
430+
index3,
431+
index4,
432+
index5,
433+
index6,
434+
]);
435+
436+
const index1 = uniqueIndex('index1').on(table1.col1);
437+
const index2 = uniqueIndex('index2').on(table1.col1, table1.col2);
438+
const index3 = index('index3').on(table1.col1);
439+
const index4 = index('index4').on(table1.col1, table1.col2);
440+
const index5 = index('index5').on(sql`${table1.col1} asc`);
441+
const index6 = index('index6').on(sql`${table1.col1} asc`, sql`${table1.col2} desc`);
442+
443+
const schema1 = { table1 };
444+
445+
const { sqlStatements: st1 } = await diff({}, schema1, []);
446+
447+
const expectedSt1 = [
448+
'CREATE TABLE `table1` (\n'
449+
+ '\t`col1` int,\n'
450+
+ '\t`col2` int,\n'
451+
+ '\tCONSTRAINT `index1` UNIQUE INDEX(`col1`),\n'
452+
+ '\tCONSTRAINT `index2` UNIQUE INDEX(`col1`,`col2`)\n'
453+
+ ');\n',
454+
'CREATE INDEX `index3` ON `table1` (`col1`);',
455+
'CREATE INDEX `index4` ON `table1` (`col1`,`col2`);',
456+
'CREATE INDEX `index5` ON `table1` (`col1` asc);',
457+
'CREATE INDEX `index6` ON `table1` (`col1` asc,`col2` desc);',
458+
];
459+
expect(st1).toStrictEqual(expectedSt1);
460+
});
461+
422462
test('rename table', async () => {
423463
const from = {
424464
table: singlestoreTable('table', {

drizzle-kit/tests/sqlite/sqlite-constraints.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import { sql } from 'drizzle-orm';
12
import {
23
AnySQLiteColumn,
34
foreignKey,
45
index,
56
int,
7+
integer,
68
primaryKey,
79
sqliteTable,
810
text,
911
unique,
12+
uniqueIndex,
1013
} from 'drizzle-orm/sqlite-core';
1114
import { afterAll, beforeAll, beforeEach, expect, test } from 'vitest';
1215
import { diff, drizzleToDDL, prepareTestDatabase, push, TestDatabase } from './mocks';
@@ -1772,3 +1775,45 @@ test('fk multistep #2', async () => {
17721775
expect(st3).toStrictEqual([]);
17731776
expect(pst3).toStrictEqual([]);
17741777
});
1778+
1779+
// https://github.com/drizzle-team/drizzle-orm/issues/3255
1780+
test('index #1', async () => {
1781+
const table1 = sqliteTable('table1', {
1782+
col1: integer(),
1783+
col2: integer(),
1784+
}, () => [
1785+
index1,
1786+
index2,
1787+
index3,
1788+
index4,
1789+
index5,
1790+
index6,
1791+
]);
1792+
1793+
const index1 = uniqueIndex('index1').on(table1.col1);
1794+
const index2 = uniqueIndex('index2').on(table1.col1, table1.col2);
1795+
const index3 = index('index3').on(table1.col1);
1796+
const index4 = index('index4').on(table1.col1, table1.col2);
1797+
const index5 = index('index5').on(sql`${table1.col1} asc`);
1798+
const index6 = index('index6').on(sql`${table1.col1} asc`, sql`${table1.col2} desc`);
1799+
1800+
const schema1 = { table1 };
1801+
1802+
const { sqlStatements: st1 } = await diff({}, schema1, []);
1803+
const { sqlStatements: pst1 } = await push({ db, to: schema1 });
1804+
1805+
const expectedSt1 = [
1806+
'CREATE TABLE `table1` (\n'
1807+
+ '\t`col1` integer,\n'
1808+
+ '\t`col2` integer\n'
1809+
+ ');\n',
1810+
'CREATE UNIQUE INDEX `index1` ON `table1` (`col1`);',
1811+
'CREATE UNIQUE INDEX `index2` ON `table1` (`col1`,`col2`);',
1812+
'CREATE INDEX `index3` ON `table1` (`col1`);',
1813+
'CREATE INDEX `index4` ON `table1` (`col1`,`col2`);',
1814+
'CREATE INDEX `index5` ON `table1` (`col1` asc);',
1815+
'CREATE INDEX `index6` ON `table1` (`col1` asc,`col2` desc);',
1816+
];
1817+
expect(st1).toStrictEqual(expectedSt1);
1818+
expect(pst1).toStrictEqual(expectedSt1);
1819+
});

0 commit comments

Comments
 (0)