-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
db: Rework index config with generated index names (#10589)
* feat: add indexes array config with name gen * fix: add _idx suffix, remove name from output * feat(test): new index config * chore: remove unused type * chore: changeset * chore: add sort() for consistent names * feat(test): consistent column ordering * feat(test): ensure no queries when migrating legacy to new
- Loading branch information
1 parent
20463a6
commit ed1031b
Showing
6 changed files
with
344 additions
and
68 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,31 @@ | ||
--- | ||
"@astrojs/db": patch | ||
--- | ||
|
||
Update the table indexes configuration to allow generated index names. The `indexes` object syntax is now deprecated in favor of an array. | ||
|
||
## Migration | ||
|
||
You can update your `indexes` configuration object to an array like so: | ||
|
||
```diff | ||
import { defineDb, defineTable, column } from 'astro:db'; | ||
|
||
const Comment = defineTable({ | ||
columns: { | ||
postId: column.number(), | ||
author: column.text(), | ||
body: column.text(), | ||
}, | ||
- indexes: { | ||
- postIdIdx: { on: 'postId' }, | ||
- authorPostIdIdx: { on: ['author, postId'], unique: true }, | ||
- }, | ||
+ indexes: [ | ||
+ { on: 'postId' /* 'name' is optional */ }, | ||
+ { on: ['author, postId'], unique: true }, | ||
+ ] | ||
}) | ||
``` | ||
|
||
This example will generate indexes with the names `Comment_postId_idx` and `Comment_author_postId_idx`, respectively. You can specify a name manually by adding the `name` attribute to a given object. This name will be **global,** so ensure index names do not conflict between tables. |
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
Oops, something went wrong.