Spinning Up a Modular Database in 2 Minutes
Dan Lynch
Nov 14, 2025
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:
bashpgpm init workspace
pgpm prompts for a workspace name:
sh? Enter the workspace name: quickstart-demo
Or, if you're not running interactively (for example, as an agent):
bashpgpm init workspace --no-tty \ --name quickstart-demo --repoName quickstart-demo \ --fullName "Ada Lovelace" --email ada@example.com \ --username ada --license MIT
This creates a complete workspace structure with everything you need.
Step 2: Create Your First Module
Change directory to your workspace:
bashcd quickstart-demo
Initialize a module inside your workspace:
bashpgpm init
Answer the prompt:
sh? Enter the module name: demo
Or, if you're not running interactively (for example, as an agent):
bashpgpm init --no-tty --moduleName demo --moduleDesc "Demo module"
The module inherits author, repo, and license from the workspace.
That's it—pgpm init scaffolds a module with no extensions by default (add them later with pgpm extension, or up front with pgpm init --extensions a,b). pgpm scaffolds a complete module structure:
mdpackages/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:
bashcd 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):
bashpgpm deploy --database quickstart_dev --createdb
Or, if you're not running interactively (for example, as an agent):
bashpgpm deploy --database quickstart_dev --createdb --yes --package demo
Note: Make sure Docker Desktop is running before deploying.
pgpm deploys the UUID module to your database. You'll see output like:
sh[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:
bashpsql -d quickstart_dev -c "SELECT * from faker.cities LIMIT 1"
You should see a row:
textid | 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:
bashpsql -d quickstart_dev -c "SELECT faker.business()"
textbusiness ------------ Brand Fund (1 row)
What Just Happened?
In under 2 minutes, you:
- Created a workspace - A modular project structure for database packages
- Initialized a module - Your database package
- Installed a dependency - A pre-built database module from npm
- Deployed to Postgres - With automatic dependency resolution
- 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:
- Downloaded the package from npm
- Extracted the database module
- Placed it in
extensions/@pgpm/faker - Updated your module's dependencies
When you ran pgpm deploy, pgpm:
- Resolved the dependency graph
- Deployed dependencies first
- Deployed your module
- Tracked everything in the database
Exploring What Was Deployed
Check the migration tracking:
bashpgpm migrate status --database quickstart_dev
You'll see all deployed modules and changes.
Rolling Back (Optional)
If you want to revert everything:
bashpgpm revert --database quickstart_dev
Or, if you're not running interactively (for example, as an agent):
bashpgpm revert --database quickstart_dev --package demo --yes
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.

