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

[Snyk] Upgrade drizzle-orm from 0.32.2 to 0.36.0 #19

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

Conversation

ShivajiVS
Copy link
Owner

snyk-top-banner

Snyk has created this PR to upgrade drizzle-orm from 0.32.2 to 0.36.0.

ℹ️ Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project.


  • The recommended version is 107 versions ahead of your current version.

  • The recommended version was released on a month ago.

Release notes
Package name: drizzle-orm
  • 0.36.0 - 2024-10-30

    This version of drizzle-orm requires drizzle-kit@0.27.0 to enable all new features

    New Features

    The third parameter in Drizzle ORM becomes an array

    The object API is still available but deprecated

    Instead of this

    pgTable('users', {
        id: integer().primaryKey(),
    }, (t) => ({
        index: index('test').on(t.id),
    }));

    You can now do this

    pgTable('users', {
        id: integer().primaryKey(),
    }, (t) => [index('test').on(t.id)]);

    Row-Level Security (RLS)

    With Drizzle, you can enable Row-Level Security (RLS) for any Postgres table, create policies with various options, and define and manage the roles those policies apply to.

    Drizzle supports a raw representation of Postgres policies and roles that can be used in any way you want. This works with popular Postgres database providers such as Neon and Supabase.

    In Drizzle, we have specific predefined RLS roles and functions for RLS with both database providers, but you can also define your own logic.

    Enable RLS

    If you just want to enable RLS on a table without adding policies, you can use .enableRLS()

    As mentioned in the PostgreSQL documentation:

    If no policy exists for the table, a default-deny policy is used, meaning that no rows are visible or can be modified.
    Operations that apply to the whole table, such as TRUNCATE and REFERENCES, are not subject to row security.

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

    export const users = pgTable('users', {
    id: integer(),
    }).enableRLS();

    If you add a policy to a table, RLS will be enabled automatically. So, there’s no need to explicitly enable RLS when adding policies to a table.

    Roles

    Currently, Drizzle supports defining roles with a few different options, as shown below. Support for more options will be added in a future release.

    import { pgRole } from 'drizzle-orm/pg-core';

    export const admin = pgRole('admin', { createRole: true, createDb: true, inherit: true });

    If a role already exists in your database, and you don’t want drizzle-kit to ‘see’ it or include it in migrations, you can mark the role as existing.

    import { pgRole } from 'drizzle-orm/pg-core';

    export const admin = pgRole('admin').existing();

    Policies

    To fully leverage RLS, you can define policies within a Drizzle table.

    In PostgreSQL, policies should be linked to an existing table. Since policies are always associated with a specific table, we decided that policy definitions should be defined as a parameter of pgTable

    Example of pgPolicy with all available properties

    import { sql } from 'drizzle-orm';
    import { integer, pgPolicy, pgRole, pgTable } from 'drizzle-orm/pg-core';

    export const admin = pgRole('admin');

    export const users = pgTable('users', {
    id: integer(),
    }, (t) => [
    pgPolicy('policy', {
    as: 'permissive',
    to: admin,
    for: 'delete',
    using: sql</span><span class="pl-kos">,</span> <span class="pl-c1">withCheck</span>: <span class="pl-en">sql</span><span class="pl-s">,
    }),
    ]);

    Link Policy to an existing table

    There are situations where you need to link a policy to an existing table in your database.
    The most common use case is with database providers like Neon or Supabase, where you need to add a policy
    to their existing tables. In this case, you can use the .link() API

    import { sql } from "drizzle-orm";
    import { pgPolicy } from "drizzle-orm/pg-core";
    import { authenticatedRole, realtimeMessages } from "drizzle-orm/supabase";

    export const policy = pgPolicy("authenticated role insert policy", {
    for: "insert",
    to: authenticatedRole,
    using: sql``,
    }).link(realtimeMessages);

    Migrations

    If you are using drizzle-kit to manage your schema and roles, there may be situations where you want to refer to roles that are not defined in your Drizzle schema. In such cases, you may want drizzle-kit to skip managing these roles without having to define each role in your drizzle schema and marking it with .existing().

    In these cases, you can use entities.roles in drizzle.config.ts. For a complete reference, refer to the the drizzle.config.ts documentation.

    By default, drizzle-kit does not manage roles for you, so you will need to enable this feature in drizzle.config.ts.

    // drizzle.config.ts
    import { defineConfig } from "drizzle-kit";

    export default defineConfig({
    dialect: 'postgresql',
    schema: "./drizzle/schema.ts",
    dbCredentials: {
    url: process.env.DATABASE_URL!
    },
    verbose: true,
    strict: true,
    entities: {
    roles: true
    }
    });

    In case you need additional configuration options, let's take a look at a few more examples.

    You have an admin role and want to exclude it from the list of manageable roles

    // drizzle.config.ts
    import { defineConfig } from "drizzle-kit";

    export default defineConfig({
    ...
    entities: {
    roles: {
    exclude: ['admin']
    }
    }
    });

    You have an admin role and want to include it in the list of manageable roles

    // drizzle.config.ts
    import { defineConfig } from "drizzle-kit";

    export default defineConfig({
    ...
    entities: {
    roles: {
    include: ['admin']
    }
    }
    });

    If you are using Neon and want to exclude Neon-defined roles, you can use the provider option

    // drizzle.config.ts
    import { defineConfig } from "drizzle-kit";

    export default defineConfig({
    ...
    entities: {
    roles: {
    provider: 'neon'
    }
    }
    });

    If you are using Supabase and want to exclude Supabase-defined roles, you can use the provider option

    // drizzle.config.ts
    import { defineConfig } from "drizzle-kit";

    export default defineConfig({
    ...
    entities: {
    roles: {
    provider: 'supabase'
    }
    }
    });

    You may encounter situations where Drizzle is slightly outdated compared to new roles specified by your database provider.
    In such cases, you can use the provider option and exclude additional roles:

    // drizzle.config.ts
    import { defineConfig } from "drizzle-kit";

    export default defineConfig({
    ...
    entities: {
    roles: {
    provider: 'supabase',
    exclude: ['new_supabase_role']
    }
    }
    });

    RLS on views

    With Drizzle, you can also specify RLS policies on views. For this, you need to use security_invoker in the view's WITH options. Here is a small example:

    export const roomsUsersProfiles = pgView("rooms_users_profiles")
    .with({
    securityInvoker: true,
    })
    .as((qb) =>
    qb
    .select({
    ...getTableColumns(roomsUsers),
    email: profiles.email,
    })
    .from(roomsUsers)
    .innerJoin(profiles, eq(roomsUsers.userId, profiles.id))
    );

    Using with Neon

    The Neon Team helped us implement their vision of a wrapper on top of our raw policies API. We defined a specific
    /neon import with the crudPolicy function that includes predefined functions and Neon's default roles.

    Here's an example of how to use the crudPolicy function:

    import { crudPolicy } from 'drizzle-orm/neon';
    import { integer, pgRole, pgTable } from 'drizzle-orm/pg-core';

    export const admin = pgRole('admin');

    export const users = pgTable('users', {
    id: integer(),
    }, (t) => [
    crudPolicy({ role: admin, read: true, modify: false }),
    ]);

    This policy is equivalent to:

    import { sql } from 'drizzle-orm';
    import { integer, pgPolicy, pgRole, pgTable } from 'drizzle-orm/pg-core';

    export const admin = pgRole('admin');

    export const users = pgTable('users', {
    id: integer(),
    }, (t) => [
    pgPolicy(crud-<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">admin</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">}</span></span>-policy-insert, {
    for: 'insert',
    to: admin,
    withCheck: sqlfalse,
    }),
    pgPolicy(crud-<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">admin</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">}</span></span>-policy-update, {
    for: 'update',
    to: admin,
    using: sqlfalse,
    withCheck: sqlfalse,
    }),
    pgPolicy(crud-<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">admin</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">}</span></span>-policy-delete, {
    for: 'delete',
    to: admin,
    using: sqlfalse,
    }),
    pgPolicy(crud-<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">admin</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">}</span></span>-policy-select, {
    for: 'select',
    to: admin,
    using: sqltrue,
    }),
    ]);

    Neon exposes predefined authenticated and anaonymous roles and related functions. If you are using Neon for RLS, you can use these roles, which are marked as existing, and the related functions in your RLS queries.

    // drizzle-orm/neon
    export const authenticatedRole = pgRole('authenticated').existing();
    export const anonymousRole = pgRole('anonymous').existing();

    export const authUid = (userIdColumn: AnyPgColumn) => sql(select auth.user_id() = <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">userIdColumn</span><span class="pl-kos">}</span></span>);

    For example, you can use the Neon predefined roles and functions like this:

    import { sql } from 'drizzle-orm';
    import { authenticatedRole } from 'drizzle-orm/neon';
    import { integer, pgPolicy, pgRole, pgTable } from 'drizzle-orm/pg-core';

    export const admin = pgRole('admin');

    export const users = pgTable('users', {
    id: integer(),
    }, (t) => [
    pgPolicy(policy-insert, {
    for: 'insert',
    to: authenticatedRole,
    withCheck: sqlfalse,
    }),
    ]);

    Using with Supabase

    We also have a /supabase import with a set of predefined roles marked as existing, which you can use in your schema.
    This import will be extended in a future release with more functions and helpers to make using RLS and Supabase simpler.

    // drizzle-orm/supabase
    export const anonRole = pgRole('anon').existing();
    export const authenticatedRole = pgRole('authenticated').existing();
    export const serviceRole = pgRole('service_role').existing();
    export const postgresRole = pgRole('postgres_role').existing();
    export const supabaseAuthAdminRole = pgRole('supabase_auth_admin').existing();

    For example, you can use the Supabase predefined roles like this:

    import { sql } from 'drizzle-orm';
    import { serviceRole } from 'drizzle-orm/supabase';
    import { integer, pgPolicy, pgRole, pgTable } from 'drizzle-orm/pg-core';

    export const admin = pgRole('admin');

    export const users = pgTable('users', {
    id: integer(),
    }, (t) => [
    pgPolicy(policy-insert, {
    for: 'insert',
    to: serviceRole,
    withCheck: sqlfalse,
    }),
    ]);

    The /supabase import also includes predefined tables and functions that you can use in your application

    // drizzle-orm/supabase

    const auth = pgSchema('auth');
    export const authUsers = auth.table('users', {
    id: uuid().primaryKey().notNull(),
    });

    const realtime = pgSchema('realtime');
    export const realtimeMessages = realtime.table(
    'messages',
    {
    id: bigserial({ mode: 'bigint' }).primaryKey(),
    topic: text().notNull(),
    extension: text({
    enum: ['presence', 'broadcast', 'postgres_changes'],
    }).notNull(),
    },
    );

    export const authUid = sql(select auth.uid());
    export const realtimeTopic = sqlrealtime.topic();

    This allows you to use it in your code, and Drizzle Kit will treat them as existing databases,
    using them only as information to connect to other entities

    import { foreignKey, pgPolicy, pgTable, text, uuid } from "drizzle-orm/pg-core";
    import { sql } from "drizzle-orm/sql";
    import { authenticatedRole, authUsers } from "drizzle-orm/supabase";

    export const profiles = pgTable(
    "profiles",
    {
    id: uuid().primaryKey().notNull(),
    email: text().notNull(),
    },
    (table) => [
    foreignKey({
    columns: [table.id],
    // reference to the auth table from Supabase
    foreignColumns: [authUsers.id],
    name: "profiles_id_fk",
    }).onDelete("cascade"),
    pgPolicy("authenticated can view all profiles", {
    for: "select",
    // using predefined role from Supabase
    to: authenticatedRole,
    using: sqltrue,
    }),
    ]
    );

    Let's check an example of adding a policy to a table that exists in Supabase

    import { sql } from "drizzle-orm";
    import { pgPolicy } from "drizzle-orm/pg-core";
    import { authenticatedRole, realtimeMessages } from "drizzle-orm/supabase";

    export const policy = pgPolicy("authenticated role insert policy", {
    for: "insert",
    to: authenticatedRole,
    using: sql``,
    }).link(realtimeMessages);

    Bug fixes

  • 0.36.0-cfa88dd - 2024-11-03
  • 0.36.0-998119e - 2024-11-04
  • 0.36.0-96d338b - 2024-11-06
  • 0.36.0-5ea5a84 - 2024-10-30
  • 0.36.0-4d56096 - 2024-11-04
  • 0.36.0-19f042a - 2024-11-04
  • 0.35.3 - 2024-10-21
  • 0.35.3-d39c24e - 2024-10-28
  • 0.35.3-b2b714a - 2024-10-27
  • 0.35.3-a43c673 - 2024-10-21
  • 0.35.3-a1e0ae9 - 2024-10-29
  • 0.35.3-9f627ed - 2024-10-28
  • 0.35.3-9a8395a - 2024-10-29
  • 0.35.3-6c5580e - 2024-10-21
  • 0.35.3-6a162f5 - 2024-10-24
  • 0.35.3-57d2372 - 2024-10-22
  • 0.35.3-53e089b - 2024-10-28
  • 0.35.3-4cb1bdb - 2024-10-23
  • 0.35.3-1b1151d - 2024-10-21
  • 0.35.3-05e88e4 - 2024-10-24
  • 0.35.2 - 2024-10-18
  • 0.35.2-728dcb3 - 2024-10-21
  • 0.35.1 - 2024-10-16
  • 0.35.1-74d2f4c - 2024-10-16
  • 0.35.0 - 2024-10-15
  • 0.34.1 - 2024-10-07
  • 0.34.1-f9ec555 - 2024-10-11
  • 0.34.1-e7d524d - 2024-10-14
  • 0.34.1-cb4af54 - 2024-10-11
  • 0.34.1-bbca092 - 2024-10-15
  • 0.34.1-a9aca5c - 2024-10-10
  • 0.34.1-a88d6b6 - 2024-10-15
  • 0.34.1-a5ec472 - 2024-10-11
  • 0.34.1-a345cb3 - 2024-10-10
  • 0.34.1-9a563af - 2024-10-15
  • 0.34.1-8c3e1b5 - 2024-10-14
  • 0.34.1-6764bd8 - 2024-10-14
  • 0.34.1-20acc2f - 2024-10-11
  • 0.34.1-1f15bfd - 2024-10-08
  • 0.34.1-1f0b52f - 2024-10-14
  • 0.34.0 - 2024-10-07
  • 0.34.0-ff1e9a5 - 2024-09-16
  • 0.34.0-f5f3e49 - 2024-09-24
  • 0.34.0-f5d46d3 - 2024-10-03
  • 0.34.0-f026b0e - 2024-09-15
  • 0.34.0-d1da3b8 - 2024-09-20
  • 0.34.0-cf39bf5 - 2024-10-08
  • 0.34.0-bab5208 - 2024-10-03
  • 0.34.0-b75016b - 2024-10-01
  • 0.34.0-b1faa33 - 2024-10-07
  • 0.34.0-a5a41e0 - 2024-09-23
  • 0.34.0-8dece56 - 2024-09-16
  • 0.34.0-746aeed - 2024-10-07
  • 0.34.0-680d055 - 2024-09-12
  • 0.34.0-605ef48 - 2024-09-13
  • 0.34.0-5a1c5d3 - 2024-09-13
  • 0.34.0-06c725b - 2024-10-02
  • 0.34.0-05b9e35 - 2024-09-23
  • 0.34.0-178591 - 2024-09-12
  • 0.33.0 - 2024-08-08
  • 0.33.0-ff1dcd9 - 2024-09-03
  • 0.33.0-f7ddd08 - 2024-08-22
  • 0.33.0-f71baf7 - 2024-08-15
  • 0.33.0-efd821d - 2024-09-05
  • 0.33.0-daeed1e - 2024-09-04
  • 0.33.0-d496e6f - 2024-09-06
  • 0.33.0-d11d7bb - 2024-09-11
  • 0.33.0-cd1f68c - 2024-09-07
  • 0.33.0-cd0b1a2 - 2024-09-11
  • 0.33.0-c6528ed - 2024-09-09
  • 0.33.0-c5d1196 - 2024-09-03
  • 0.33.0-bddd952 - 2024-08-16
  • 0.33.0-b921e79 - 2024-08-29
  • 0.33.0-ad58316 - 2024-09-04
  • 0.33.0-ab3b46d - 2024-09-02
  • 0.33.0-8db0aa4 - 2024-08-27
  • 0.33.0-8cf7a61 - 2024-09-05
  • 0.33.0-8948f19 - 2024-08-28
  • 0.33.0-8944ef1 - 2024-09-06
  • 0.33.0-87d7704 - 2024-08-26
  • 0.33.0-86140ad - 2024-09-09
  • 0.33.0-807aa5b - 2024-09-02
  • 0.33.0-7bea25c - 2024-09-06
  • 0.33.0-766f76f - 2024-08-27
  • 0.33.0-7469abe - 2024-09-06
  • 0.33.0-6fbcf46 - 2024-09-14
  • 0.33.0-6386ea9 - 2024-08-14
  • 0.33.0-626cc95 - 2024-08-23
  • 0.33.0-6205f01 - 2024-08-08
  • 0.33.0-5be80aa - 2024-09-02
  • 0.33.0-5b9600e - 2024-09-02
  • 0.33.0-540bab9 - 2024-09-05
  • 0.33.0-50ebd0a - 2024-08-30
  • 0.33.0-4c4912d - 2024-08-23
  • 0.33.0-417b0fa - 2024-08-27
  • 0.33.0-4045fbc - 2024-08-23
  • 0.33.0-3e27645 - 2024-09-03
  • 0.33.0-3c3ccca - 2024-09-04
  • 0.33.0-38d6dab - 2024-08-12
  • 0.33.0-30e7661 - 2024-08-26
  • 0.33.0-277e6de - 2024-09-06
  • 0.33.0-25af8ee - 2024-08-27
  • 0.33.0-1a5913a - 2024-08-26
  • 0.33.0-1321cf9 - 2024-09-04
  • 0.33.0-12ef143 - 2024-08-27
  • ...

Snyk has created this PR to upgrade drizzle-orm from 0.32.2 to 0.36.0.

See this package in npm:
drizzle-orm

See this project in Snyk:
https://app.snyk.io/org/sivajikondeti37/project/5013ea6d-0985-4045-89eb-fccdfe49bd2e?utm_source=github&utm_medium=referral&page=upgrade-pr
Copy link

vercel bot commented Nov 27, 2024

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

Name Status Preview Comments Updated (UTC)
invoice-generate ❌ Failed (Inspect) Nov 27, 2024 7:08am

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.

2 participants