Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): update dependency drizzle-orm to v0.33.0 #702

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Mar 30, 2024

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
drizzle-orm (source) 0.31.0 -> 0.33.0 age adoption passing confidence

Release Notes

drizzle-team/drizzle-orm (drizzle-orm)

v0.33.0

Compare Source

Breaking changes (for some of postgres.js users)

Bugs fixed for this breaking change

As we are doing with other drivers, we've changed the behavior of PostgreSQL-JS to pass raw JSON values, the same as you see them in the database. So if you are using the PostgreSQL-JS driver and passing data to Drizzle elsewhere, please check the new behavior of the client after it is passed to Drizzle.

We will update it to ensure it does not override driver behaviors, but this will be done as a complex task for everything in Drizzle in other releases

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:

update table_name
set jsonb_column = (jsonb_column #>> '{}')::jsonb;

if you are using json:

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:

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:

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

v0.32.2

Compare Source

  • Fix AWS Data API type hints bugs in RQB
  • Fix set transactions in MySQL bug - thanks @​roguesherlock
  • Add forwaring dependencies within useLiveQuery, fixes #​2651 - thanks @​anstapol
  • Export additional types from SQLite package, like AnySQLiteUpdate - thanks @​veloii

v0.32.1

Compare Source

  • Fix typings for indexes and allow creating indexes on 3+ columns mixing columns and expressions - thanks @​lbguilherme!
  • Added support for "limit 0" in all dialects - closes #​2011 - thanks @​sillvva!
  • Make inArray and notInArray accept empty list, closes #​1295 - thanks @​RemiPeruto!
  • fix typo in lt typedoc - thanks @​dalechyn!
  • fix wrong example in README.md - thanks @​7flash!

v0.32.0

Compare Source

Release notes for drizzle-orm@0.32.0 and drizzle-kit@0.23.0

It's not mandatory to upgrade both packages, but if you want to use the new features in both queries and migrations, you will need to upgrade both packages

New Features

🎉 MySQL $returningId() function

MySQL itself doesn't have native support for RETURNING after using INSERT. There is only one way to do it for primary keys with autoincrement (or serial) types, where you can access insertId and affectedRows fields. We've prepared an automatic way for you to handle such cases with Drizzle and automatically receive all inserted IDs as separate objects

import { boolean, int, text, mysqlTable } from 'drizzle-orm/mysql-core';

const usersTable = mysqlTable('users', {
  id: int('id').primaryKey(),
  name: text('name').notNull(),
  verified: boolean('verified').notNull().default(false),
});

const result = await db.insert(usersTable).values([{ name: 'John' }, { name: 'John1' }]).$returningId();
//    ^? { id: number }[]

Also with Drizzle, you can specify a primary key with $default function that will generate custom primary keys at runtime. We will also return those generated keys for you in the $returningId() call

import { varchar, text, mysqlTable } from 'drizzle-orm/mysql-core';
import { createId } from '@​paralleldrive/cuid2';

const usersTableDefFn = mysqlTable('users_default_fn', {
  customId: varchar('id', { length: 256 }).primaryKey().$defaultFn(createId),
  name: text('name').notNull(),
});

const result = await db.insert(usersTableDefFn).values([{ name: 'John' }, { name: 'John1' }]).$returningId();
//  ^? { customId: string }[]

If there is no primary keys -> type will be {}[] for such queries

🎉 PostgreSQL Sequences

You can now specify sequences in Postgres within any schema you need and define all the available properties

Example
import { pgSchema, pgSequence } from "drizzle-orm/pg-core";

// No params specified
export const customSequence = pgSequence("name");

// Sequence with params
export const customSequence = pgSequence("name", {
      startWith: 100,
      maxValue: 10000,
      minValue: 100,
      cycle: true,
      cache: 10,
      increment: 2
});

// Sequence in custom schema
export const customSchema = pgSchema('custom_schema');

export const customSequence = customSchema.sequence("name");
🎉 PostgreSQL Identity Columns

Source: As mentioned, the serial type in Postgres is outdated and should be deprecated. Ideally, you should not use it. Identity columns are the recommended way to specify sequences in your schema, which is why we are introducing the identity columns feature

Example
import { pgTable, integer, text } from 'drizzle-orm/pg-core' 

export const ingredients = pgTable("ingredients", {
  id: integer("id").primaryKey().generatedAlwaysAsIdentity({ startWith: 1000 }),
  name: text("name").notNull(),
  description: text("description"),
});

You can specify all properties available for sequences in the .generatedAlwaysAsIdentity() function. Additionally, you can specify custom names for these sequences

PostgreSQL docs reference.

🎉 PostgreSQL Generated Columns

You can now specify generated columns on any column supported by PostgreSQL to use with generated columns

Example with generated column for tsvector

Note: we will add tsVector column type before latest release

import { SQL, sql } from "drizzle-orm";
import { customType, index, integer, pgTable, text } from "drizzle-orm/pg-core";

const tsVector = customType<{ data: string }>({
  dataType() {
    return "tsvector";
  },
});

export const test = pgTable(
  "test",
  {
    id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
    content: text("content"),
    contentSearch: tsVector("content_search", {
      dimensions: 3,
    }).generatedAlwaysAs(
      (): SQL => sql`to_tsvector('english', ${test.content})`
    ),
  },
  (t) => ({
    idx: index("idx_content_search").using("gin", t.contentSearch),
  })
);

In case you don't need to reference any columns from your table, you can use just sql template or a string

export const users = pgTable("users", {
  id: integer("id"),
  name: text("name"),
  generatedName: text("gen_name").generatedAlwaysAs(sql`hello world!`),
  generatedName1: text("gen_name1").generatedAlwaysAs("hello world!"),
}),
🎉 MySQL Generated Columns

You can now specify generated columns on any column supported by MySQL to use with generated columns

You can specify both stored and virtual options, for more info you can check MySQL docs

Also MySQL has a few limitation for such columns usage, which is described here

Drizzle Kit will also have limitations for push command:

  1. You can't change the generated constraint expression and type using push. Drizzle-kit will ignore this change. To make it work, you would need to drop the column, push, and then add a column with a new expression. This was done due to the complex mapping from the database side, where the schema expression will be modified on the database side and, on introspection, we will get a different string. We can't be sure if you changed this expression or if it was changed and formatted by the database. As long as these are generated columns and push is mostly used for prototyping on a local database, it should be fast to drop and create generated columns. Since these columns are generated, all the data will be restored

  2. generate should have no limitations

Example
export const users = mysqlTable("users", {
  id: int("id"),
  id2: int("id2"),
  name: text("name"),
  generatedName: text("gen_name").generatedAlwaysAs(
    (): SQL => sql`${schema2.users.name} || 'hello'`,
    { mode: "stored" }
  ),
  generatedName1: text("gen_name1").generatedAlwaysAs(
    (): SQL => sql`${schema2.users.name} || 'hello'`,
    { mode: "virtual" }
  ),
}),

In case you don't need to reference any columns from your table, you can use just sql template or a string in .generatedAlwaysAs()

🎉 SQLite Generated Columns

You can now specify generated columns on any column supported by SQLite to use with generated columns

You can specify both stored and virtual options, for more info you can check SQLite docs

Also SQLite has a few limitation for such columns usage, which is described here

Drizzle Kit will also have limitations for push and generate command:

  1. You can't change the generated constraint expression with the stored type in an existing table. You would need to delete this table and create it again. This is due to SQLite limitations for such actions. We will handle this case in future releases (it will involve the creation of a new table with data migration).

  2. You can't add a stored generated expression to an existing column for the same reason as above. However, you can add a virtual expression to an existing column.

  3. You can't change a stored generated expression in an existing column for the same reason as above. However, you can change a virtual expression.

  4. You can't change the generated constraint type from virtual to stored for the same reason as above. However, you can change from stored to virtual.

New Drizzle Kit features

🎉 Migrations support for all the new orm features

PostgreSQL sequences, identity columns and generated columns for all dialects

🎉 New flag --force for drizzle-kit push

You can auto-accept all data-loss statements using the push command. It's only available in CLI parameters. Make sure you always use it if you are fine with running data-loss statements on your database

🎉 New migrations flag prefix

You can now customize migration file prefixes to make the format suitable for your migration tools:

  • index is the default type and will result in 0001_name.sql file names;
  • supabase and timestamp are equal and will result in 20240627123900_name.sql file names;
  • unix will result in unix seconds prefixes 1719481298_name.sql file names;
  • none will omit the prefix completely;
Example: Supabase migrations format
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "postgresql",
  migrations: {
    prefix: 'supabase'
  }
});

v0.31.4

Compare Source

  • Mark prisma clients package as optional - thanks @​Cherry

v0.31.3

Compare Source

Bug fixed
  • 🛠️ Fixed RQB behavior for tables with same names in different schemas
  • 🛠️ Fixed [BUG]: Mismatched type hints when using RDS Data API - #​2097
New Prisma-Drizzle extension
import { PrismaClient } from '@&#8203;prisma/client';
import { drizzle } from 'drizzle-orm/prisma/pg';
import { User } from './drizzle';

const prisma = new PrismaClient().$extends(drizzle());
const users = await prisma.$drizzle.select().from(User);

For more info, check docs: https://orm.drizzle.team/docs/prisma

v0.31.2

Compare Source

  • 🎉 Added support for TiDB Cloud Serverless driver:

    import { connect } from '@&#8203;tidbcloud/serverless';
    import { drizzle } from 'drizzle-orm/tidb-serverless';
    
    const client = connect({ url: '...' });
    const db = drizzle(client);
    await db.select().from(...);

v0.31.1

Compare Source

New Features

Live Queries 🎉

For a full explanation about Drizzle + Expo welcome to discussions

As of v0.31.1 Drizzle ORM now has native support for Expo SQLite Live Queries!
We've implemented a native useLiveQuery React Hook which observes necessary database changes and automatically re-runs database queries. It works with both SQL-like and Drizzle Queries:

import { useLiveQuery, drizzle } from 'drizzle-orm/expo-sqlite';
import { openDatabaseSync } from 'expo-sqlite/next';
import { users } from './schema';
import { Text } from 'react-native';

