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

Update dependency drizzle-kit to ^0.23.0 #21

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

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Nov 9, 2023

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
drizzle-kit ^0.19.13 -> ^0.23.0 age adoption passing confidence

Release Notes

drizzle-team/drizzle-kit-mirror (drizzle-kit)

v0.23.0

Compare Source

v0.22.8: 0.22.8

Compare Source

v0.22.7

Compare Source

v0.22.6: 0.22.6

Compare Source

  • 🐛 Fixed drizzle-kit up of snapshots from v6 to v7
  • 🐛 [BUG]: extensionsFilters: ['postgis'] still trying to delete spatial_ref_sys - #​2464

v0.22.5: 0.22.5

Compare Source

  • 🐛 [BUG]: Recreating pg index in version 0.31(orm) + 0.22(kit) fails - #​2470
  • 🐛 [BUG]: Drizzle migrator doesn't work with uppercase names when creating indexes - #​2457
  • 🐛 [BUG]: 'left' column name not escaped in index - #​2425
  • 🐛 [BUG]: drizzle-kit push TypeError Cannot use 'in' operator to search for 'default' in undefined - #​2385
  • 🐛 [BUG]: Breaking change in the new "PostgreSQL Indexes API" missing quotes for uppercase column letters - #​2413
  • 🐛 [BUG]: drizzle-kit migrate fail "applying migrations...error: column "authorid" does not exist" - #​2423

v0.22.4: 0.22.4

Compare Source

  • Removed data loss triggers on push when adding a NOT NULL constraint to a column and when removing the default value from a column. These actions will now be performed immediately, and if there are any NULL values in the column, you will receive an error from the database

v0.22.3: 0.22.3

Compare Source

  • 🐛 Fix Cannot use 'in' operator to search for 'default' in undefined error on push and generate

v0.22.2: 0.22.2

Compare Source

  • 🐛 Fixed index-on-expressions sql statement generation if the expression contains a ,. This should fix problems for tsvector indexes, such as:
titleSearchIndex: index('title_search_index').using('gin', sql`to_tsvector('english', ${table.title})`)

v0.22.1: 0.22.1

Compare Source

Bug fixes
  • 🐛 [BUG]: postgis geometry error: type "geometry(point)" does not exist
Improvements
  • 🎉 Drizzle Studio now supports raw responses from D1 HTTP. This means that Drizzle Studio now has full support for D1, and all queries should work as expected!

  • 🎉 Refactor the d1-http driver to properly show the table row count

v0.22.0: 0.22.0

Compare Source

New Features

🎉 Full support for indexes in PostgreSQL

The previous Drizzle+PostgreSQL indexes API was incorrect and was not aligned with the PostgreSQL documentation. The good thing is that it was not used in queries, and drizzle-kit didn't support all properties for indexes. This means we can now change the API to the correct one and provide full support for it in drizzle-kit

Previous API

  • No way to define SQL expressions inside .on.
  • .using and .on in our case are the same thing, so the API is incorrect here.
  • .asc(), .desc(), .nullsFirst(), and .nullsLast() should be specified for each column or expression on indexes, but not on an index itself.
// Index declaration reference
index('name')
  .on(table.column1, table.column2, ...) or .onOnly(table.column1, table.column2, ...)
  .concurrently()
  .using(sql``) // sql expression
  .asc() or .desc()
  .nullsFirst() or .nullsLast()
  .where(sql``) // sql expression

Current API

// First example, with `.on()`
index('name')
  .on(table.column1.asc(), table.column2.nullsFirst(), ...) or .onOnly(table.column1.desc().nullsLast(), table.column2, ...)
  .concurrently()
  .where(sql``)
  .with({ fillfactor: '70' })

// Second Example, with `.using()`
index('name')
  .using('btree', table.column1.asc(), sql`lower(${table.column2})`, table.column1.op('text_ops'))
  .where(sql``) // sql expression
  .with({ fillfactor: '70' })

🎉 Support for new types

Drizzle Kit can now handle:

  • point and line from PostgreSQL
  • vector from the PostgreSQL pg_vector extension
  • geometry from the PostgreSQL PostGIS extension

🎉 New param in drizzle.config - extensionsFilters

The PostGIS extension creates a few internal tables in the public schema. This means that if you have a database with the PostGIS extension and use push or introspect, all those tables will be included in diff operations. In this case, you would need to specify tablesFilter, find all tables created by the extension, and list them in this parameter.

