npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shoito/prismarls

v0.0.5

Published

Prismarls is a CLI tool designed to facilitate the integration of PostgreSQL Row-Level Security (RLS) with Prisma Migrations. After creating a migration using `prisma migrate dev --create-only`, running `prismarls` will automatically generate SQL to appen

Downloads

321

Readme

Prismarls

Prismarls is a CLI tool designed to facilitate the integration of PostgreSQL Row-Level Security (RLS) with Prisma Migrations. After creating a migration using prisma migrate dev --create-only, running prismarls will automatically generate SQL to append RLS configurations to the latest migration file.

Here's an example of the SQL generated by Prisma Migrate:

-- CreateTable
CREATE TABLE "Company" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Company_pkey" PRIMARY KEY ("id")
);

Prismarls will add the following RLS settings:

-- RLS Settings
ALTER TABLE "Company" ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation_policy ON "Company" USING("id" = current_setting('app.company_id'));
CREATE POLICY bypass_rls_policy ON "Company" USING (current_setting('app.bypass_rls', TRUE)::text = 'on');

Usage

Create a migration with Prisma Migrate and then append RLS configurations using Prismarls:

# Create a migration with Prisma Migrate --create-only
npx prisma migrate dev --create-only --name migration
# Use Prismarls to add RLS settings and create policies for the specified tables
npx @shoito/prismarls --schema=./prisma/schema.prisma --migrations=./prisma/migrations --currentSettingIsolation=app.company_id --currentSettingBypass=app.bypass_rls

schema.prisma

Add a /// @RLS comment in your schema.prisma to specify tables and columns for which RLS should be configured.

model Company {
  id        String   @id @default(cuid()) /// @RLS
  name      String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

If table or column names are specified using map, include these in the @RLS annotation:

model User {
  id        String   @id @default(cuid())
  email     String   @unique
  company   Company? @relation(fields: [companyId], references: [id])
  companyId String?  @map("company_id") /// @RLS(table: "users", column: "company_id")
  @@map("users")
}

Command Options

  • --schema: Path to your Prisma schema.prisma file. Default is ./prisma/schema.prisma.
  • --migrations: Directory path containing migration files generated by Prisma Migrate. Default is ./prisma/migrations.
  • --currentSettingIsolation: Specify the current setting for RLS isolation. Default is app.tenant_id.
  • --currentUser: Specify if using current_user with RLS. Default is false.
  • --currentSettingBypass: Specify the current setting for RLS bypass. Default is app.bypass_rls.
  • --forceEnable: Enable FORCE ROW LEVEL SECURITY for all tables. Default is false.

Prisma Limitations

  • Settings from prisma db pull do not include RLS configurations.
  • Deploying schemas with prisma db push does not apply RLS settings.

License

MIT