Skip to content

Commit

Permalink
Merge pull request drizzle-team#3879 from drizzle-team/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
AndriiSherman authored Dec 31, 2024
2 parents 06be106 + c8a4996 commit 04c9143
Show file tree
Hide file tree
Showing 17 changed files with 1,596 additions and 115 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@ dist-dts
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
drizzle-seed/src/dev
40 changes: 40 additions & 0 deletions changelogs/drizzle-seed/0.3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# New features

## Drizzle Relations support

The `seed` function can now accept Drizzle Relations objects and treat them as foreign key constraints


```ts
// schema.ts
import { integer, serial, text, pgTable } from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm';
export const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
});
export const usersRelations = relations(users, ({ many }) => ({
posts: many(posts),
}));
export const posts = pgTable('posts', {
id: serial('id').primaryKey(),
content: text('content').notNull(),
authorId: integer('author_id').notNull(),
});
export const postsRelations = relations(posts, ({ one }) => ({
author: one(users, { fields: [posts.authorId], references: [users.id] }),
}));
```

```ts
// index.ts
import { seed } from "drizzle-seed";
import * as schema from './schema.ts'

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

main();
```
4 changes: 2 additions & 2 deletions drizzle-seed/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-seed",
"version": "0.2.1",
"version": "0.3.0",
"main": "index.js",
"type": "module",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"generate-for-tests:mysql": "drizzle-kit generate --config=./src/tests/mysql/drizzle.config.ts",
"generate-for-tests:sqlite": "drizzle-kit generate --config=./src/tests/sqlite/drizzle.config.ts",
"generate": "drizzle-kit generate",
"start": "npx tsx ./src/test.ts",
"start": "npx tsx ./src/dev/test.ts",
"start:pg": "npx tsx ./src/tests/northwind/pgTest.ts",
"start:mysql": "npx tsx ./src/tests/northwind/mysqlTest.ts",
"start:sqlite": "npx tsx ./src/tests/northwind/sqliteTest.ts",
Expand Down
Loading

0 comments on commit 04c9143

Please sign in to comment.