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

tablerizer

v1.5.0

Published

๐ŸŽฒ Tablerizer - The PostgreSQL table export wizard! Generate SQL files for RBAC, RLS, triggers, and schema documentation

Readme

๐ŸŽฒ Tablerizer - PostgreSQL Table Export Wizard

npm version TypeScript MIT License

Tablerizer is a powerful PostgreSQL table export wizard that generates SQL files to recreate table privileges (RBAC), Row Level Security (RLS) policies, triggers, constraints, and comprehensive table documentation.

Perfect for database migrations, environment synchronization, and integration with tools like Graphile Migrate.

โœจ Features

  • ๐Ÿ—๏ธ Complete Database Schema Export - Tables, privileges, policies, triggers, constraints
  • ๐Ÿ” RBAC & RLS Support - Full table and column-level permissions with RLS policies
  • ๐Ÿ—๏ธ Role Mapping - Replace database roles with placeholders (perfect for Graphile Migrate)
  • ๐Ÿ“ Rich Documentation - Includes table schema, foreign keys, constraints, and comments
  • โšก Multi-Schema Support - Export multiple schemas with organized folder structure
  • ๐Ÿ”ง Flexible Configuration - CLI args, config files, or environment variables
  • ๐Ÿงน Idempotent Scripts - Generated SQL includes cleanup sections for safe re-runs
  • ๐Ÿ“ฆ TypeScript Library - Use as a library in your Node.js applications
  • ๐ŸŽจ Beautiful CLI - Wizard-themed command-line interface with progress reporting
  • ๐Ÿ”ฎ Function Export - Export stored procedures and functions with GRANT EXECUTE
  • ๐Ÿ“Š Flexible Scope - Export tables, functions, or both with scope configuration

๐Ÿš€ Installation

As a CLI Tool

npm install -g tablerizer

As a Library

npm install tablerizer

๐ŸŽฏ Quick Start

CLI Usage

# Automatic config detection (.tablerizerrc)
tablerizer

# Specify schemas directly
tablerizer --schemas "app_public,app_private" --out ./exports

# Export only functions
tablerizer --schemas "app_public" --scope functions --out ./functions

# Export both tables and functions (default)
tablerizer --schemas "app_public" --scope all

Library Usage

import { Tablerizer, exportTables, exportFunctions } from "tablerizer";

// Export both tables and functions
const result = await exportTables({
  schemas: ["app_public", "app_private"],
  database_url: "postgres://user:pass@localhost:5432/db",
  out: "./exports",
  scope: "all", // or ['tables', 'functions']
  roles: ["admin", "user"],
  role_mappings: {
    myapp_admin: ":DATABASE_ADMIN",
    myapp_user: ":DATABASE_USER",
  },
});

console.log(
  `Exported ${result.totalFiles} files (${result.tableFiles} tables, ${result.functionFiles} functions)`
);

// Export only functions
const functionsResult = await exportFunctions({
  schemas: ["app_public"],
  database_url: process.env.DATABASE_URL,
  roles: ["admin", "user"],
});

Advanced Library Usage

import { Tablerizer } from "tablerizer";

const tablerizer = new Tablerizer({
  schemas: ["app_public"],
  database_url: process.env.DATABASE_URL,
  scope: "all", // Export both tables and functions
  role_mappings: {
    myapp_admin: ":DATABASE_ADMIN",
  },
});

// Export all with progress reporting
const result = await tablerizer.export((progress) => {
  console.log(
    `Processing ${progress.schema}.${progress.table} (${progress.progress}/${progress.total})`
  );
});

// Export a single table
const tableSql = await tablerizer.exportTable(
  "app_public",
  "users",
  "./users.sql"
);

// Export a single function
const functionSql = await tablerizer.exportFunction(
  "app_public",
  "get_user_by_id",
  "./get_user_by_id.sql"
);

// Export only functions
const functionsResult = await tablerizer.exportFunctions();

// Export only tables
const tablesResult = await tablerizer.exportTables();

// Clean up
await tablerizer.disconnect();

โš™๏ธ Configuration

