Files
drizzle-team--drizzle-orm/changelogs/drizzle-orm-mysql/0.15.1.md
T
2026-07-13 12:10:05 +08:00

88 lines
2.7 KiB
Markdown

# drizzle-orm-mysql 0.15.1
Add support for schemas -> [MySQL schemas](https://dev.mysql.com/doc/refman/8.0/en/create-database.html)
> **Warning**
> If you will have tables with same names in different schemas then drizzle will respond with `never[]` error in result types and error from database
>
> In this case you may use [alias syntax](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-mysql#join-aliases-and-self-joins)
---
Usage example
```typescript
// Table in default schema
const publicUsersTable = mysqlTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
verified: boolean('verified').notNull().default(false),
jsonb: json<string[]>('jsonb'),
createdAt: timestamp('created_at', { fsp: 2 }).notNull().defaultNow(),
});
// Table in custom schema
const mySchema = mysqlSchema('mySchema');
const mySchemaUsersTable = mySchema('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
verified: boolean('verified').notNull().default(false),
jsonb: json<string[]>('jsonb'),
createdAt: timestamp('created_at', { fsp: 2 }).notNull().defaultNow(),
});
```
---
## Breaking changes
- `foreignKey()` function api changes. Previously you need to pass callback function with table columns for FK. Right now no need for callback, just object with data for FK
#### Before
```typescript
export const usersTable = mysqlTable('userstest', {
id: serial('id').primaryKey(),
homeCity: text('name').notNull(),
createdAt: timestamp('created_at', { fsp: 2 }).notNull().defaultNow(),
}, (users) => ({
// foreignKey has a callback as param
usersCityFK: foreignKey(() => { columns: [users.homeCity], foreignColumns: [cities.id] }),
}));
```
#### Now
```typescript
export const usersTable = mysqlTable('userstest', {
id: serial('id').primaryKey(),
homeCity: text('name').notNull(),
createdAt: timestamp('created_at', { fsp: 2 }).notNull().defaultNow(),
}, (users) => ({
// foreignKey has a callback as param
usersCityFK: foreignKey({ columns: [users.homeCity], foreignColumns: [cities.id] }),
}));
```
---
- Change enum initializing strategy for mysql
You should use
``` typescript
mysqlEnum('popularity', ['unknown', 'known', 'popular']).notNull().default('known')
```
instead of
``` typescript
export const popularityEnum = mysqlEnum('popularity', ['unknown', 'known', 'popular']);
popularityEnum('column_name');
```
Usage example in table schema
``` typescript
const tableWithEnums = mysqlTable('enums_test_case', {
id: serial('id').primaryKey(),
enum1: mysqlEnum('enum1', ['a', 'b', 'c']).notNull(),
enum2: mysqlEnum('enum2', ['a', 'b', 'c']).default('a'),
enum3: mysqlEnum('enum3', ['a', 'b', 'c']).notNull().default('b'),
});
```