Skip to content

FORK - Capture a snapshot (or subset) of your Postgres database whilst transforming the data.

License

Notifications You must be signed in to change notification settings

adaptyvbio/snaplet

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Snaplet - Production-like data for development

Snaplet Logo

License npm version Discord Documentation

What is Snaplet?

Snaplet is an all-in-one developer tool that gives developers realistic, production-like data to code against. It solves the common problem developers face when working with databases - having safe, realistic data without exposing sensitive production information.

Key Features

  • πŸ“Έ Database Snapshots: Capture and transform data from your production database
  • πŸ” Data Privacy: Automatically detect and transform PII with built-in anonymization
  • 🎯 Data Subsetting: Capture only the data you need while maintaining referential integrity
  • πŸš€ Fast Restoration: Quickly restore snapshots to your development database
  • πŸ› οΈ TypeScript Configuration: Type-safe configuration with full IDE support
  • 🏠 Self-Hostable: Run on your own infrastructure for complete control
  • πŸ”„ Database Agnostic: Works with PostgreSQL (more databases coming soon)

Quick Start

Prerequisites

  • Node.js v18.18.2 or higher
  • PostgreSQL database (for capturing/restoring snapshots)
  • npm, yarn, or pnpm package manager

Installation

# Using npm
npm install -g @snaplet/snapshot

# Using yarn
yarn global add @snaplet/snapshot

# Using pnpm
pnpm add -g @snaplet/snapshot

Basic Usage

  1. Setup Snaplet in your project
snaplet setup

This will create a snaplet.config.ts file in your project root.

  1. Capture a snapshot from your database
# Capture from your production database
snaplet snapshot capture --db-url postgresql://user:pass@host:5432/mydb

# Or use environment variables
DATABASE_URL=postgresql://... snaplet snapshot capture
  1. List available snapshots
snaplet snapshot list
  1. Restore a snapshot to your development database
# Restore the latest snapshot
snaplet snapshot restore --latest

# Restore a specific snapshot
snaplet snapshot restore <snapshot-id>

Configuration

Snaplet uses a TypeScript configuration file (snaplet.config.ts) for advanced features:

import { defineConfig } from '@snaplet/sdk'
import { copycat } from '@snaplet/copycat'

export default defineConfig({
  // Select which schemas to include
  select: {
    public: {
      // Include all tables except 'logs'
      $default: true,
      logs: false,
    }
  },

  // Transform sensitive data
  transform: {
    public: {
      users: ({ row }) => ({
        email: copycat.email(row.email),
        name: copycat.fullName(row.name),
        phone: copycat.phoneNumber(row.phone),
      }),
    }
  },

  // Data subsetting
  subset: {
    enabled: true,
    version: '3',
    targets: [
      {
        table: 'public.users',
        percent: 10, // Capture only 10% of users
      }
    ]
  }
})

Common Use Cases

1. Development Environment Setup

Create safe development databases with production-like data:

# Capture a subset of production data
snaplet snapshot capture --db-url $PROD_DB_URL

# Restore to local development
snaplet snapshot restore --db-url postgresql://localhost:5432/dev_db

2. CI/CD Testing

Use snapshots in your CI pipeline:

# .github/workflows/test.yml
steps:
  - uses: actions/checkout@v3
  - name: Restore test database
    run: snaplet snapshot restore --latest
  - name: Run tests
    run: npm test

3. Data Privacy Compliance

Transform PII automatically during capture:

// snaplet.config.ts
export default defineConfig({
  transform: {
    $mode: 'auto', // Automatically detect and transform PII
  }
})

CLI Commands

Core Commands

  • snaplet setup - Initialize Snaplet in your project
  • snaplet snapshot capture - Create a database snapshot
  • snaplet snapshot list - List available snapshots
  • snaplet snapshot restore - Restore a snapshot
  • snaplet config generate - Generate configuration files

Useful Flags

  • --db-url - Database connection string
  • --latest - Use the latest snapshot
  • --yes - Skip confirmation prompts
  • --verbose - Enable verbose logging

Run snaplet --help for a complete list of commands and options.

Documentation

Visit our documentation for:

Contributing

We welcome contributions! Please see our Contributing Guide for details on:

  • Setting up your development environment
  • Running tests
  • Submitting pull requests
  • Code style guidelines

Community & Support

License

Snaplet is licensed under the Functional Source License (FSL-1.1-MIT). See the LICENSE file for details.

After 2 years, the license automatically converts to MIT.

Acknowledgments

Snaplet is built on top of many amazing open-source projects including:

  • PostgreSQL - The world's most advanced open source database
  • TypeScript - JavaScript with syntax for types
  • Turborepo - High-performance build system for JavaScript and TypeScript
  • And many more wonderful projects!

Made with ❀️ by the Snaplet team

About

FORK - Capture a snapshot (or subset) of your Postgres database whilst transforming the data.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 75.8%
  • PLpgSQL 23.5%
  • JavaScript 0.7%