We have addressed this issue so that you won't need to take all these steps. Simply specify extensionsFilters with the name of the extension used, and Drizzle will skip all the necessary tables.

Currently, we only support the postgis option, but we plan to add more extensions if they create tables in the public schema.

The postgis option will skip the geography_columns, geometry_columns, and spatial_ref_sys tables

import { defineConfig } from 'drizzle-kit'

export default defaultConfig({
  dialect: "postgresql",
  extensionsFilters: ["postgis"],
})

Improvements

👍 Update zod schemas for database credentials and write tests to all the positive/negative cases
👍 Support full set of SSL params in kit config, provide types from node:tls connection
import { defineConfig } from 'drizzle-kit'

export default defaultConfig({
  dialect: "postgresql",
  dbCredentials: {
    ssl: true, //"require" | "allow" | "prefer" | "verify-full" | options from node:tls
  }
})
import { defineConfig } from 'drizzle-kit'

export default defaultConfig({
  dialect: "mysql",
  dbCredentials: {
    ssl: "", // string | SslOptions (ssl options from mysql2 package)
  }
})
👍 Normilized SQLite urls for libsql and better-sqlite3 drivers

Those drivers have different file path patterns, and Drizzle Kit will accept both and create a proper file path format for each

👍 Updated MySQL and SQLite index-as-expression behavior

In this release MySQL and SQLite will properly map expressions into SQL query. Expressions won't be escaped in string but columns will be

export const users = sqliteTable(
  'users',
  {
    id: integer('id').primaryKey(),
    email: text('email').notNull(),
  },
  (table) => ({
    emailUniqueIndex: uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
  }),
);
-- before
CREATE UNIQUE INDEX `emailUniqueIndex` ON `users` (`lower("users"."email")`);

-- now
CREATE UNIQUE INDEX `emailUniqueIndex` ON `users` (lower("email"));

Bug Fixes

  • [BUG]: multiple constraints not added (only the first one is generated) - #​2341
  • Drizzle Studio: Error: Connection terminated unexpectedly - #​435
  • Unable to run sqlite migrations local - #​432
  • error: unknown option '--config' - #​423

How push and generate works for indexes

Limitations
You should specify a name for your index manually if you have an index on at least one expression

Example

index().on(table.id, table.email) // will work well and name will be autogeneretaed
index('my_name').on(table.id, table.email) // will work well

// but

index().on(sql`lower(${table.email})`) // error
index('my_name').on(sql`lower(${table.email})`) // will work well
Push won't generate statements if these fields(list below) were changed in an existing index:
  • expressions inside .on() and .using()
  • .where() statements
  • operator classes .op() on columns

If you are using push workflows and want to change these fields in the index, you would need to:

  • Comment out the index
  • Push
  • Uncomment the index and change those fields
  • Push again

For the generate command, drizzle-kit will be triggered by any changes in the index for any property in the new drizzle indexes API, so there are no limitations here.

v0.21.4

Compare Source

bug fixes

  • fix node-pg pool connection halting, regression introduced in previous release while migrating from client to pool with max 1 connection

v0.21.3

Compare Source

Cloudflare D1 HTTP API support 🎉
Drizzle Chrome Extension now has support for Cloudflare D1!

Drizzle Kit now lets you run migrate, push, introspect and studio commands using Cloudflare D1 HTTP API, you just need to update connection params in drizzle.config.ts:

dialect: "sqlite",
+ driver: "d1-http",
dbCredentials: {
+  accountId: "...",
+  databaseId: "...",
+  token: "...",
}

You can find accountId, databaseId and token in Cloudflare dashboard
To get accountId go to Workers & Pages -> Overview -> copy Account ID from the right sidebar
To get databaseId open D1 database you want to connect to and copy Database ID
To get token go to My profile -> API Tokens and create token with D1 edit permissions

Bug fixes

v0.21.2

Compare Source

Bug fixes

A list of regressions after 0.21.0 that were fixed (there are more, and those should be fixed in the next patch releases):

  • SQLite generate and push were not detecting new columns added.
  • Timestamps with precision in Postgres were always detected as a change on push
  • Unique constraints for PostgreSQL were not generated and pushed
  • When adding columns to SQLite, table name was not escaped

Tickets that were closed

  • 🐛 [BUG]:"drizzle-kit generate" doesn't generate a migration file when a column is added - 2307
  • 🐛 [BUG]: Unique constraint is not added to the change - 2302
  • 🐛 [bug]: drizzle-kit push is not detecting changes correctly (Turso) - #​397