Automatic Config Detection

Tablerizer automatically looks for configuration files in this order:

  • .tablerizerrc
  • .tablerizerrc.json

Config File Format

Basic Configuration

{
  "schemas": ["app_public", "app_private"],
  "out": "./exports",
  "roles": ["admin", "user", "visitor"],
  "database_url": "postgres://user:password@localhost:5432/database",
  "scope": "all",
  "role_mappings": {
    "myapp_admin": ":DATABASE_ADMIN",
    "myapp_user": ":DATABASE_USER",
    "myapp_visitor": ":DATABASE_VISITOR"
  }
}

With Environment Variables ๐ŸŽฏ

Tablerizer supports environment variable interpolation in config files using $ syntax:

{
  "schemas": ["app_public", "app_private"],
  "out": "${OUTPUT_DIR:./exports}",
  "roles": ["$ADMIN_ROLE", "$USER_ROLE", "${VISITOR_ROLE:visitor}"],
  "database_url": "$DATABASE_URL",
  "scope": "${EXPORT_SCOPE:all}",
  "role_mappings": {
    "myapp_admin": "${ADMIN_PLACEHOLDER::DATABASE_ADMIN}",
    "myapp_user": "${USER_PLACEHOLDER::DATABASE_USER}",
    "myapp_visitor": "${VISITOR_PLACEHOLDER::DATABASE_VISITOR}"
  }
}

Environment Variable Syntax:

  • $VAR - Simple variable expansion
  • ${VAR} - Braced variable expansion
  • ${VAR:default} - Variable with default value
  • ${VAR:} - Variable with empty default

Example .env file:

DATABASE_URL="postgres://user:pass@host:5432/db"
OUTPUT_DIR="./my-exports"
ADMIN_ROLE="admin"
USER_ROLE="user"
EXPORT_SCOPE="all"
ADMIN_PLACEHOLDER=":DATABASE_ADMIN"
USER_PLACEHOLDER=":DATABASE_USER"

Environment Variables

DATABASE_URL="postgres://user:pass@host:5432/db"
SCHEMAS="app_public,app_private"
OUTPUT_DIR="./exports"
ROLES="admin,user"

๐ŸŽฏ Role Mappings for Graphile Migrate

Tablerizer's role mapping feature is perfect for Graphile Migrate workflows:

{
  "role_mappings": {
    "myapp_admin": ":DATABASE_ADMIN",
    "myapp_user": ":DATABASE_USER"
  }
}

Generated SQL contains placeholders:

GRANT SELECT ON TABLE users TO :DATABASE_ADMIN;
REVOKE ALL ON TABLE users FROM :DATABASE_VISITOR;

Graphile Migrate replaces :DATABASE_ADMIN with actual roles during deployment.

๐Ÿ“ Output Structure

exports/
โ”œโ”€โ”€ app_public/
โ”‚   โ”œโ”€โ”€ tables/
โ”‚   โ”‚   โ”œโ”€โ”€ users.sql
โ”‚   โ”‚   โ”œโ”€โ”€ posts.sql
โ”‚   โ”‚   โ””โ”€โ”€ comments.sql
โ”‚   โ””โ”€โ”€ functions/
โ”‚       โ”œโ”€โ”€ get_user_by_id.sql
โ”‚       โ””โ”€โ”€ create_post.sql
โ””โ”€โ”€ app_private/
    โ”œโ”€โ”€ tables/
    โ”‚   โ”œโ”€โ”€ sessions.sql
    โ”‚   โ””โ”€โ”€ audit_log.sql
    โ””โ”€โ”€ functions/
        โ””โ”€โ”€ cleanup_sessions.sql

Each SQL file contains:

Table Files:

  • ๐Ÿงน Cleanup Section - Drops existing policies, triggers, revokes grants
  • ๐Ÿ—๏ธ Recreation Section - Creates RLS policies, grants, triggers
  • ๐Ÿ“‹ Schema Documentation - Table structure, foreign keys, constraints, comments

