Skip to content

Commit 4d72640

Browse files
Merge pull request #4037 from drizzle-team/beta
Beta
2 parents 1dd14ac + 5ffd0bd commit 4d72640

File tree

29 files changed

+891
-219
lines changed

29 files changed

+891
-219
lines changed

changelogs/drizzle-kit/0.30.4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Fix bug that generates incorrect syntax when introspect in mysql
2+
- Fix a bug that caused incorrect syntax output when introspect in unsigned columns

changelogs/drizzle-orm/0.39.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Fixed SQLite onConflict clauses being overwritten instead of stacked - [#2276](https://github.com/drizzle-team/drizzle-orm/issues/2276)
2+
- Added view support to `aliasedTable()`
3+
- Fixed sql builder prefixing aliased views and tables with their schema

changelogs/drizzle-seed/0.3.1.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Bug fixes
2+
3+
- Combining a reference in a table schema (foreign key constraint) with a one-to-many relation for the same two tables defined in the constraint causes the seeder to duplicate these relations and enter an infinite loop.
4+
5+
Example:
6+
7+
```ts
8+
// schema.ts
9+
import { integer, pgTable, text } from "drizzle-orm/pg-core";
10+
import { relations } from "drizzle-orm/relations";
11+
12+
export const users = pgTable("users", {
13+
id: integer().primaryKey(),
14+
name: text(),
15+
email: text(),
16+
});
17+
18+
export const posts = pgTable("posts", {
19+
id: integer().primaryKey(),
20+
content: text(),
21+
userId: integer().references(() => users.id),
22+
});
23+
24+
export const postsRelation = relations(posts, ({ one }) => ({
25+
user: one(users, {
26+
fields: [posts.userId],
27+
references: [users.id],
28+
}),
29+
}));
30+
```
31+
32+
Now, seeding with the schema above will trigger a warning.
33+
34+
```
35+
You are providing a one-to-many relation between the 'users' and 'posts' tables,
36+
while the 'posts' table object already has foreign key constraint in the schema referencing 'users' table.
37+
In this case, the foreign key constraint will be used.
38+
```

drizzle-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-kit",
3-
"version": "0.30.3",
3+
"version": "0.30.4",
44
"homepage": "https://orm.drizzle.team",
55
"keywords": [
66
"drizzle",

drizzle-kit/src/introspect-mysql.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,7 @@ const column = (
405405
if (lowered.startsWith('int')) {
406406
const isUnsigned = lowered.startsWith('int unsigned');
407407
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
408-
let out = `${casing(name)}: int(${columnName}${
409-
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
410-
})`;
408+
let out = `${casing(name)}: int(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
411409
out += autoincrement ? `.autoincrement()` : '';
412410
out += typeof defaultValue !== 'undefined'
413411
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
@@ -419,9 +417,7 @@ const column = (
419417
const isUnsigned = lowered.startsWith('tinyint unsigned');
420418
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
421419
// let out = `${name.camelCase()}: tinyint("${name}")`;
422-
let out: string = `${casing(name)}: tinyint(${columnName}${
423-
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
424-
})`;
420+
let out: string = `${casing(name)}: tinyint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
425421
out += autoincrement ? `.autoincrement()` : '';
426422
out += typeof defaultValue !== 'undefined'
427423
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
@@ -432,9 +428,7 @@ const column = (
432428
if (lowered.startsWith('smallint')) {
433429
const isUnsigned = lowered.startsWith('smallint unsigned');
434430
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
435-
let out = `${casing(name)}: smallint(${columnName}${
436-
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
437-
})`;
431+
let out = `${casing(name)}: smallint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
438432
out += autoincrement ? `.autoincrement()` : '';
439433
out += defaultValue
440434
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
@@ -445,9 +439,7 @@ const column = (
445439
if (lowered.startsWith('mediumint')) {
446440
const isUnsigned = lowered.startsWith('mediumint unsigned');
447441
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
448-
let out = `${casing(name)}: mediumint(${columnName}${
449-
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
450-
})`;
442+
let out = `${casing(name)}: mediumint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
451443
out += autoincrement ? `.autoincrement()` : '';
452444
out += defaultValue
453445
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
@@ -923,7 +915,7 @@ const createTableIndexes = (
923915

924916
idxKey = casing(idxKey);
925917

926-
statement += `\t\t${idxKey}: `;
918+
statement += `\n\t`;
927919
statement += it.isUnique ? 'uniqueIndex(' : 'index(';
928920
statement += `"${it.name}")`;
929921
statement += `.on(${

drizzle-kit/src/introspect-singlestore.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,7 @@ const column = (
380380
if (lowered.startsWith('int')) {
381381
const isUnsigned = lowered.includes('unsigned');
382382
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
383-
let out = `${casing(name)}: int(${columnName}${
384-
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
385-
})`;
383+
let out = `${casing(name)}: int(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
386384
out += autoincrement ? `.autoincrement()` : '';
387385
out += typeof defaultValue !== 'undefined'
388386
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
@@ -393,10 +391,7 @@ const column = (
393391
if (lowered.startsWith('tinyint')) {
394392
const isUnsigned = lowered.includes('unsigned');
395393
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
396-
// let out = `${name.camelCase()}: tinyint("${name}")`;
397-
let out: string = `${casing(name)}: tinyint(${columnName}${
398-
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
399-
})`;
394+
let out: string = `${casing(name)}: tinyint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
400395
out += autoincrement ? `.autoincrement()` : '';
401396
out += typeof defaultValue !== 'undefined'
402397
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
@@ -407,9 +402,7 @@ const column = (
407402
if (lowered.startsWith('smallint')) {
408403
const isUnsigned = lowered.includes('unsigned');
409404
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
410-
let out = `${casing(name)}: smallint(${columnName}${
411-
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
412-
})`;
405+
let out = `${casing(name)}: smallint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
413406
out += autoincrement ? `.autoincrement()` : '';
414407
out += defaultValue
415408
? `.default(${mapColumnDefault(defaultValue, isExpression)})`
@@ -420,9 +413,7 @@ const column = (
420413
if (lowered.startsWith('mediumint')) {
421414
const isUnsigned = lowered.includes('unsigned');
422415
const columnName = dbColumnName({ name, casing: rawCasing, withMode: isUnsigned });
423-
let out = `${casing(name)}: mediumint(${columnName}${
424-
isUnsigned ? `${columnName.length > 0 ? ', ' : ''}{ unsigned: true }` : ''
425-
})`;
416+
let out = `${casing(name)}: mediumint(${columnName}${isUnsigned ? '{ unsigned: true }' : ''})`;
426417
out += autoincrement ? `.autoincrement()` : '';
427418
out += defaultValue
428419
? `.default(${mapColumnDefault(defaultValue, isExpression)})`

drizzle-orm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-orm",
3-
"version": "0.39.0",
3+
"version": "0.39.1",
44
"description": "Drizzle ORM package for SQL databases",
55
"type": "module",
66
"scripts": {

drizzle-orm/src/alias.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ export class RelationTableAliasProxyHandler<T extends Relation> implements Proxy
8888
}
8989
}
9090

91-
export function aliasedTable<T extends Table>(table: T, tableAlias: string): T {
92-
return new Proxy(table, new TableAliasProxyHandler(tableAlias, false));
91+
export function aliasedTable<T extends Table | View>(
92+
table: T,
93+
tableAlias: string,
94+
): T {
95+
return new Proxy(table, new TableAliasProxyHandler(tableAlias, false)) as any;
9396
}
9497

9598
export function aliasedRelation<T extends Relation>(relation: T, tableAlias: string): T {

drizzle-orm/src/mysql-core/query-builders/select.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export type MySqlJoin<
9797
T['_']['selection'],
9898
TJoinedName,
9999
TJoinedTable extends MySqlTable ? TJoinedTable['_']['columns']
100-
: TJoinedTable extends Subquery ? Assume<TJoinedTable['_']['selectedFields'], SelectedFields>
100+
: TJoinedTable extends Subquery | View ? Assume<TJoinedTable['_']['selectedFields'], SelectedFields>
101101
: never,
102102
T['_']['selectMode']
103103
>,

drizzle-orm/src/pg-core/query-builders/select.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export type PgSelectJoin<
9898
T['_']['selection'],
9999
TJoinedName,
100100
TJoinedTable extends Table ? TJoinedTable['_']['columns']
101-
: TJoinedTable extends Subquery ? Assume<TJoinedTable['_']['selectedFields'], SelectedFields>
101+
: TJoinedTable extends Subquery | View ? Assume<TJoinedTable['_']['selectedFields'], SelectedFields>
102102
: never,
103103
T['_']['selectMode']
104104
>,

0 commit comments

Comments
 (0)