Skip to content

Commit

Permalink
Merge branch 'beta' into singlestore-blob-new-column-type
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiSherman authored Dec 26, 2024
2 parents 683bb23 + 5ed29d9 commit a035a6b
Show file tree
Hide file tree
Showing 128 changed files with 10,227 additions and 2,132 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
35 changes: 35 additions & 0 deletions changelogs/drizzle-kit/0.30.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# New Features

### `drizzle-kit export`

To make drizzle-kit integration with other migration tools, like Atlas much easier, we've prepared a new command called `export`. It will translate your drizzle schema in SQL representation(DDL) statements and outputs to the console

```ts
// schema.ts
import { pgTable, serial, text } from 'drizzle-orm/pg-core'

export const users = pgTable('users', {
id: serial('id').primaryKey(),
email: text('email').notNull(),
name: text('name')
});
```
Running
```bash
npx drizzle-kit export
```

will output this string to console
```bash
CREATE TABLE "users" (
"id" serial PRIMARY KEY NOT NULL,
"email" text NOT NULL,
"name" text
);
```

By default, the only option for now is `--sql`, so the output format will be SQL DDL statements. In the future, we will support additional output formats to accommodate more migration tools

```bash
npx drizzle-kit export --sql
```
1 change: 1 addition & 0 deletions changelogs/drizzle-orm/0.38.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Closed [[FEATURE]: Add more flexible typing for usage with exactOptionalPropertyTypes](https://github.com/drizzle-team/drizzle-orm/issues/2742)
58 changes: 58 additions & 0 deletions changelogs/drizzle-orm/0.38.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# New features

## `USE INDEX`, `FORCE INDEX` and `IGNORE INDEX` for MySQL

In MySQL, the statements USE INDEX, FORCE INDEX, and IGNORE INDEX are hints used in SQL queries to influence how the query optimizer selects indexes. These hints provide fine-grained control over index usage, helping optimize performance when the default behavior of the optimizer is not ideal.

### Use Index

The `USE INDEX` hint suggests to the optimizer which indexes to consider when processing the query. The optimizer is not forced to use these indexes but will prioritize them if they are suitable.

```ts
export const users = mysqlTable('users', {
id: int('id').primaryKey(),
name: varchar('name', { length: 100 }).notNull(),
}, () => [usersTableNameIndex]);

const usersTableNameIndex = index('users_name_index').on(users.name);

await db.select()
.from(users, { useIndex: usersTableNameIndex })
.where(eq(users.name, 'David'));
```

### Ignore Index

The `IGNORE INDEX` hint tells the optimizer to avoid using specific indexes for the query. MySQL will consider all other indexes (if any) or perform a full table scan if necessary.

```ts
export const users = mysqlTable('users', {
id: int('id').primaryKey(),
name: varchar('name', { length: 100 }).notNull(),
}, () => [usersTableNameIndex]);

const usersTableNameIndex = index('users_name_index').on(users.name);

await db.select()
.from(users, { ignoreIndex: usersTableNameIndex })
.where(eq(users.name, 'David'));
```

### Force Index

The `FORCE INDEX` hint forces the optimizer to use the specified index(es) for the query. If the specified index cannot be used, MySQL will not fall back to other indexes; it might resort to a full table scan instead.

```ts copy
export const users = mysqlTable('users', {
id: int('id').primaryKey(),
name: varchar('name', { length: 100 }).notNull(),
}, () => [usersTableNameIndex]);

const usersTableNameIndex = index('users_name_index').on(users.name);

await db.select()
.from(users, { forceIndex: usersTableNameIndex })
.where(eq(users.name, 'David'));
```

You can also combine those hints and use multiple indexes in a query if you need
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
131 changes: 131 additions & 0 deletions changelogs/drizzle-seed/0.1.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
## Bug fixes

- https://github.com/drizzle-team/drizzle-orm/issues/3644
- seeding a table with columns that have .default(sql``) will result in an error

## Features

- added support for postgres uuid columns

Example

```ts
import { pgTable, uuid } from "drizzle-orm/pg-core";
import { drizzle } from "drizzle-orm/node-postgres";
import { seed } from "drizzle-seed";

const users = pgTable("users", {
uuid: uuid("uuid"),
});

async function main() {
const db = drizzle(process.env.DATABASE_URL!);
// You can let it seed automatically
// await seed(db, { users });

// Alternatively, you can manually specify the generator in refine.
await seed(db, { users }, { count: 1000 }).refine((funcs) => ({
users: {
columns: {
uuid: funcs.uuid(),
},
},
}));
}

main();
```

##

- added support for postgres array columns

Example

```ts
import { pgTable, integer, text, varchar } from "drizzle-orm/pg-core";
import { drizzle } from "drizzle-orm/node-postgres";
import { seed } from "drizzle-seed";

const users = pgTable("users", {
id: integer().primaryKey(),
name: text().notNull(),
phone_numbers: varchar({ length: 256 }).array(),
});
```

You can specify the `arraySize` parameter in generator options, like `funcs.phoneNumber({ arraySize: 3 })`, to generate 1D arrays.

```ts
async function main() {
const db = drizzle(process.env.DATABASE_URL!);
await seed(db, { users }, { count: 1000 }).refine((funcs) => ({
users: {
columns: {
phone_numbers: funcs.phoneNumber({ arraySize: 3 }),
},
},
}));
}

main();
```

Alternatively, you can let it seed automatically, and it will handle arrays of any dimension.

```ts
async function main() {
const db = drizzle(process.env.DATABASE_URL!);
await seed(db, { users });
}

main();
```

##

- added support for cyclic tables

You can now seed tables with cyclic relations.

```ts
import type { AnyPgColumn } from "drizzle-orm/pg-core";
import {
foreignKey,
integer,
pgTable,
serial,
varchar,
} from "drizzle-orm/pg-core";

export const modelTable = pgTable(
"model",
{
id: serial().primaryKey(),
name: varchar().notNull(),
defaultImageId: integer(),
},
(t) => [
foreignKey({
columns: [t.defaultImageId],
foreignColumns: [modelImageTable.id],
}),
]
);

export const modelImageTable = pgTable("model_image", {
id: serial().primaryKey(),
url: varchar().notNull(),
caption: varchar(),
modelId: integer()
.notNull()
.references((): AnyPgColumn => modelTable.id),
});

async function main() {
const db = drizzle(process.env.DATABASE_URL!);
await seed(db, { modelTable, modelImageTable });
}

main();
```
Loading

0 comments on commit a035a6b

Please sign in to comment.