-
-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support varchar for postgres using sql column type * added checks to string-like generators, updated sqlite and mysql seeding using sql column type * added array support for studio * updated postgres interval generators to work with fields, added tests * fixes, partial implementation of generator versioning * added generator versioning with version v1 for string and interval generators * updated changelogs * updated generator versioning * updated changelogs * Review * changes in generator selection * updated generator versioning * bug fix, refine functions versioning * fixes * fixes * Change release notes text * Bump version --------- Co-authored-by: Andrii Sherman <[email protected]>
- Loading branch information
1 parent
019d9b0
commit 414ffd9
Showing
25 changed files
with
2,567 additions
and
1,408 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,166 @@ | ||
## 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 }) | ||
``` | ||
|
||
Functions from refine that will be affected by this change: `` | ||
|
||
## 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) |
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 |
---|---|---|
|
@@ -4844,3 +4844,5 @@ export default [ | |
'zonked', | ||
'zoological', | ||
]; | ||
|
||
export const maxStringLength = 22; |
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 |
---|---|---|
|
@@ -42857,3 +42857,5 @@ export default [ | |
'Garches', | ||
'Chemini', | ||
]; | ||
|
||
export const maxStringLength = 49; |
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 |
---|---|---|
|
@@ -25,3 +25,5 @@ export default [ | |
'Co.', | ||
'SCC', | ||
]; | ||
|
||
export const maxStringLength = 7; |
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 |
---|---|---|
|
@@ -169,3 +169,5 @@ export default [ | |
'Yemen', | ||
'Zambia', | ||
]; | ||
|
||
export const maxStringLength = 30; |
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 |
---|---|---|
|
@@ -22,3 +22,5 @@ export default [ | |
'ymail.com', | ||
'libero.it', | ||
]; | ||
|
||
export const maxStringLength = 14; |
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 |
---|---|---|
|
@@ -30277,3 +30277,5 @@ export default [ | |
'Lavasia', | ||
'Laniqua', | ||
]; | ||
|
||
export const maxStringLength = 15; |
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 |
---|---|---|
|
@@ -150,3 +150,5 @@ export default [ | |
'Legal secretary', | ||
'Market analyst', | ||
]; | ||
|
||
export const maxStringLength = 35; |
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 |
---|---|---|
|
@@ -50001,3 +50001,5 @@ export default [ | |
'Thagard', | ||
'Leavelle', | ||
]; | ||
|
||
export const maxStringLength = 15; |
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 |
---|---|---|
|
@@ -50,3 +50,5 @@ export default [ | |
'Wisconsin', | ||
'Wyoming', | ||
]; | ||
|
||
export const maxStringLength = 14; |
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 |
---|---|---|
|
@@ -198,3 +198,5 @@ export default [ | |
'Well', | ||
'Wells', | ||
]; | ||
|
||
export const maxStringLength = 10; |
Oops, something went wrong.