Skip to content

Commit 42d222b

Browse files
committed
Merge branch 'issues2' of https://github.com/drizzle-team/drizzle-orm into issues2
2 parents ba666ff + b295f84 commit 42d222b

File tree

17 files changed

+210
-50
lines changed

17 files changed

+210
-50
lines changed

changelogs/drizzle-kit/1.0.0-beta.19.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- [[BUG]: drizzle-kit push attempts to drop policies in excluded schemas (e.g. cron) despite schemaFilter: ["public"]](https://github.com/drizzle-team/drizzle-orm/issues/5329)
44
- [[BUG]: error attempting to drizzle-kit migrate table with char array field generated using drizzle-kit generate](https://github.com/drizzle-team/drizzle-orm/issues/5370)
55
- [[BUG]: Ignore Vim *.swp files in drizzle-kit generate](https://github.com/drizzle-team/drizzle-orm/issues/4906)
6+
- [[BUG]: drizzle-kit pull outputs access method name instead of operator class for ivfflat indexes](https://github.com/drizzle-team/drizzle-orm/issues/5495)
67

78
## Updates
89
The behavior for reading schema files has been updated. From now only files with the following extensions will be processed: `.js` `.mjs` `.cjs` `.jsx` `.ts` `.mts` `.cts` `.tsx`

drizzle-kit/src/cli/commands/utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ export type GenerateConfig = {
9494

9595
export type ExportConfig = {
9696
dialect: Dialect;
97-
schema: string | string[];
9897
sql: boolean;
9998
casing?: CasingType;
10099
filenames: string[];
@@ -178,7 +177,6 @@ export const prepareExportConfig = async (
178177
return {
179178
casing: config.casing,
180179
dialect: dialect,
181-
schema: schema,
182180
sql: sql,
183181
filenames: fileNames,
184182
};

drizzle-kit/src/dialects/postgres/introspect.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ export const fromDatabase = async (
933933
expression: string | null;
934934
where: string;
935935
columnOrdinals: number[];
936-
opclasses: { oid: number | string; name: string; default: boolean }[];
936+
opclasses: { oid: number | string; access_method_name: string; op_class_name: string; default: boolean }[];
937937
options: number[];
938938
isUnique: boolean;
939939
isPrimary: boolean;
@@ -963,7 +963,8 @@ export const fromDatabase = async (
963963
SELECT
964964
pg_catalog.json_build_object(
965965
'oid', opclass.oid,
966-
'name', pg_am.amname,
966+
'access_method_name', pg_am.amname,
967+
'op_class_name', pg_opclass.opcname,
967968
'default', pg_opclass.opcdefault
968969
)
969970
FROM
@@ -1028,7 +1029,7 @@ export const fromDatabase = async (
10281029
| { type: 'expression'; value: string }
10291030
| { type: 'column'; value: DBColumn }
10301031
)
1031-
& { options: (typeof opts)[number]; opclass: { name: string; default: boolean } }
1032+
& { options: (typeof opts)[number]; opclass: { op_class_name: string; default: boolean } }
10321033
)[];
10331034

10341035
let k = 0;
@@ -1050,7 +1051,7 @@ export const fromDatabase = async (
10501051

10511052
// ! options and opclass can be undefined when index have "INCLUDE" columns (columns from "INCLUDE" don't have options and opclass)
10521053
const options = opts[i] as typeof opts[number] | undefined;
1053-
const opclass = metadata.opclasses[i] as { name: string; default: boolean } | undefined;
1054+
const opclass = metadata.opclasses[i] as { op_class_name: string; default: boolean } | undefined;
10541055
if (options && opclass) {
10551056
res.push({
10561057
type: 'column',
@@ -1067,7 +1068,7 @@ export const fromDatabase = async (
10671068
asc: !it.options.descending,
10681069
nullsFirst: it.options.nullsFirst,
10691070
opclass: it.opclass.default ? null : {
1070-
name: it.opclass.name,
1071+
name: it.opclass.op_class_name,
10711072
default: it.opclass.default,
10721073
},
10731074
isExpression: it.type === 'expression',

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,3 +906,25 @@ test('introspect cyclic foreign key', async () => {
906906
expect(statements).toStrictEqual([]);
907907
expect(sqlStatements).toStrictEqual([]);
908908
});
909+
910+
test('introspect cyclic foreign key', async () => {
911+
const content = mysqlTable('content', {
912+
id: int('id').notNull(),
913+
virtualPath: varchar('virtual_path', { length: 255 }).notNull(),
914+
pid: varchar('pid', { length: 750 }).notNull(),
915+
pageTitle: varchar('page_title', { length: 75 }).default('Untitled Document').notNull(),
916+
navTitle: varchar('nav_title', { length: 25 }).default('NULL'),
917+
protected: mysqlEnum('protected', ['Y', 'N']).default('N').notNull(),
918+
metaData: varchar('meta_data', { length: 750 }).default('NULL'),
919+
content: longtext('content').notNull(),
920+
navPlacement: longtext('navPlacement').default('NULL'),
921+
weight: decimal('weight', { precision: 10, scale: 2 }).notNull(),
922+
dateRecorded: datetime('date_recorded', { mode: 'string' }).notNull(),
923+
lastModified: timestamp('last_modified', { mode: 'string' }).default(sql`current_timestamp()`),
924+
});
925+
926+
const { statements, sqlStatements } = await diffIntrospect(db, { content }, 'double-quote-issue');
927+
928+
expect(statements).toStrictEqual([]);
929+
expect(sqlStatements).toStrictEqual([]);
930+
});

drizzle-kit/tests/other/cli-export.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { test as brotest } from '@drizzle-team/brocli';
2+
import { join } from 'node:path';
23
import { assert, expect, test } from 'vitest';
34
import { exportRaw } from '../../src/cli/schema';
45

@@ -14,6 +15,7 @@ import { exportRaw } from '../../src/cli/schema';
1415
// #4 drizzle-kit export --config=drizzle.config.ts --schema=schema.ts
1516
// #5 drizzle-kit export --config=drizzle.config.ts --dialect=postgresql
1617

18+
const filename = join(process.cwd(), 'tests/cli/schema.ts');
1719
test('export #1', async (t) => {
1820
const res = await brotest(
1921
exportRaw,
@@ -24,7 +26,7 @@ test('export #1', async (t) => {
2426

2527
expect(res.options).toStrictEqual({
2628
dialect: 'postgresql',
27-
schema: 'schema.ts',
29+
filenames: [filename],
2830
sql: true,
2931
casing: undefined,
3032
});
@@ -36,7 +38,7 @@ test('export #2', async (t) => {
3638
if (res.type !== 'handler') assert.fail(res.type, 'handler');
3739
expect(res.options).toStrictEqual({
3840
dialect: 'postgresql',
39-
schema: './schema.ts',
41+
filenames: [filename],
4042
sql: true,
4143
casing: undefined,
4244
});
@@ -49,7 +51,7 @@ test('export #3', async (t) => {
4951
if (res.type !== 'handler') assert.fail(res.type, 'handler');
5052
expect(res.options).toStrictEqual({
5153
dialect: 'sqlite',
52-
schema: './schema.ts',
54+
filenames: [filename],
5355
sql: true,
5456
casing: undefined,
5557
});

drizzle-kit/tests/other/cli-generate.test.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { test as brotest } from '@drizzle-team/brocli';
2+
import { join } from 'node:path';
23
import { assert, expect, test } from 'vitest';
34
import { generate } from '../../src/cli/schema';
45

@@ -23,6 +24,8 @@ import { generate } from '../../src/cli/schema';
2324
// #7 drizzle-kit generate --config=drizzle.config.ts --schema=schema.ts
2425
// #8 drizzle-kit generate --config=drizzle.config.ts --dialect=postgresql
2526

27+
const filename = join(process.cwd(), 'tests/cli/schema.ts');
28+
2629
test('generate #1', async (t) => {
2730
const res = await brotest(
2831
generate,
@@ -34,7 +37,7 @@ test('generate #1', async (t) => {
3437
name: undefined,
3538
custom: false,
3639
breakpoints: true,
37-
schema: 'schema.ts',
40+
filenames: [filename],
3841
out: 'drizzle',
3942
bundle: false,
4043
casing: undefined,
@@ -55,7 +58,7 @@ test('generate #2', async (t) => {
5558
name: undefined,
5659
custom: false,
5760
breakpoints: true,
58-
schema: 'schema.ts',
61+
filenames: [filename],
5962
out: 'out',
6063
bundle: false,
6164
casing: undefined,
@@ -73,7 +76,7 @@ test('generate #3', async (t) => {
7376
name: undefined,
7477
custom: false,
7578
breakpoints: true,
76-
schema: './schema.ts',
79+
filenames: [filename],
7780
out: 'drizzle',
7881
bundle: false,
7982
casing: undefined,
@@ -92,7 +95,7 @@ test('generate #4', async (t) => {
9295
name: undefined,
9396
custom: true,
9497
breakpoints: true,
95-
schema: './schema.ts',
98+
filenames: [filename],
9699
out: 'drizzle',
97100
bundle: false,
98101
casing: undefined,
@@ -110,7 +113,7 @@ test('generate #5', async (t) => {
110113
name: 'custom',
111114
custom: false,
112115
breakpoints: true,
113-
schema: './schema.ts',
116+
filenames: [filename],
114117
out: 'drizzle',
115118
bundle: false,
116119
casing: undefined,
@@ -128,7 +131,7 @@ test('generate #6', async (t) => {
128131
name: undefined,
129132
custom: false,
130133
breakpoints: true,
131-
schema: './schema.ts',
134+
filenames: [filename],
132135
out: 'drizzle',
133136
bundle: false,
134137
casing: undefined,
@@ -146,7 +149,7 @@ test('generate #7', async (t) => {
146149
name: 'custom',
147150
custom: true,
148151
breakpoints: true,
149-
schema: './schema.ts',
152+
filenames: [filename],
150153
out: 'drizzle',
151154
bundle: false,
152155
casing: undefined,
@@ -165,7 +168,7 @@ test('generate #8', async (t) => {
165168
name: undefined,
166169
custom: false,
167170
breakpoints: true,
168-
schema: './schema.ts',
171+
filenames: [filename],
169172
out: 'drizzle',
170173
bundle: true, // expo driver
171174
casing: undefined,
@@ -183,7 +186,7 @@ test('generate #9', async (t) => {
183186
name: undefined,
184187
custom: false,
185188
breakpoints: true,
186-
schema: './schema.ts',
189+
filenames: [filename],
187190
out: 'drizzle',
188191
bundle: true, // expo driver
189192
casing: undefined,
@@ -205,7 +208,7 @@ test('generate #9', async (t) => {
205208
name: 'custom',
206209
custom: true,
207210
breakpoints: true,
208-
schema: 'schema.ts',
211+
filenames: [filename],
209212
out: 'out',
210213
bundle: false,
211214
casing: undefined,

drizzle-kit/tests/other/cli-push.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { test as brotest } from '@drizzle-team/brocli';
2+
import { lstatSync } from 'node:fs';
3+
import { join, resolve } from 'node:path';
24
import { assert, expect, test } from 'vitest';
35
import { push } from '../../src/cli/schema';
46

@@ -13,6 +15,7 @@ import { push } from '../../src/cli/schema';
1315
// #1 drizzle-kit push --config=expo.config.ts
1416
// TODO: missing required params in config?
1517

18+
const filename = join(process.cwd(), 'tests/cli/schema.ts');
1619
test('push #1', async (t) => {
1720
const res = await brotest(push, '');
1821
if (res.type !== 'handler') assert.fail(res.type, 'handler');
@@ -22,7 +25,7 @@ test('push #1', async (t) => {
2225
url: 'postgresql://postgres:postgres@127.0.0.1:5432/db',
2326
},
2427
force: false,
25-
schemaPath: './schema.ts',
28+
filenames: [filename],
2629
explain: false,
2730
filters: {
2831
schemas: undefined,
@@ -49,7 +52,7 @@ test('push #2', async (t) => {
4952
url: 'turso.dev',
5053
},
5154
force: false,
52-
schemaPath: './schema.ts',
55+
filenames: [filename],
5356
explain: false,
5457
filters: {
5558
schemas: undefined,
@@ -78,7 +81,7 @@ test('push #3', async (t) => {
7881
token: 'token',
7982
},
8083
force: false,
81-
schemaPath: './schema.ts',
84+
filenames: [filename],
8285
explain: false,
8386
filters: {
8487
schemas: undefined,
@@ -115,7 +118,7 @@ test('push #4', async (t) => {
115118
entities: undefined,
116119
extensions: undefined,
117120
},
118-
schemaPath: './schema.ts',
121+
filenames: [filename],
119122
verbose: false,
120123
casing: undefined,
121124
migrations: {
@@ -141,7 +144,7 @@ test('push #5', async (t) => {
141144
port: 5432,
142145
user: 'postgresql',
143146
},
144-
schemaPath: './schema.ts',
147+
filenames: [filename],
145148
explain: false,
146149
filters: {
147150
schemas: undefined,

drizzle-kit/tests/postgres/pg-columns.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ test('alter text type to enum type', async () => {
323323

324324
// https://github.com/drizzle-team/drizzle-orm/issues/3589
325325
// After discussion it was decided to postpone this feature
326-
test.skipIf(Date.now() < +new Date('2026-03-15'))('alter integer type to text type with fk constraints', async () => {
326+
test.skipIf(Date.now() < +new Date('2026-03-25'))('alter integer type to text type with fk constraints', async () => {
327327
const users1 = pgTable('users', {
328328
id: serial().primaryKey(),
329329
});

drizzle-kit/tests/postgres/pg-enums.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,7 @@ test('drop enum', async () => {
24602460

24612461
// https://github.com/drizzle-team/drizzle-orm/issues/4982
24622462
// enhancement
2463-
test.skipIf(Date.now() < +new Date('2026-03-15'))(
2463+
test.skipIf(Date.now() < +new Date('2026-03-25'))(
24642464
'alter enum values; enum value is column default; table with data',
24652465
async () => {
24662466
enum AppStatus1 {

drizzle-kit/tests/postgres/pg-indexes.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ test('index in other schema', async () => {
776776
};
777777

778778
const { sqlStatements: st1, next: n1 } = await diff({}, schema1, []);
779-
const { sqlStatements: pst1 } = await push({ db, to: schema1, log: 'statements' });
779+
const { sqlStatements: pst1 } = await push({ db, to: schema1 });
780780

781781
const expectedSt1 = [
782782
'CREATE SCHEMA "common";\n',
@@ -804,3 +804,29 @@ test('index in other schema', async () => {
804804
expect(st2).toStrictEqual(expectedSt2);
805805
expect(pst2).toStrictEqual(expectedSt2);
806806
});
807+
808+
// https://github.com/drizzle-team/drizzle-orm/issues/5495
809+
test('access method issue', async () => {
810+
await db.query(`CREATE EXTENSION IF NOT EXISTS vector;`);
811+
812+
const schema = {
813+
table: pgTable(
814+
'table',
815+
{
816+
id: integer(),
817+
name: vector({ dimensions: 1536 }),
818+
},
819+
(table) => [index('idx_claims_embedding').using('ivfflat', table.name.asc().nullsLast().op('vector_cosine_ops'))],
820+
),
821+
};
822+
823+
const { sqlStatements: st1, next: n1 } = await diff({}, schema, []);
824+
const { sqlStatements: pst1 } = await push({ db, to: schema });
825+
826+
const expectedSt1 = [
827+
'CREATE TABLE "table" (\n\t"id" integer,\n\t"name" vector(1536)\n);\n',
828+
'CREATE INDEX "idx_claims_embedding" ON "table" USING ivfflat ("name" vector_cosine_ops);',
829+
];
830+
expect(st1).toStrictEqual(expectedSt1);
831+
expect(pst1).toStrictEqual(expectedSt1);
832+
});

0 commit comments

Comments
 (0)