v0.21.1

Compare Source

Drizzle Studio support for per-database preferences

When connecting to different databases with Drizzle Local Studio, we will store all preferences such as selected tabs, hidden columns, pagination, etc., separately for each database

Drizzle Studio support for advanced bug report context

Now you can assist us in debugging Drizzle Studio errors. No more need to say, "Please share your schema with us"; just click a button, download the bug report, and send it to us!

image

image

v0.21.0

Compare Source

Breaking changes
❗ Snapshots Upgrade

All PostgreSQL and SQLite-generated snapshots will be upgraded to version 6. You will be prompted to upgrade them by running drizzle-kit up

❗ Removing :dialect from drizzle-kit cli commands

You can now just use commands, like:

  • drizzle-kit generate
  • drizzle-kit push
  • etc.

without specifying dialect. This param is moved to drizzle.config.ts

drizzle.config update
  • dialect is now mandatory; specify which database dialect you are connecting to. Options include mysql, postgresql, or sqlite.
  • driver has become optional and will have a specific driver, each with a different configuration of dbCredentials. Available drivers are:
    • aws-data-api
    • turso
    • d1-http - currently WIP
    • expo
  • url - a unified parameter for the previously existing connectionString and uri.
  • migrations - a new object parameter to specify a custom table and schema for the migrate command:
    • table - the custom table where drizzle will store migrations.
    • schema - the custom schema where drizzle will store migrations (Postgres only).

Usage examples for all new and updated commands

import { defineConfig } from "drizzle-kit"

export default defineConfig({
    dialect: "sqlite", // "postgresql" | "mysql"
    driver: "turso"
    dbCredentials: {
        url: ""
    },
    migration: {
        table: "migrations",
        schema: "public"
    }
})

Drizzle driver selection follows the current strategy:

If a driver is specified, use this driver for querying.

If no driver is specified:

  • For postgresql dialect, Drizzle will:

    • Check if the pg driver is installed and use it.
    • If not, try to find the postgres driver and use it.
    • If still not found, try to find @vercel/postgres.
    • Then try @neondatabase/serverless.
    • If nothing is found, an error will be thrown.
  • For mysql dialect, Drizzle will:

    • Check if the mysql2 driver is installed and use it.
    • If not, try to find @planetscale/database and use it.
    • If nothing is found, an error will be thrown.
  • For sqlite dialect, Drizzle will:

    • Check if the @libsql/client driver is installed and use it.
    • If not, try to find better-sqlite3 and use it.
    • If nothing is found, an error will be thrown
❗ MySQL schemas/database are no longer supported by drizzle-kit

Drizzle Kit won't handle any schema changes for additional schemas/databases in your drizzle schema file

New Features
🎉 Pull relations

Drizzle will now pull relations from the database by extracting foreign key information and translating it into a relations object. You can view the relations.ts file in the out folder after introspection is complete

For more info about relations, please check the docs

🎉 Custom name for generated migrations

To specify a name for your migration you should use --name <name>

Usage

drizzle-kit generate --name init_db
🎉 New command migrate

You can now apply generated migrations to your database directly from drizzle-kit

Usage

drizzle-kit migrate

By default, drizzle-kit will store migration data entries in the __drizzle_migrations table and, in the case of PostgreSQL, in a drizzle schema. If you want to change this, you will need to specify the modifications in drizzle.config.ts.

import { defineConfig } from "drizzle-kit"

export default defineConfig({
    migrations: {
        table: "migrations",
        schema: "public"
    }
})
How to migrate from 0.20.18 to 0.21.0
1. Remove all :dialect prefixes from your Drizzle-Kit commands.

Example: Change drizzle-kit push:mysql to drizzle-kit push.

2. Update your drizzle.config.ts file:
  • Add dialect to drizzle.config.ts. It is now mandatory and can be 'postgresql', 'mysql', or 'sqlite'.
  • Add driver to drizzle.config.ts ONLY if you are using aws-data-api, turso, d1-http(WIP), or expo. Otherwise, you can remove the driver from drizzle.config.ts.
  • If you were using connectionString or uri in dbCredentials, you should now use url.
import { defineConfig } from "drizzle-kit"

export default defineConfig({
    dialect: "sqlite", // "postgresql" | "mysql"
    driver: "turso" // optional and used only if `aws-data-api`, `turso`, `d1-http`(WIP) or `expo` are used
    dbCredentials: {
        url: ""
    }
})
3. If you are using PostgreSQL and had migrations generated in your project, please run drizzle-kit up so Drizzle can upgrade all the snapshots to version 6.

