Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
samarjit authored Dec 28, 2024
2 parents 51650ed + 06be106 commit 1692a18
Show file tree
Hide file tree
Showing 61 changed files with 4,900 additions and 1,701 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ rollup.config-*.mjs
*.log
.DS_Store
drizzle-seed/src/test.ts
drizzle-seed/src/testMysql.ts
drizzle-seed/src/testSqlite.ts
drizzle-seed/src/schemaTest.ts
1 change: 1 addition & 0 deletions changelogs/drizzle-orm/0.38.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix incorrect deprecation detection for table declarations
165 changes: 165 additions & 0 deletions changelogs/drizzle-seed/0.2.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
## API updates

We are introducing a new parameter, `version`, to the `seed` function options. This parameter, which controls generator versioning, has been added to make it easier to update deterministic generators in the future. Since values should remain consistent after each regeneration, it is crucial to provide a well-designed API for gradual updates

```ts
await seed(db, schema, { version: '2' });
```

#### Example:

> This is not an actual API change; it is just an example of how we will proceed with `drizzle-seed` versioning
For example, `lastName` generator was changed, and new version, `V2`, of this generator became available.

Later, `firstName` generator was changed, making `V3` version of this generator available.

| | `V1` | `V2` | `V3(latest)` |
| :--------------: | :--------------: | :-------------: | :--------------: |
| **LastNameGen** | `LastNameGenV1` | `LastNameGenV2` | |
| **FirstNameGen** | `FirstNameGenV1` | | `FirstNameGenV3` |


##### Use the `firstName` generator of version 3 and the `lastName` generator of version 2
```ts
await seed(db, schema);
```

If you are not ready to use latest generator version right away, you can specify max version to use

##### Use the `firstName` generator of version 1 and the `lastName` generator of version 2
```ts
await seed(db, schema, { version: '2' });
```

##### Use the `firstName` generator of version 1 and the `lastName` generator of version 1.
```ts
await seed(db, schema, { version: '1' });
```

Each update with breaking changes for generators will be documented on our docs and in release notes, explaining which version you should use, if you are not ready to upgrade the way generators works

## Breaking changes

### `interval` unique generator was changed and upgraded to v2

```ts
await seed(db, { table }).refine((f) => ({
table: {
columns: {
// this function usage will output different values with the same `seed` number from previous version
column1: f.interval({ isUnique: true }),
}
}
}))
```

**Reason for upgrade**
An older version of the generator could produce intervals like `1 minute 60 seconds` and `2 minutes 0 seconds`, treating them as distinct intervals.
However, when the `1 minute 60 seconds` interval is inserted into a PostgreSQL database, it is automatically converted to `2 minutes 0 seconds`. As a result, attempting to insert the `2 minutes 0 seconds` interval into a unique column afterwards will cause an error

**Usage**
```ts
await seed(db, schema);
// or explicit
await seed(db, schema, { version: '2' });
```

**Switch to the old version**
```ts
await seed(db, schema, { version: '1' });
```

### `string` generators were changed and upgraded to v2

```ts
await seed(db, { table }).refine((f) => ({
table: {
columns: {
// this function will output different values with the same `seed` number from previous version
column1: f.string(),
}
}
}))
```

**Reason to upgrade**

Ability to generate a unique string based on the length of the text column (e.g., `varchar(20)`)

#### PostgreSQL changes

Default generators for `text`, `varchar`, `char` will output different values with the same `seed` number from previous version.

```ts
// schema.ts
import * as p from 'drizzle-orm/pg-core'

export const table = p.pgTable('table', {
column1: p.text(),
column2: p.varchar(),
column3: p.char()
});

// index.ts
...
// this will be affected with new changes
await seed(db, { table });
```

**Switch to the old version**
```ts
await seed(db, schema, { version: '' });
```

#### MySQL changes

Default generators for `text`, `char`, `varchar`, `binary`, `varbinary` will output different values with the same `seed` number.

```ts
// schema.ts
import * as p from 'drizzle-orm/mysql-core'

export const table = p.mysqlTable('table', {
column1: p.text(),
column2: p.char(),
column3: p.varchar({ length: 256 }),
column4: p.binary(),
column5: p.varbinary({ length: 256 }),
});

// index.ts
...
// this will be affected with new changes
await seed(db, {table})
```

**Switch to the old version**
```ts
await seed(db, schema, { version: '1' });
```

#### SQLite changes

Default generators for `text`, `numeric`, `blob`, `blobbuffer` will output different values with the same `seed` number.
```ts
// schema.ts
import * as p from 'drizzle-orm/sqlite-core'

export const table = p.sqliteTable('table', {
column1: p.text(),
column2: p.numeric(),
column3: p.blob({ mode:'buffer' }),
column4: p.blob(),
});

// index.ts
...
// this will be affected with new changes
await seed(db, { table })
```


