Skip to content

Commit 9e59a7d

Browse files
committed
Use mysql connection strin in CI tests
1 parent 846c6dd commit 9e59a7d

File tree

5 files changed

+113
-135
lines changed

5 files changed

+113
-135
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ cd drizzle-orm
134134
### <a name="project-structure-orm"></a> Project structure
135135

136136
```
137-
Project sctructure
137+
Project structure
138138
139139
📂 pg-core, mysql-core, sqlite-core - core packages for each dialect with all the main logic for relation and query builder
140140

drizzle-kit/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-kit",
3-
"version": "0.23.1",
3+
"version": "0.23.2",
44
"repository": "https://github.com/drizzle-team/drizzle-orm",
55
"author": "Drizzle Team",
66
"license": "MIT",

drizzle-kit/src/serializer/pgSerializer.ts

+95-117
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,34 @@ function stringFromIdentityProperty(
4545
return typeof field === 'string'
4646
? (field as string)
4747
: typeof field === 'undefined'
48-
? undefined
49-
: String(field);
48+
? undefined
49+
: String(field);
5050
}
5151

5252
function maxRangeForIdentityBasedOn(columnType: string) {
5353
return columnType === 'integer'
5454
? '2147483647'
5555
: columnType === 'bigint'
56-
? '9223372036854775807'
57-
: '32767';
56+
? '9223372036854775807'
57+
: '32767';
5858
}
5959

6060
function minRangeForIdentityBasedOn(columnType: string) {
6161
return columnType === 'integer'
6262
? '-2147483648'
6363
: columnType === 'bitint'
64-
? '-9223372036854775808'
65-
: '-32768';
64+
? '-9223372036854775808'
65+
: '-32768';
6666
}
6767

6868
function stringFromDatabaseIdentityProperty(field: any): string | undefined {
6969
return typeof field === 'string'
7070
? (field as string)
7171
: typeof field === 'undefined'
72-
? undefined
73-
: typeof field === 'bigint'
74-
? field.toString()
75-
: String(field);
72+
? undefined
73+
: typeof field === 'bigint'
74+
? field.toString()
75+
: String(field);
7676
}
7777

7878
export const generatePgSnapshot = (
@@ -146,8 +146,8 @@ export const generatePgSnapshot = (
146146
as: is(generated.as, SQL)
147147
? dialect.sqlToQuery(generated.as as SQL).sql
148148
: typeof generated.as === 'function'
149-
? dialect.sqlToQuery(generated.as() as SQL).sql
150-
: (generated.as as any),
149+
? dialect.sqlToQuery(generated.as() as SQL).sql
150+
: (generated.as as any),
151151
type: 'stored',
152152
}
153153
: undefined,
@@ -170,24 +170,19 @@ export const generatePgSnapshot = (
170170
const existingUnique = uniqueConstraintObject[column.uniqueName!];
171171
if (typeof existingUnique !== 'undefined') {
172172
console.log(
173-
`\n${
174-
withStyle.errorWarning(`We\'ve found duplicated unique constraint names in ${
175-
chalk.underline.blue(
176-
tableName,
177-
)
173+
`\n${withStyle.errorWarning(`We\'ve found duplicated unique constraint names in ${chalk.underline.blue(
174+
tableName,
175+
)
178176
} table.
179-
The unique constraint ${
180-
chalk.underline.blue(
181-
column.uniqueName,
182-
)
183-
} on the ${
184-
chalk.underline.blue(
185-
column.name,
186-
)
187-
} column is confilcting with a unique constraint name already defined for ${
188-
chalk.underline.blue(
189-
existingUnique.columns.join(','),
190-
)
177+
The unique constraint ${chalk.underline.blue(
178+
column.uniqueName,
179+
)
180+
} on the ${chalk.underline.blue(
181+
column.name,
182+
)
183+
} column is confilcting with a unique constraint name already defined for ${chalk.underline.blue(
184+
existingUnique.columns.join(','),
185+
)
191186
} columns\n`)
192187
}`,
193188
);
@@ -208,21 +203,19 @@ export const generatePgSnapshot = (
208203
columnToSet.default = `'${column.default}'`;
209204
} else {
210205
if (sqlTypeLowered === 'jsonb' || sqlTypeLowered === 'json') {
211-
columnToSet.default = `'${
212-
JSON.stringify(
213-
column.default,
214-
)
215-
}'::${sqlTypeLowered}`;
206+
columnToSet.default = `'${JSON.stringify(
207+
column.default,
208+
)
209+
}'::${sqlTypeLowered}`;
216210
} else if (column.default instanceof Date) {
217211
if (sqlTypeLowered === 'date') {
218212
columnToSet.default = `'${column.default.toISOString().split('T')[0]}'`;
219213
} else if (sqlTypeLowered === 'timestamp') {
220-
columnToSet.default = `'${
221-
column.default
222-
.toISOString()
223-
.replace('T', ' ')
224-
.slice(0, 23)
225-
}'`;
214+
columnToSet.default = `'${column.default
215+
.toISOString()
216+
.replace('T', ' ')
217+
.slice(0, 23)
218+
}'`;
226219
} else {
227220
columnToSet.default = `'${column.default.toISOString()}'`;
228221
}
@@ -253,24 +246,19 @@ export const generatePgSnapshot = (
253246
const existingUnique = uniqueConstraintObject[name];
254247
if (typeof existingUnique !== 'undefined') {
255248
console.log(
256-
`\n${
257-
withStyle.errorWarning(`We\'ve found duplicated unique constraint names in ${
258-
chalk.underline.blue(
259-
tableName,
260-
)
249+
`\n${withStyle.errorWarning(`We\'ve found duplicated unique constraint names in ${chalk.underline.blue(
250+
tableName,
251+
)
261252
} table.
262-
The unique constraint ${
263-
chalk.underline.blue(
264-
name,
265-
)
266-
} on the ${
267-
chalk.underline.blue(
268-
columnNames.join(','),
269-
)
270-
} columns is confilcting with a unique constraint name already defined for ${
271-
chalk.underline.blue(
272-
existingUnique.columns.join(','),
273-
)
253+
The unique constraint ${chalk.underline.blue(
254+
name,
255+
)
256+
} on the ${chalk.underline.blue(
257+
columnNames.join(','),
258+
)
259+
} columns is confilcting with a unique constraint name already defined for ${chalk.underline.blue(
260+
existingUnique.columns.join(','),
261+
)
274262
} columns\n`)
275263
}`,
276264
);
@@ -323,16 +311,13 @@ export const generatePgSnapshot = (
323311
if (is(it, SQL)) {
324312
if (typeof value.config.name === 'undefined') {
325313
console.log(
326-
`\n${
327-
withStyle.errorWarning(
328-
`Please specify an index name in ${
329-
getTableName(
330-
value.config.table,
331-
)
332-
} table that has "${
333-
dialect.sqlToQuery(it).sql
334-
}" expression. We can generate index names for indexes on columns only; for expressions in indexes, you need to specify the name yourself.`,
314+
`\n${withStyle.errorWarning(
315+
`Please specify an index name in ${getTableName(
316+
value.config.table,
335317
)
318+
} table that has "${dialect.sqlToQuery(it).sql
319+
}" expression. We can generate index names for indexes on columns only; for expressions in indexes, you need to specify the name yourself.`,
320+
)
336321
}`,
337322
);
338323
process.exit(1);
@@ -345,34 +330,27 @@ export const generatePgSnapshot = (
345330
&& typeof it.indexConfig!.opClass === 'undefined'
346331
) {
347332
console.log(
348-
`\n${
349-
withStyle.errorWarning(
350-
`You are specifying an index on the ${
351-
chalk.blueBright(
352-
it.name,
353-
)
354-
} column inside the ${
355-
chalk.blueBright(
356-
tableName,
357-
)
358-
} table with the ${
359-
chalk.blueBright(
360-
'vector',
361-
)
362-
} type without specifying an operator class. Vector extension doesn't have a default operator class, so you need to specify one of the available options. Here is a list of available op classes for the vector extension: [${
363-
vectorOps
364-
.map((it) => `${chalk.underline(`${it}`)}`)
365-
.join(
366-
', ',
367-
)
368-
}].\n\nYou can specify it using current syntax: ${
369-
chalk.underline(
370-
`index("${value.config.name}").using("${value.config.method}", table.${it.name}.op("${
371-
vectorOps[0]
372-
}"))`,
373-
)
374-
}\n\nYou can check the "pg_vector" docs for more info: https://github.com/pgvector/pgvector?tab=readme-ov-file#indexing\n`,
333+
`\n${withStyle.errorWarning(
334+
`You are specifying an index on the ${chalk.blueBright(
335+
it.name,
336+
)
337+
} column inside the ${chalk.blueBright(
338+
tableName,
339+
)
340+
} table with the ${chalk.blueBright(
341+
'vector',
375342
)
343+
} type without specifying an operator class. Vector extension doesn't have a default operator class, so you need to specify one of the available options. Here is a list of available op classes for the vector extension: [${vectorOps
344+
.map((it) => `${chalk.underline(`${it}`)}`)
345+
.join(
346+
', ',
347+
)
348+
}].\n\nYou can specify it using current syntax: ${chalk.underline(
349+
`index("${value.config.name}").using("${value.config.method}", table.${it.name}.op("${vectorOps[0]
350+
}"))`,
351+
)
352+
}\n\nYou can check the "pg_vector" docs for more info: https://github.com/pgvector/pgvector?tab=readme-ov-file#indexing\n`,
353+
)
376354
}`,
377355
);
378356
process.exit(1);
@@ -402,8 +380,8 @@ export const generatePgSnapshot = (
402380
nulls: it.indexConfig?.nulls
403381
? it.indexConfig?.nulls
404382
: it.indexConfig?.order === 'desc'
405-
? 'first'
406-
: 'last',
383+
? 'first'
384+
: 'last',
407385
opclass: it.indexConfig?.opClass,
408386
};
409387
}
@@ -414,18 +392,15 @@ export const generatePgSnapshot = (
414392
if (typeof indexesInSchema[schema ?? 'public'] !== 'undefined') {
415393
if (indexesInSchema[schema ?? 'public'].includes(name)) {
416394
console.log(
417-
`\n${
418-
withStyle.errorWarning(
419-
`We\'ve found duplicated index name across ${
420-
chalk.underline.blue(
421-
schema ?? 'public',
422-
)
423-
} schema. Please rename your index in either the ${
424-
chalk.underline.blue(
425-
tableName,
426-
)
427-
} table or the table with the duplicated index name`,
395+
`\n${withStyle.errorWarning(
396+
`We\'ve found duplicated index name across ${chalk.underline.blue(
397+
schema ?? 'public',
398+
)
399+
} schema. Please rename your index in either the ${chalk.underline.blue(
400+
tableName,
428401
)
402+
} table or the table with the duplicated index name`,
403+
)
429404
}`,
430405
);
431406
process.exit(1);
@@ -465,7 +440,7 @@ export const generatePgSnapshot = (
465440
const name = sequence.seqName!;
466441
if (
467442
typeof sequencesToReturn[`${sequence.schema ?? 'public'}.${name}`]
468-
=== 'undefined'
443+
=== 'undefined'
469444
) {
470445
const increment = stringFromIdentityProperty(sequence?.seqOptions?.increment) ?? '1';
471446
const minValue = stringFromIdentityProperty(sequence?.seqOptions?.minValue)
@@ -594,8 +569,7 @@ export const fromDatabase = async (
594569
const seqWhere = schemaFilters.map((t) => `schemaname = '${t}'`).join(' or ');
595570

596571
const allSequences = await db.query(
597-
`select schemaname, sequencename, start_value, min_value, max_value, increment_by, cycle, cache_size from pg_sequences as seq${
598-
seqWhere === '' ? '' : ` WHERE ${seqWhere}`
572+
`select schemaname, sequencename, start_value, min_value, max_value, increment_by, cycle, cache_size from pg_sequences as seq${seqWhere === '' ? '' : ` WHERE ${seqWhere}`
599573
};`,
600574
);
601575

@@ -622,6 +596,10 @@ export const fromDatabase = async (
622596
};
623597
}
624598

599+
const whereEnums = schemaFilters
600+
.map((t) => `n.nspname = '${t}'`)
601+
.join(" or ");
602+
625603
const allEnums = await db.query(
626604
`select n.nspname as enum_schema,
627605
t.typname as enum_name,
@@ -630,6 +608,7 @@ export const fromDatabase = async (
630608
from pg_type t
631609
join pg_enum e on t.oid = e.enumtypid
632610
join pg_catalog.pg_namespace n ON n.oid = t.typnamespace
611+
${whereEnums === "" ? "" : ` WHERE ${whereEnums}`}
633612
order by enum_schema, enum_name, sort_order;`,
634613
);
635614

@@ -881,7 +860,7 @@ export const fromDatabase = async (
881860
} else {
882861
if (
883862
typeof internals.tables[tableName]!.columns[columnName]
884-
=== 'undefined'
863+
=== 'undefined'
885864
) {
886865
internals.tables[tableName]!.columns[columnName] = {
887866
isArray: true,
@@ -937,8 +916,8 @@ export const fromDatabase = async (
937916
cache: sequencesToReturn[identityName]?.cache
938917
? sequencesToReturn[identityName]?.cache
939918
: sequencesToReturn[`${tableSchema}.${identityName}`]?.cache
940-
? sequencesToReturn[`${tableSchema}.${identityName}`]?.cache
941-
: undefined,
919+
? sequencesToReturn[`${tableSchema}.${identityName}`]?.cache
920+
: undefined,
942921
cycle: identityCycle,
943922
schema: tableSchema,
944923
}
@@ -1184,11 +1163,10 @@ const defaultForColumn = (column: any) => {
11841163
return Number(rt);
11851164
} else if (column.data_type === 'json' || column.data_type === 'jsonb') {
11861165
const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
1187-
return `'${jsonWithoutSpaces}'${
1188-
hasDifferentDefaultCast
1189-
? columnToDefault[hasDifferentDefaultCast]
1190-
: `::${column.data_type as string}`
1191-
}`;
1166+
return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast
1167+
? columnToDefault[hasDifferentDefaultCast]
1168+
: `::${column.data_type as string}`
1169+
}`;
11921170
} else if (column.data_type === 'boolean') {
11931171
return column.column_default === 'true';
11941172
} else {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function createDockerDB(): Promise<string> {
4040
}
4141

4242
beforeAll(async () => {
43-
const connectionString = await createDockerDB();
43+
const connectionString = process.env.MYSQL_CONNECTION_STRING ?? await createDockerDB();
4444

4545
const sleep = 1000;
4646
let timeLeft = 20000;

0 commit comments

Comments
 (0)