Function Files:

  • ๐Ÿ”ฎ CREATE OR REPLACE - Idempotent function definitions
  • ๐Ÿ” GRANT EXECUTE - Permission grants for specified roles
  • ๐Ÿ“ Comments - Function descriptions and metadata

๐Ÿ”ง CLI Options

tablerizer [options]

SPELLBOOK (OPTIONS):
  --config <file>     ๐Ÿ“œ Path to configuration grimoire (JSON)
  --schemas <list>    ๐ŸŽฏ Target schema realms, comma-separated
  --out <directory>   ๐Ÿ“ Output sanctum (default: ./tables/)
  --roles <list>      ๐Ÿ” Filter by magical roles, comma-separated
  --scope <type>      ๐ŸŽฏ Export scope: tables, functions, or all (default: all)
  --help, -h         โ“ Show this magical help
  --version, -v      โ„น๏ธ  Show version of the wizard

๐Ÿ“š Library API

Main Classes

Tablerizer

The main class for programmatic usage.

class Tablerizer {
  constructor(options?: Partial<TablerizerOptions>);
  configure(options: Partial<TablerizerOptions>): void;
  async connect(connectionString?: string): Promise<void>;
  async disconnect(): Promise<void>;
  async export(progressCallback?: ProgressCallback): Promise<ExportResult>;
  async exportTable(
    schema: string,
    tableName: string,
    outputPath?: string
  ): Promise<string>;
  async exportFunction(
    schema: string,
    functionName: string,
    outputPath?: string
  ): Promise<string>;
  async exportTables(
    progressCallback?: ProgressCallback
  ): Promise<ExportResult>;
  async exportFunctions(
    progressCallback?: ProgressCallback
  ): Promise<ExportResult>;
}

Types

interface TablerizerOptions {
  schemas: string[];
  out?: string;
  roles?: string[];
  database_url?: string;
  role_mappings?: Record<string, string>;
  scope?: "tables" | "functions" | "all" | Array<"tables" | "functions">;
}

interface ExportResult {
  schemas: string[];
  totalFiles: number;
  tableFiles: number;
  functionFiles: number;
  outputPath: string;
  files: Array<{
    schema: string;
    name: string;
    type: "table" | "function";
    filePath: string;
    size: number;
  }>;
}

type ProgressCallback = (progress: {
  schema: string;
  table: string;
  progress: number;
  total: number;
}) => void;

Convenience Functions

// Export all tables quickly
async function exportTables(
  options: TablerizerOptions,
  progressCallback?: ProgressCallback
): Promise<ExportResult>;

// Export all functions quickly
async function exportFunctions(
  options: TablerizerOptions,
  progressCallback?: ProgressCallback
): Promise<ExportResult>;

// Export a single table
async function exportTable(
  schema: string,
  tableName: string,
  options: TablerizerOptions,
  outputPath?: string
): Promise<string>;

// Export a single function
async function exportFunction(
  schema: string,
  functionName: string,
  options: TablerizerOptions,
  outputPath?: string
): Promise<string>;

๐Ÿ› ๏ธ Development

Build from Source

git clone https://github.com/your-username/tablerizer.git
cd tablerizer
npm install
npm run build

Project Structure

src/
โ”œโ”€โ”€ index.ts      # Main Tablerizer class and exports
โ”œโ”€โ”€ cli.ts        # CLI interface and help
โ”œโ”€โ”€ config.ts     # Configuration management
โ”œโ”€โ”€ database.ts   # Database connection utilities
โ””โ”€โ”€ generators.ts # SQL generation functions
bin/
โ””โ”€โ”€ tablerizer.js # CLI binary entry point
lib/              # Compiled JavaScript (generated)

Scripts

npm run build         # Compile TypeScript
npm run dev          # Watch mode compilation
npm run clean        # Remove compiled files
npm test             # Run tests (when available)

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built for the PostgreSQL community
  • Designed to work seamlessly with Graphile Migrate
  • Inspired by the need for better database permission management

Made with โค๏ธ for PostgreSQL database management

"Let the magic of organized database permissions flow through your migrations!" ๐Ÿง™โ€โ™‚๏ธโœจ