Skip to main content

Plan Command Limitations

The postkit db plan command uses pgschema to generate schema diffs. Understanding what pgschema supports (and doesn't) will help you use the plan command effectively.

How the Plan Command Works

┌─────────────────────────────────────────────────────────────────────────────┐
│ DB PLAN COMMAND WORKFLOW │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ $ postkit db plan │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ 1. Read schema │ │ 2. Combine all │ │
│ │ files │───────────►│ files into │ │
│ │ │ │ schema.sql │ │
│ └──────────────────┘ └────────┬─────────┘ │
│ │ │
│ ┌────────▼─────────┐ │
│ │ 3. Run pgschema │ │
│ │ plan (diff) │ │
│ └────────┬─────────┘ │
│ │ │
│ ┌────────▼─────────┐ │
│ │ 4. Compare with │ │
│ │ current DB │ │
│ └────────┬─────────┘ │
│ │ │
│ ┌────────▼─────────┐ │
│ │ 5. Generate │ │
│ │ migration │ │
│ │ plan │ │
│ └──────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

What pgschema DOES Support

Schema-level objects within a schema are fully supported:

Object TypeSupported
TablesCREATE TABLE, ALTER TABLE
ViewsCREATE VIEW, CREATE MATERIALIZED VIEW
FunctionsCREATE FUNCTION
TriggersCREATE TRIGGER
IndexesCREATE INDEX, CREATE UNIQUE INDEX
ConstraintsPRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK
EnumsCREATE TYPE ... AS ENUM
DomainsCREATE DOMAIN
SequencesCREATE SEQUENCE

What pgschema DOES NOT Support

pgschema does not support cluster and database level commands:

Cluster Level (Not Supported)

CommandAlternative
CREATE DATABASEUse db/schema/infra/ or manual migration
CREATE ROLEUse db/schema/infra/ or manual migration
CREATE TABLESPACEUse manual migration
CREATE USERUse db/schema/infra/ or manual migration

Database Level (Not Supported)

CommandAlternative
CREATE EXTENSIONUse db/schema/infra/ or manual migration
CREATE SCHEMAUse db/schema/infra/ or manual migration
CREATE CASTUse manual migration
CREATE COLLATIONUse manual migration
CREATE CONVERSIONUse manual migration
CREATE EVENT TRIGGERUse manual migration
CREATE FOREIGN DATA WRAPPERUse manual migration
CREATE LANGUAGEUse manual migration
CREATE OPERATORUse manual migration
CREATE PUBLICATIONUse manual migration
CREATE SERVERUse manual migration
CREATE SUBSCRIPTIONUse manual migration
CREATE TEXT SEARCHUse manual migration
CREATE USER MAPPINGUse manual migration

Other

  • RENAME commands are not supported

How to Handle Unsupported Commands

Option 1: Infrastructure SQL (db/schema/infra/)

Place cluster and database level commands in db/schema/infra/. These are applied before the plan command runs:

db/schema/infra/
├── 001_roles.sql -- CREATE ROLE, CREATE USER
├── 002_schemas.sql -- CREATE SCHEMA
└── 003_extensions.sql -- CREATE EXTENSION

Option 2: Manual Migrations

For one-off SQL operations, use postkit db migration:

# Create a manual migration
postkit db migration <name>

# Edit the generated file in .postkit/db/session/
# Add your SQL (e.g., CREATE EXTENSION, CREATE ROLE, etc.)

# Apply it
postkit db apply

# Commit it
postkit db commit

Examples

Creating Extensions

postkit db migration add_uuid_extension
-- Enable UUID extension
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

Creating Schemas

postkit db migration create_custom_schemas
-- Create custom schemas
CREATE SCHEMA IF NOT EXISTS audit;
CREATE SCHEMA IF NOT EXISTS analytics;

Creating Roles

postkit db migration create_app_roles
-- Create application roles
CREATE ROLE app_read;
CREATE ROLE app_write;
CREATE ROLE app_admin;

-- Grant privileges
GRANT app_read TO app_write;
GRANT app_write TO app_admin;

Key Takeaway

The plan command uses pgschema, which only handles schema-level objects. For cluster/database level commands, use db/schema/infra/ or create manual migrations with postkit db migration.