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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cipherstash/migrate

v1.0.0

Published

Plaintext-to-encrypted column migration for CipherStash: resumable backfill, per-column state, and EQL lifecycle orchestration.

Readme

@cipherstash/migrate

Primitives for safely and resumably migrating existing plaintext columns to concrete EQL v3 eql_v3_* domains in production PostgreSQL databases.

The package backs stash encrypt backfill and stash encrypt drop. You can also embed runBackfill() in a worker or cron job when a large migration should not run inside a CLI process.

Lifecycle

schema-added → dual-writing → backfilling → backfilled → dropped

EQL v3 has no configuration table and no rename cut-over. The application switches to the encrypted column by name after backfill, then drops the original plaintext column after verifying coverage. State is tracked in the append-only cipherstash.cs_migrations table installed by stash eql install.

State readers still accept the legacy cut_over event and its cut-over phase. Manifest readers retain the cut-over target phase and eqlVersion: 2. Those fields are kept only so status tools can display existing migration history; this package no longer exports the EQL v2 Proxy configuration or rename primitives.

API

import {
  appendEvent,
  installMigrationsSchema,
  latestByColumn,
  progress,
  readManifest,
  runBackfill,
  writeManifest,
} from '@cipherstash/migrate'

installMigrationsSchema(client)

Creates cipherstash.cs_migrations idempotently. Normally called by stash eql install.

runBackfill(options)

Runs a chunked, resumable, idempotent plaintext-to-encrypted backfill. For each chunk, it selects the next keyset page and encrypts it through bulkEncryptModels before BEGIN. The database transaction commits only the encrypted-column writes and the corresponding cs_migrations checkpoint. The encrypted IS NULL guard makes retries converge.

Pass an initialized EQL v3 Encryption client and an EQL v3 encryptedTable. The lower-level runner writes the envelope produced by the supplied client; the stash encrypt backfill command additionally verifies that the destination is an eql_v3_* domain before invoking it.

State and manifest helpers

appendEvent, progress, and latestByColumn access the migration event log. readManifest and writeManifest manage the Zod-validated .cipherstash/migrations.json intent file.

Domain and coverage helpers

detectColumnEqlVersion, classifyEqlDomain, listEncryptedColumns, and resolveEncryptedColumn recognize concrete EQL v3 domains and resolve the encrypted counterpart without relying on a naming convention. A legacy eql_v2_encrypted column returns null; callers must not treat that as an authorable generation.

countUnencrypted(client, table, plaintextColumn, encryptedColumn) counts rows with plaintext set and ciphertext NULL. stash encrypt drop uses it before generating the v3 plaintext-drop migration. countEncrypted counts populated target rows. Both are full-table scans intended for one-shot verification.

Worker example

import pg from 'pg'
import { runBackfill } from '@cipherstash/migrate'
import { encryptionClient, usersTable } from './src/encryption/index.js'

const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })

export async function handler({ signal }: { signal: AbortSignal }) {
  const db = await pool.connect()
  try {
    return await runBackfill({
      db,
      encryptionClient,
      tableSchema: usersTable,
      tableName: 'users',
      schemaColumnKey: 'email_encrypted',
      plaintextColumn: 'email',
      encryptedColumn: 'email_encrypted',
      pkColumn: 'id',
      chunkSize: 2000,
      signal,
    })
  } finally {
    db.release()
  }
}