-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update seed to use export default function() instead of top-level awa…
…it (#10334) * Update fixtures seed files to export default function * Call default export when running seed files * Add changeset
- Loading branch information
Showing
6 changed files
with
117 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
"@astrojs/db": minor | ||
--- | ||
|
||
Changes the seed file format to require exporting a default function instead of running seed code at the top level. | ||
|
||
To migrate a seed file, wrap your existing code in a default function export: | ||
|
||
```diff | ||
// db/seed.ts | ||
import { db, Table } from 'astro:db'; | ||
|
||
+ export default async function() { | ||
await db.insert(Table).values({ foo: 'bar' }); | ||
+ } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,62 @@ | ||
import { Ingredient, Recipe, db } from 'astro:db'; | ||
|
||
const pancakes = await db | ||
.insert(Recipe) | ||
.values({ | ||
title: 'Pancakes', | ||
description: 'A delicious breakfast', | ||
}) | ||
.returning() | ||
.get(); | ||
export default async function () { | ||
const pancakes = await db | ||
.insert(Recipe) | ||
.values({ | ||
title: 'Pancakes', | ||
description: 'A delicious breakfast', | ||
}) | ||
.returning() | ||
.get(); | ||
|
||
await db.insert(Ingredient).values([ | ||
{ | ||
name: 'Flour', | ||
quantity: 1, | ||
recipeId: pancakes.id, | ||
}, | ||
{ | ||
name: 'Eggs', | ||
quantity: 2, | ||
recipeId: pancakes.id, | ||
}, | ||
{ | ||
name: 'Milk', | ||
quantity: 1, | ||
recipeId: pancakes.id, | ||
}, | ||
]); | ||
await db.insert(Ingredient).values([ | ||
{ | ||
name: 'Flour', | ||
quantity: 1, | ||
recipeId: pancakes.id, | ||
}, | ||
{ | ||
name: 'Eggs', | ||
quantity: 2, | ||
recipeId: pancakes.id, | ||
}, | ||
{ | ||
name: 'Milk', | ||
quantity: 1, | ||
recipeId: pancakes.id, | ||
}, | ||
]); | ||
|
||
const pizza = await db | ||
.insert(Recipe) | ||
.values({ | ||
title: 'Pizza', | ||
description: 'A delicious dinner', | ||
}) | ||
.returning() | ||
.get(); | ||
const pizza = await db | ||
.insert(Recipe) | ||
.values({ | ||
title: 'Pizza', | ||
description: 'A delicious dinner', | ||
}) | ||
.returning() | ||
.get(); | ||
|
||
await db.insert(Ingredient).values([ | ||
{ | ||
name: 'Flour', | ||
quantity: 1, | ||
recipeId: pizza.id, | ||
}, | ||
{ | ||
name: 'Eggs', | ||
quantity: 2, | ||
recipeId: pizza.id, | ||
}, | ||
{ | ||
name: 'Milk', | ||
quantity: 1, | ||
recipeId: pizza.id, | ||
}, | ||
{ | ||
name: 'Tomato Sauce', | ||
quantity: 1, | ||
recipeId: pizza.id, | ||
}, | ||
]); | ||
await db.insert(Ingredient).values([ | ||
{ | ||
name: 'Flour', | ||
quantity: 1, | ||
recipeId: pizza.id, | ||
}, | ||
{ | ||
name: 'Eggs', | ||
quantity: 2, | ||
recipeId: pizza.id, | ||
}, | ||
{ | ||
name: 'Milk', | ||
quantity: 1, | ||
recipeId: pizza.id, | ||
}, | ||
{ | ||
name: 'Tomato Sauce', | ||
quantity: 1, | ||
recipeId: pizza.id, | ||
}, | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { Event, db } from 'astro:db'; | ||
|
||
await db.insert(Event).values({ | ||
name: 'Sampha LIVE in Brooklyn', | ||
description: | ||
'Sampha is on tour with his new, flawless album Lahai. Come see the live performance outdoors in Prospect Park. Yes, there will be a grand piano 🎹', | ||
date: new Date('2024-01-01'), | ||
ticketPrice: 10000, | ||
location: 'Brooklyn, NY', | ||
}); | ||
export default async function () { | ||
await db.insert(Event).values({ | ||
name: 'Sampha LIVE in Brooklyn', | ||
description: | ||
'Sampha is on tour with his new, flawless album Lahai. Come see the live performance outdoors in Prospect Park. Yes, there will be a grand piano 🎹', | ||
date: new Date('2024-01-01'), | ||
ticketPrice: 10000, | ||
location: 'Brooklyn, NY', | ||
}); | ||
} |