## Bug fixes
- Seeding a table with a foreign key referencing another table, without including the second table in the schema, will cause the seeding process to get stuck
- [[BUG]: seeding postgresql char column doesn't respect length option](https://github.com/drizzle-team/drizzle-orm/issues/3774)
25 changes: 25 additions & 0 deletions changelogs/drizzle-typebox/0.2.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Added support for SingleStore dialect

```ts
import { singlestoreTable, text, int } from 'drizzle-orm/singlestore-core';
import { createSelectSchema } from 'drizzle-typebox';
import { Value } from '@sinclair/typebox/value';

const users = singlestoreTable('users', {
id: int().primaryKey(),
name: text().notNull(),
age: int().notNull()
});

const userSelectSchema = createSelectSchema(users);

const rows = await db.select({ id: users.id, name: users.name }).from(users).limit(1);
const parsed: { id: number; name: string; age: number } = Value.Parse(userSelectSchema, rows[0]); // Error: `age` is not returned in the above query

const rows = await db.select().from(users).limit(1);
const parsed: { id: number; name: string; age: number } = Value.Parse(userSelectSchema, rows[0]); // Will parse successfully
```

# Bug fixes

- [[BUG]: drizzle-typebox infers integer() as TString](https://github.com/drizzle-team/drizzle-orm/issues/3756)
23 changes: 23 additions & 0 deletions changelogs/drizzle-valibot/0.3.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Added support for SingleStore dialect

```ts
import { singlestoreTable, text, int } from 'drizzle-orm/singlestore-core';
import { createSelectSchema } from 'drizzle-valibot';
import { parse } from 'valibot';

const users = singlestoreTable('users', {
id: int().primaryKey(),
name: text().notNull(),
age: int().notNull()
});

const userSelectSchema = createSelectSchema(users);
const rows = await db.select({ id: users.id, name: users.name }).from(users).limit(1);
const parsed: { id: number; name: string; age: number } = parse(userSelectSchema, rows[0]); // Error: `age` is not returned in the above query
const rows = await db.select().from(users).limit(1);
const parsed: { id: number; name: string; age: number } = parse(userSelectSchema, rows[0]); // Will parse successfully
```

# Bug fixes

- [[BUG]: drizzle-valibot throws Type instantiation is excessively deep and possibly infinite. for refinements](https://github.com/drizzle-team/drizzle-orm/issues/3751)
26 changes: 26 additions & 0 deletions changelogs/drizzle-zod/0.6.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# New Features

## Added support for SingleStore dialect

```ts
import { singlestoreTable, text, int } from 'drizzle-orm/singlestore-core';
import { createSelectSchema } from 'drizzle-zod';

const users = singlestoreTable('users', {
id: int().primaryKey(),
name: text().notNull(),
age: int().notNull()
});

const userSelectSchema = createSelectSchema(users);
const rows = await db.select({ id: users.id, name: users.name }).from(users).limit(1);
const parsed: { id: number; name: string; age: number } = userSelectSchema.parse(rows[0]); // Error: `age` is not returned in the above query

const rows = await db.select().from(users).limit(1);
const parsed: { id: number; name: string; age: number } = userSelectSchema.parse(rows[0]); // Will parse successfully
```

# Bug fixes

- [[BUG]: refining schema using createSelectSchema is not working with drizzle-kit 0.6.0](https://github.com/drizzle-team/drizzle-orm/issues/3735)
- [[BUG]: drizzle-zod inferring types incorrectly](https://github.com/drizzle-team/drizzle-orm/issues/3734)
2 changes: 1 addition & 1 deletion drizzle-orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-orm",
"version": "0.38.2",
"version": "0.38.3",
"description": "Drizzle ORM package for SQL databases",
"type": "module",
"scripts": {
Expand Down
59 changes: 29 additions & 30 deletions drizzle-orm/src/mysql-core/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,35 @@ export function mysqlTableWithSchema<
}

export interface MySqlTableFn<TSchemaName extends string | undefined = undefined> {
<
TTableName extends string,
TColumnsMap extends Record<string, MySqlColumnBuilderBase>,
>(
name: TTableName,
columns: TColumnsMap,
extraConfig?: (
self: BuildColumns<TTableName, TColumnsMap, 'mysql'>,
) => MySqlTableExtraConfigValue[],
): MySqlTableWithColumns<{
name: TTableName;
schema: TSchemaName;
columns: BuildColumns<TTableName, TColumnsMap, 'mysql'>;
dialect: 'mysql';
}>;

<
TTableName extends string,
TColumnsMap extends Record<string, MySqlColumnBuilderBase>,
>(
name: TTableName,
columns: (columnTypes: MySqlColumnBuilders) => TColumnsMap,
extraConfig?: (self: BuildColumns<TTableName, TColumnsMap, 'mysql'>) => MySqlTableExtraConfigValue[],
): MySqlTableWithColumns<{
name: TTableName;
schema: TSchemaName;
columns: BuildColumns<TTableName, TColumnsMap, 'mysql'>;
dialect: 'mysql';
}>;
/**
* @deprecated The third parameter of mysqlTable is changing and will only accept an array instead of an object
*
Expand Down Expand Up @@ -187,36 +216,6 @@ export interface MySqlTableFn<TSchemaName extends string | undefined = undefined
columns: BuildColumns<TTableName, TColumnsMap, 'mysql'>;
dialect: 'mysql';
}>;

<
TTableName extends string,
TColumnsMap extends Record<string, MySqlColumnBuilderBase>,
>(
name: TTableName,
columns: TColumnsMap,
extraConfig?: (
self: BuildColumns<TTableName, TColumnsMap, 'mysql'>,
) => MySqlTableExtraConfigValue[],
): MySqlTableWithColumns<{
name: TTableName;
schema: TSchemaName;
columns: BuildColumns<TTableName, TColumnsMap, 'mysql'>;
dialect: 'mysql';
}>;

<
TTableName extends string,
TColumnsMap extends Record<string, MySqlColumnBuilderBase>,
>(
name: TTableName,
columns: (columnTypes: MySqlColumnBuilders) => TColumnsMap,
extraConfig?: (self: BuildColumns<TTableName, TColumnsMap, 'mysql'>) => MySqlTableExtraConfigValue[],
): MySqlTableWithColumns<{
name: TTableName;
schema: TSchemaName;
columns: BuildColumns<TTableName, TColumnsMap, 'mysql'>;
dialect: 'mysql';
}>;
}

export const mysqlTable: MySqlTableFn = (name, columns, extraConfig) => {
Expand Down
Loading

0 comments on commit 1692a18

Please sign in to comment.