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

v0.2.0

Published

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

Downloads

68

Readme

@cipherstash/migrate

Primitives for migrating existing plaintext columns to CipherStash's eql_v2_encrypted in production Postgres databases, safely and resumably.

Backs the stash encrypt CLI command group, but also exported for direct use — embed runBackfill() in your own worker or cron job when you'd rather not pipe gigabytes through a CLI process.

Lifecycle

Each column walks through these phases:

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

State is tracked in an append-only cipherstash.cs_migrations table installed by stash db install. The EQL intent (which indexes, which cast_as) continues to live in eql_v2_configuration so Proxy continues to work against the same database.

API

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

installMigrationsSchema(client)

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

runBackfill({ db, encryptionClient, tableSchema, tableName, plaintextColumn, encryptedColumn, pkColumn, schemaColumnKey, chunkSize?, signal?, onProgress? })

Chunked, resumable, idempotent backfill of plaintext → encrypted. Per chunk, in a single transaction: select next page → encrypt via client.bulkEncryptModelsUPDATE … FROM (VALUES …)INSERT a backfill_checkpoint event. Guards with encrypted IS NULL so re-runs never double-write.

  • db: a pg.PoolClient (the runner drives transactions on it).
  • encryptionClient: your initialised @cipherstash/stack EncryptionClient (or anything that exposes bulkEncryptModels(models, table) returning { data } | { failure }).
  • tableSchema: the EncryptedTable for the target table from your encryption client file.
  • signal: optional AbortSignal. If aborted between chunks, the backfill exits cleanly and leaves a resumable checkpoint.

Returns { resumed, rowsProcessed, rowsTotal, completed }.

appendEvent(client, { tableName, columnName, event, phase, … }) / progress(client, table, column) / latestByColumn(client)

Direct access to the cs_migrations event log. Use these if you're building your own migration UI or orchestration on top.

renameEncryptedColumns(client) / reloadConfig(client)

Thin wrappers around eql_v2.rename_encrypted_columns() (the cut-over primitive) and eql_v2.reload_config() (Proxy refresh hint — no-op when connected directly to Postgres).

readManifest(cwd) / writeManifest(manifest, cwd)

Read/write .cipherstash/migrations.json — the repo-side intent declaration. Zod-validated. The manifest is optional; commands work without it but you lose the plan diff.

Drop-in usage in a BullMQ/Inngest worker

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',
      plaintextColumn: 'email',
      encryptedColumn: 'email_encrypted',
      pkColumn: 'id',
      chunkSize: 2000,
      signal,
      onProgress: (p) => console.log(`${p.rowsProcessed}/${p.rowsTotal}`),
    })
  } finally {
    db.release()
  }
}