v0.20.18

Compare Source

v0.20.17: 0.20.17

Compare Source

  • Fixed $default values to work with new local drizzle studio. You will be forced to upgrade drizzle-kit

v0.20.16

Compare Source

  • Fixed 0.20.15 bugs and force to upgrade from studio UI

v0.20.15

Compare Source

  • Moving server instantiations from Local Drizzle Studio to drizzle-kit. Local Studio will now require an upgrade to the latest version of drizzle-kit

v0.20.14: 0.20.14

Compare Source

  • 🐛 When upgrading from <0.20.0 to 0.20.0+, if you have composite primary keys and are using the generate command only for SQLite database, you may encounter a malformed error from drizzle-kit for all snapshots. This issue has been fixed in this version

v0.20.13: 0.20.13

Compare Source

v0.20.12: 0.20.12

Compare Source

  • Made schemaTo optional during the serialize step, preventing unnecessary drop+create foreign key statements from appearing.

  • Fixed an issue: when using a barrel file, drizzle-kit was exporting duplicated tables, leading to an error with multiple indexes having the same name. It should now remove duplicates and function as expected

v0.20.11: 0.20.11

Compare Source

  • 🐛 [BUG]: how to recover from snapshot.json data is malformed #​1554

v0.20.10: 0.20.10

Compare Source

  • 🐛 [BUG]: drizzle-kit generates incorrect foreign key references to a table from a different schema when using pgSchema #​636
  • 🐛 Introspect error #​277

v0.20.9: 0.20.9

Compare Source

  • Local Drizzle Studio proper support for Safari with mkcert
  • Remove wrangler from prod deps

v0.20.8: 0.20.8

Compare Source

Bug Fixes

  • Fixed introspect and push for PlanetScale. A newly added feature to PlanetScale was not functioning properly with the 'drizzle-kit introspect' and 'push' commands, failing to retrieve foreign keys from a database. This issue should now be resolved

New Drivers

🎉 Expo SQLite Driver is available

For starting with Expo SQLite Driver, you need to install expo-sqlite and drizzle-orm packages.

npm install drizzle-orm expo-sqlite@next

Then, you can use it like this:

import { drizzle } from "drizzle-orm/expo-sqlite";
import { openDatabaseSync } from "expo-sqlite/next";

const expoDb = openDatabaseSync("db.db");

const db = drizzle(expoDb);

await db.select().from(...)...

// or

db.select().from(...).then(...);

// or

db.select().from(...).all();

If you want to use Drizzle Migrations, you need to update babel and metro configuration files.

  1. Install babel-plugin-inline-import package.
npm install babel-plugin-inline-import
  1. Update babel.config.js and metro.config.js files.

babel.config.js

module.exports = function(api) {
  api.cache(true);

  return {
    presets: ['babel-preset-expo'],
+   plugins: [["inline-import", { "extensions": [".sql"] }]]
  };
};

metro.config.js

const { getDefaultConfig } = require('expo/metro-config');