const expo = openDatabaseSync('db.db', { enableChangeListener: true }); // <-- enable change listeners
const db = drizzle(expo);

const App = () => {
  // Re-renders automatically when data changes
  const { data } = useLiveQuery(db.select().from(users));

  // const { data, error, updatedAt } = useLiveQuery(db.query.users.findFirst());
  // const { data, error, updatedAt } = useLiveQuery(db.query.users.findMany());

  return <Text>{JSON.stringify(data)}</Text>;
};

export default App;

We've intentionally not changed the API of ORM itself to stay with conventional React Hook API, so we have useLiveQuery(databaseQuery) as opposed to db.select().from(users).useLive() or db.query.users.useFindMany()

We've also decided to provide data, error and updatedAt fields as a result of hook for concise explicit error handling following practices of React Query and Electric SQL


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Enabled.

Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot added the dependencies Pull requests that update a dependency file label Mar 30, 2024
Copy link
Contributor Author

renovate bot commented Mar 30, 2024

Branch automerge failure

This PR was configured for branch automerge. However, this is not possible, so it has been raised as a PR instead.


  • Branch has one or more failed status checks

Copy link

vercel bot commented Mar 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
zws ⬜️ Ignored (Inspect) Visit Preview Sep 19, 2024 4:03pm

@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch 4 times, most recently from c7b8eeb to f291111 Compare April 2, 2024 02:01
@renovate renovate bot changed the title build(deps): update dependency drizzle-orm to v0.30.6 build(deps): update dependency drizzle-orm to v0.30.7 Apr 3, 2024
@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch 10 times, most recently from 8127784 to 4e5e16b Compare April 9, 2024 10:58
@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch 2 times, most recently from e07dcc9 to 9d8a962 Compare April 11, 2024 10:05
@renovate renovate bot changed the title build(deps): update dependency drizzle-orm to v0.30.7 build(deps): update dependency drizzle-orm to v0.30.8 Apr 11, 2024
@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch 3 times, most recently from b114a1c to 007de52 Compare April 15, 2024 23:13
@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch 3 times, most recently from 7ea8731 to 8fde36f Compare April 21, 2024 15:35
@renovate renovate bot changed the title build(deps): update dependency drizzle-orm to v0.30.8 build(deps): update dependency drizzle-orm to v0.30.9 Apr 21, 2024
@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch 2 times, most recently from d517e8d to a785e83 Compare April 24, 2024 03:33
@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch from d2dc382 to 2bf2c9a Compare July 15, 2024 19:59
Copy link

vercel bot commented Jul 15, 2024

Deployment failed with the following error:

Resource is limited - try again in 3 hours (more than 100, code: "api-deployments-free-per-day").

@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch from 2bf2c9a to b64c0b6 Compare July 23, 2024 17:09
@renovate renovate bot changed the title build(deps): update dependency drizzle-orm to v0.32.0 build(deps): update dependency drizzle-orm to v0.32.1 Jul 23, 2024
@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch 4 times, most recently from 2e569a0 to 5915819 Compare July 30, 2024 15:50
Copy link

vercel bot commented Jul 30, 2024

Deployment failed with the following error:

Resource is limited - try again in 27 minutes (more than 100, code: "api-deployments-free-per-day").

@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch from 5915819 to 607d838 Compare August 5, 2024 18:54
@renovate renovate bot changed the title build(deps): update dependency drizzle-orm to v0.32.1 build(deps): update dependency drizzle-orm to v0.32.2 Aug 5, 2024
@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch from 607d838 to 3e1381a Compare August 8, 2024 17:59
@renovate renovate bot changed the title build(deps): update dependency drizzle-orm to v0.32.2 build(deps): update dependency drizzle-orm to v0.33.0 Aug 8, 2024
@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch from 3e1381a to 475825f Compare August 8, 2024 21:32
Copy link

vercel bot commented Aug 8, 2024

Deployment failed with the following error:

Resource is limited - try again in 30 minutes (more than 100, code: "api-deployments-free-per-day").

@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch from 475825f to 358e6f2 Compare August 9, 2024 22:37
Copy link

vercel bot commented Aug 9, 2024

Deployment failed with the following error:

Resource is limited - try again in 1 hour (more than 100, code: "api-deployments-free-per-day").

@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch from 358e6f2 to f2f0c2b Compare August 10, 2024 12:40
@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch 2 times, most recently from 88db423 to cba6678 Compare August 24, 2024 10:46
Copy link

vercel bot commented Aug 24, 2024

Deployment failed with the following error:

Resource is limited - try again in 4 hours (more than 100, code: "api-deployments-free-per-day").

@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch from cba6678 to 53fe8b0 Compare August 26, 2024 16:14
@renovate renovate bot force-pushed the renovate/drizzle-orm-0.x branch 5 times, most recently from 21c5379 to c19e36a Compare September 15, 2024 23:15
Copy link

vercel bot commented Sep 15, 2024

Deployment failed with the following error:

Resource is limited - try again in 2 hours (more than 100, code: "api-deployments-free-per-day").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Development

Successfully merging this pull request may close these issues.

0 participants