Skip to content

Commit

Permalink
Add release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiSherman committed Aug 8, 2024
1 parent d486e9b commit 86a8714
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 61 deletions.
24 changes: 24 additions & 0 deletions changelogs/drizzle-kit/0.24.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Breaking changes (for SQLite users)

#### Fixed [Composite primary key order is not consistent](https://github.com/drizzle-team/drizzle-kit-mirror/issues/342) by removing `sort` in SQLite and to be consistant with the same logic in PostgreSQL and MySQL

The issue that may arise for SQLite users with any driver using composite primary keys is that the order in the database may differ from the Drizzle schema.

- If you are using `push`, you **MAY** be prompted to update your table with a new order of columns in the composite primary key. You will need to either change it manually in the database or push the changes, but this may lead to data loss, etc.

- If you are using `generate`, you **MAY** also be prompted to update your table with a new order of columns in the composite primary key. You can either keep that migration or skip it by emptying the SQL migration file.

If nothing works for you and you are blocked, please reach out to me @AndriiSherman. I will try to help you!


## Bug fixes

- [[BUG] When using double type columns, import is not inserted](https://github.com/drizzle-team/drizzle-kit-mirror/issues/403) - thanks @Karibash
- [[BUG] A number value is specified as the default for a column of type char](https://github.com/drizzle-team/drizzle-kit-mirror/issues/404) - thanks @Karibash
- [[BUG]: Array default in migrations are wrong](https://github.com/drizzle-team/drizzle-orm/issues/2621) - thanks @L-Mario564
- [[FEATURE]: Simpler default array fields](https://github.com/drizzle-team/drizzle-orm/issues/2709) - thanks @L-Mario564
- [[BUG]: drizzle-kit generate succeeds but generates invalid SQL for default([]) - Postgres](https://github.com/drizzle-team/drizzle-orm/issues/2432) - thanks @L-Mario564
- [[BUG]: Incorrect type for array column default value](https://github.com/drizzle-team/drizzle-orm/issues/2334) - thanks @L-Mario564
- [[BUG]: error: column is of type integer[] but default expression is of type integer](https://github.com/drizzle-team/drizzle-orm/issues/2224) - thanks @L-Mario564
- [[BUG]: Default value in array generating wrong migration file](https://github.com/drizzle-team/drizzle-orm/issues/1003) - thanks @L-Mario564
- [[BUG]: enum as array, not possible?](https://github.com/drizzle-team/drizzle-orm/issues/1564) - thanks @L-Mario564
60 changes: 60 additions & 0 deletions changelogs/drizzle-orm/0.33.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## Breaking changes (for some of postgres.js users)

#### Bugs fixed for this breaking change

- [Open
[BUG]: jsonb always inserted as a json string when using postgres-js](https://github.com/drizzle-team/drizzle-orm/issues/724)
- [[BUG]: jsonb type on postgres implement incorrectly](https://github.com/drizzle-team/drizzle-orm/issues/1511)

If you were using `postgres-js` with `jsonb` fields, you might have seen stringified objects in your database, while drizzle insert and select operations were working as expected.

You need to convert those fields from strings to actual JSON objects. To do this, you can use the following query to update your database:

**if you are using jsonb:**
```sql
update table_name
set jsonb_column = (jsonb_column #>> '{}')::jsonb;
```

**if you are using json:**
```sql
update table_name
set json_column = (json_column #>> '{}')::json;
```

We've tested it in several cases, and it worked well, but only if all stringified objects are arrays or objects. If you have primitives like strings, numbers, booleans, etc., you can use this query to update all the fields

**if you are using jsonb:**
```sql
UPDATE table_name
SET jsonb_column = CASE
-- Convert to JSONB if it is a valid JSON object or array
WHEN jsonb_column #>> '{}' LIKE '{%' OR jsonb_column #>> '{}' LIKE '[%' THEN
(jsonb_column #>> '{}')::jsonb
ELSE
jsonb_column
END
WHERE
jsonb_column IS NOT NULL;
```

**if you are using json:**
```sql
UPDATE table_name
SET json_column = CASE
-- Convert to JSON if it is a valid JSON object or array
WHEN json_column #>> '{}' LIKE '{%' OR json_column #>> '{}' LIKE '[%' THEN
(json_column #>> '{}')::json
ELSE
json_column
END
WHERE json_column IS NOT NULL;
```

If nothing works for you and you are blocked, please reach out to me @AndriiSherman. I will try to help you!

## Bug Fixes

- [[BUG]: boolean mode not working with prepared statements (bettersqlite)](https://github.com/drizzle-team/drizzle-orm/issues/2568) - thanks @veloii
- [[BUG]: isTable helper function is not working](https://github.com/drizzle-team/drizzle-orm/issues/2672) - thanks @hajek-raven
- [[BUG]: Documentation is outdated on inArray and notInArray Methods](https://github.com/drizzle-team/drizzle-orm/issues/2690) - thanks @RemiPeruto
2 changes: 1 addition & 1 deletion drizzle-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-kit",
"version": "0.23.2",
"version": "0.24.0",
"homepage": "https://orm.drizzle.team",
"keywords": [
"drizzle",
Expand Down
106 changes: 47 additions & 59 deletions drizzle-kit/src/serializer/sqliteSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export const generateSqliteSnapshot = (
as: is(generated.as, SQL)
? `(${dialect.sqlToQuery(generated.as as SQL, 'indexes').sql})`
: typeof generated.as === 'function'
? `(${dialect.sqlToQuery(generated.as() as SQL, 'indexes').sql})`
: `(${generated.as as any})`,
? `(${dialect.sqlToQuery(generated.as() as SQL, 'indexes').sql})`
: `(${generated.as as any})`,
type: generated.mode ?? 'virtual',
}
: undefined,
Expand All @@ -79,9 +79,9 @@ export const generateSqliteSnapshot = (
columnToSet.default = typeof column.default === 'string'
? `'${column.default}'`
: typeof column.default === 'object'
|| Array.isArray(column.default)
? `'${JSON.stringify(column.default)}'`
: column.default;
|| Array.isArray(column.default)
? `'${JSON.stringify(column.default)}'`
: column.default;
}
}
columnsObject[column.name] = columnToSet;
Expand All @@ -90,24 +90,19 @@ export const generateSqliteSnapshot = (
const existingUnique = indexesObject[column.uniqueName!];
if (typeof existingUnique !== 'undefined') {
console.log(
`\n${
withStyle.errorWarning(`We\'ve found duplicated unique constraint names in ${
chalk.underline.blue(
tableName,
)
`\n${withStyle.errorWarning(`We\'ve found duplicated unique constraint names in ${chalk.underline.blue(
tableName,
)
} table.
The unique constraint ${
chalk.underline.blue(
column.uniqueName,
)
} on the ${
chalk.underline.blue(
column.name,
)
} column is confilcting with a unique constraint name already defined for ${
chalk.underline.blue(
existingUnique.columns.join(','),
)
The unique constraint ${chalk.underline.blue(
column.uniqueName,
)
} on the ${chalk.underline.blue(
column.name,
)
} column is confilcting with a unique constraint name already defined for ${chalk.underline.blue(
existingUnique.columns.join(','),
)
} columns\n`)
}`,
);
Expand Down Expand Up @@ -202,26 +197,21 @@ export const generateSqliteSnapshot = (
const existingUnique = indexesObject[name];
if (typeof existingUnique !== 'undefined') {
console.log(
`\n${
withStyle.errorWarning(
`We\'ve found duplicated unique constraint names in ${
chalk.underline.blue(
tableName,
)
} table. \nThe unique constraint ${
chalk.underline.blue(
name,
)
} on the ${
chalk.underline.blue(
columnNames.join(','),
)
} columns is confilcting with a unique constraint name already defined for ${
chalk.underline.blue(
existingUnique.columns.join(','),
)
} columns\n`,
`\n${withStyle.errorWarning(
`We\'ve found duplicated unique constraint names in ${chalk.underline.blue(
tableName,
)
} table. \nThe unique constraint ${chalk.underline.blue(
name,
)
} on the ${chalk.underline.blue(
columnNames.join(','),
)
} columns is confilcting with a unique constraint name already defined for ${chalk.underline.blue(
existingUnique.columns.join(','),
)
} columns\n`,
)
}`,
);
process.exit(1);
Expand All @@ -237,7 +227,7 @@ export const generateSqliteSnapshot = (
primaryKeys.forEach((it) => {
if (it.columns.length > 1) {
primaryKeysObject[it.getName()] = {
columns: it.columns.map((it) => it.name).sort(),
columns: it.columns.map((it) => it.name),
name: it.getName(),
};
} else {
Expand Down Expand Up @@ -464,26 +454,26 @@ export const fromDatabase = async (
default: columnDefault === null
? undefined
: /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault)
? Number(columnDefault)
: ['CURRENT_TIME', 'CURRENT_DATE', 'CURRENT_TIMESTAMP'].includes(
? Number(columnDefault)
: ['CURRENT_TIME', 'CURRENT_DATE', 'CURRENT_TIMESTAMP'].includes(
columnDefault,
)
? `(${columnDefault})`
: columnDefault === 'false'
? false
: columnDefault === 'true'
? true
: columnDefault.startsWith("'") && columnDefault.endsWith("'")
? columnDefault
// ? columnDefault.substring(1, columnDefault.length - 1)
: `(${columnDefault})`,
? `(${columnDefault})`
: columnDefault === 'false'
? false
: columnDefault === 'true'
? true
: columnDefault.startsWith("'") && columnDefault.endsWith("'")
? columnDefault
// ? columnDefault.substring(1, columnDefault.length - 1)
: `(${columnDefault})`,
autoincrement: isAutoincrement,
name: columnName,
type: mapSqlToSqliteType(columnType),
primaryKey: false,
notNull: isNotNull,
generated: tableToGeneratedColumnsInfo[tableName]
&& tableToGeneratedColumnsInfo[tableName][columnName]
&& tableToGeneratedColumnsInfo[tableName][columnName]
? {
type: tableToGeneratedColumnsInfo[tableName][columnName].type,
as: tableToGeneratedColumnsInfo[tableName][columnName].expression,
Expand All @@ -509,7 +499,6 @@ export const fromDatabase = async (

for (const [key, value] of Object.entries(tableToPk)) {
if (value.length > 1) {
value.sort();
result[key].compositePrimaryKeys = {
[`${key}_${value.join('_')}_pk`]: {
columns: value,
Expand Down Expand Up @@ -580,10 +569,9 @@ export const fromDatabase = async (
const columnsTo = fkByTableName[`${tableName}_${id}`].columnsTo;
fkByTableName[
`${tableName}_${id}`
].name = `${tableName}_${
columnsFrom.join(
'_',
)
].name = `${tableName}_${columnsFrom.join(
'_',
)
}_${refTableName}_${columnsTo.join('_')}_fk`;
}

Expand Down
2 changes: 1 addition & 1 deletion drizzle-orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-orm",
"version": "0.32.2",
"version": "0.33.0",
"description": "Drizzle ORM package for SQL databases",
"type": "module",
"scripts": {
Expand Down

0 comments on commit 86a8714

Please sign in to comment.