/** @&#8203;type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);

+config.resolver.sourceExts.push('sql');

module.exports = config;
  1. Create drizzle.config.ts file in your project root folder.
import type { Config } from 'drizzle-kit';

export default {
	schema: './db/schema.ts',
	out: './drizzle',
	driver: 'expo',
} satisfies Config;

After creating schema file and drizzle.config.ts file, you can generate migrations like this:

npx drizzle-kit generate:sqlite

Then you need to import migrations.js file in your App.tsx file from ./drizzle folder and use hook useMigrations or migrate function.

import { drizzle } from "drizzle-orm/expo-sqlite";
import { openDatabaseSync } from "expo-sqlite/next";
import { useMigrations } from 'drizzle-orm/expo-sqlite/migrator';
import migrations from './drizzle/migrations';

const expoDb = openDatabaseSync("db.db");

const db = drizzle(expoDb);

export default function App() {
    const { success, error } = useMigrations(db, migrations);

    if (error) {
        return (
            <View>
                <Text>Migration error: {error.message}</Text>
            </View>
        );
    }

    if (!success) {
        return (
            <View>
                <Text>Migration is in progress...</Text>
            </View>
        );
    }

    return ...your application component;
}

v0.20.7: 0.20.7

Compare Source

Bug fixes

  • BUG drizzle-kit introspect:mysql from Planetscale db returns wrong primary key #​216
  • BUG: v0.20.2 push:mysql error: there can be only one auto column and it must be defined as a key #​234
  • Fixed dropping all primary keys and creating them 1 more time

Improvements

  • Check names for indexes and notify if you have specified the same index names within the schema.
  • Verify that auto-increment can only be created for primary keys in MySQL

v0.20.6

Compare Source

v0.20.5

Compare Source

v0.20.4

Compare Source

v0.20.3

Compare Source

v0.20.2

Compare Source

v0.20.1

Compare Source

v0.20.0: 0.20.0

Compare Source

Drizzle ORM version 0.29.0 will require a minimum Drizzle Kit version of 0.20.0, and vice versa. Therefore, when upgrading to a newer version of Drizzle ORM, you will also need to upgrade Drizzle Kit. This may result in some breaking changes throughout the versions, especially if you need to upgrade Drizzle Kit and your Drizzle ORM version is older than <0.28.0

New Features

New way to define drizzle.config using defineConfig function

import { defineConfig } from 'drizzle-kit/utils'

export default defineConfig({
  schema: "./schema.ts",
  out: "./drizzle",
  driver: "..",
  dbCredentials: {
    // connection
  },
  verbose: true,
  strict: true,
})

Possibility to access Cloudflare D1 with Drizzle Studio using wrangler.toml file

You can now use Drizzle Studio with your D1 database. Please note that it may be slow at times because Drizzle Studio utilizes Wrangler CLI calls to perform data selection, updates, deletions, and insertions. The speed of these operations depends on the performance of Wrangler CLI calls.

To use Drizzle Studio with the D1 database, you need to provide the file path to your wrangler.toml file and specify the dbName you are using in Cloudflare D1

import { defineConfig } from 'drizzle-kit/utils'

export default defineConfig({
  schema: "./schema.ts",
  out: "./drizzle",
  driver: "d1",
  dbCredentials: {
    wranglerConfigPath: 'wrangler.toml',
    dbName: 'd1-test'
  },
  verbose: true,
  strict: true,
})

And then run drizzle-kit studio

Note: make sure you have wrangler cli installed globally or inside your project and you invoked wrangler login before running studio

Drizzle Studio is migrating to https://local.drizzle.studio/

Previously, Drizzle Studio used 127.0.0.1:4983 as the default host and port for the web page. Currently, Drizzle Studio will always be hosted on https://local.drizzle.studio/, connecting to the backend at 127.0.0.1:4983. You can modify the host and port for the backend server by using the --host and --port options in drizzle-kit studio.

local.drizzle.studio provides the ability to ship updates to the Drizzle Studio web UI immediately, eliminating the need for constant drizzle-kit upgrades

bigint unsigned support

This option is now available in the introspect, push, and generate commands.

primaryKeys and foreignKeys now can have custom names

This option is now available in the introspect, push, and generate commands.

Environment variables are now fetched automatically

As mentioned many times, you can finally skip fetching environment variables to use with the drizzle.config file. Drizzle Kit will handle this process automatically.

Drizzle Studio Updates

  • Refresh button for the view inside a table.
  • Possibility to choose schemas for Postgres. For MySQL and SQLite, public will be the default, and the only choice.

Improvements

  • remove libsql_wasm_func_table from sqlite introspect and push
  • Handle primaryKey columns order for composite constraints

Bug Fixes

  • Fix the case, when having turso or libsql driver user was seeing an error with no better-sqlite3 dependency
  • Add tableFilters to cli options in all push commands
  • Fix dropping unique indexes syntax for push and generate command

Configuration

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

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, 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 has been generated by Mend Renovate. View repository job log here.

@renovate renovate bot changed the title Update dependency drizzle-kit to ^0.20.0 Update dependency drizzle-kit to ^0.21.0 May 9, 2024
@renovate renovate bot force-pushed the renovate/drizzle-kit-0.x branch from 6fcbe65 to 4b67f45 Compare May 9, 2024 14:27
@renovate renovate bot force-pushed the renovate/drizzle-kit-0.x branch from 4b67f45 to 3852229 Compare May 31, 2024 08:36
@renovate renovate bot changed the title Update dependency drizzle-kit to ^0.21.0 Update dependency drizzle-kit to ^0.22.0 May 31, 2024
@renovate renovate bot force-pushed the renovate/drizzle-kit-0.x branch from 3852229 to 4ae8d23 Compare July 10, 2024 14:52
@renovate renovate bot changed the title Update dependency drizzle-kit to ^0.22.0 Update dependency drizzle-kit to ^0.23.0 Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants