Spinning Up a Modular Database in 2 Minutes

Dan Lynch

Dan Lynch

Nov 14, 2025

lesson header image

See Prerequisites.

Experience the power of modular databases in under 2 minutes. You'll install a pre-built database module from npm and deploy it to Postgres—no SQL writing required. This is your first taste of modular database development.

What You'll Build

By the end of this lesson, you'll have a working Postgres database with UUID generation capabilities, deployed using pgpm's module system. This demonstrates how pgpm modules work like npm packages—install, deploy, done.

Step 1: Create a Workspace

Create a directory for your project:

pgpm init workspace

pgpm prompts for a workspace name:

? Enter the workspace name: quickstart-demo

This creates a complete workspace structure with everything you need.

Step 2: Create Your First Module

Change directory to your workspace:

cd quickstart-demo

Initialize a module inside your workspace:

pgpm init

Answer the prompts:

? Enter the module name: demo
? Which extensions? (Press space to select, enter to continue)

Just press Enter to skip extensions for now. pgpm scaffolds a complete module structure:

packages/demo/
├── demo.control
├── pgpm.plan
├── deploy/
├── revert/
└── verify/

Step 3: Install a Database Module

Navigate to your module and install a pre-built database module:

cd packages/demo
pgpm install @pgpm/faker

pgpm downloads the module from npm and installs it into your workspace's extensions/ directory.

Your module's package.json is automatically updated with the dependency.

Step 4: Deploy to Postgres

Deploy to a new database (pgpm will create it for you):

pgpm deploy --database quickstart_dev --createdb --yes

Note: Make sure Docker Desktop is running before deploying.

pgpm deploys the UUID module to your database. You'll see output like:

[cli] INFO: Selected package: demo
[deploy] SUCCESS: 🚀 Starting deployment to database quickstart_dev...
[deploy] INFO: 📥 Installing external extension: citext
[deploy] INFO: 📥 Installing external extension: pgcrypto
[deploy] INFO: 📥 Installing external extension: plpgsql
[deploy] INFO: 📥 Installing external extension: uuid-ossp
[deploy] INFO: 📂 Deploying local module: launchql-verify
[deploy] INFO: 📂 Deploying local module: launchql-types
[deploy] INFO: 📂 Deploying local module: launchql-faker
[deploy] INFO: 📂 Deploying local module: demo
[migrate] INFO: Checking pgpm migration schema...
[migrate] SUCCESS: Migration schema found and ready
[deploy] SUCCESS: ✅ Deployment complete for demo.
[cli] SUCCESS: Deployment complete.
[pg-cache] SUCCESS: pg.Pool quickstart_dev ended.

Step 5: Verify It Works

Test the deployed faker schema and its tables and functions:

Query the faker.cities table to see sample city data:

psql -d quickstart_dev -c "SELECT * from faker.cities LIMIT 1"

You should see a row:

                  id                  |   city   | state |           zips            |   lat   |   lng
--------------------------------------+----------+-------+---------------------------+---------+----------
 e36c5cc7-eb79-42be-8a11-5bcd535c8147 | New York | NY    | {11226,11225,11224,11222} | 40.6943 | -73.9249
(1 row)

Test the faker.business() function to generate a random business name:

 psql -d quickstart_dev -c "SELECT faker.business()"
  business
------------
 Brand Fund
(1 row)

What Just Happened?

In under 2 minutes, you:

  1. Created a workspace - A modular project structure for database packages
  2. Initialized a module - Your database package
  3. Installed a dependency - A pre-built database module from npm
  4. Deployed to Postgres - With automatic dependency resolution
  5. Verified functionality - UUID generation working instantly

This workflow demonstrates the core philosophy of modular databases: database development should be as modular and productive as frontend development. You didn't write SQL, configure migrations, or manually track dependencies. pgpm handled the infrastructure.

Understanding the Module System

The @pgpm/faker module you installed is a real npm package containing:

  • SQL migration scripts
  • Dependency declarations
  • Version information

When you ran pgpm install, pgpm:

  1. Downloaded the package from npm
  2. Extracted the database module
  3. Placed it in extensions/@pgpm/faker
  4. Updated your module's dependencies

When you ran pgpm deploy, pgpm:

  1. Resolved the dependency graph
  2. Deployed dependencies first
  3. Deployed your module
  4. Tracked everything in the database

Exploring What Was Deployed

Check the migration tracking:

pgpm migrate status --database quickstart_dev

You'll see all deployed modules and changes.

Rolling Back (Optional)

If you want to revert everything:

pgpm revert --database quickstart_dev

pgpm runs the revert scripts in reverse order, cleanly removing all changes.

What's Next

You've experienced the install-and-deploy workflow for modular databases, but the real power comes when you start authoring your own database changes. In the next course, you'll learn how to:

  • Create custom database schemas
  • Add migrations with deploy/revert/verify scripts
  • Manage dependencies between changes
  • Build reusable database modules

Key Takeaways

  • Database modules are npm packages - Install database code like frontend dependencies
  • Automatic dependency resolution - pgpm deploys in the correct order
  • Migration tracking built-in - Every deployment is tracked and reversible
  • Zero configuration - No build tools, no manual migration management
  • Fast feedback loops - From install to deployed database in seconds

The workflow you just experienced—from zero to deployed database in 2 minutes—demonstrates the power of modular databases. This same pattern scales from simple utilities to complex multi-module applications.

Ready to start building your own modules? Check out the "Modular Postgres Development with Database Packages" course to learn how to author database changes.