pgpm-env

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PGPM Env

PGPM Env

Manage PostgreSQL environment variables with profile support using the
pgpm env
command.
使用
pgpm env
命令管理PostgreSQL环境变量,支持多profile。

When to Apply

适用场景

Use this skill when:
  • Setting up environment variables for database connections
  • Running commands that need PostgreSQL connection info
  • Switching between local Postgres and Supabase profiles
  • Deploying PGPM modules with correct database settings
  • Running tests or scripts that need database access
在以下场景使用该技能:
  • 为数据库连接配置环境变量
  • 运行需要PostgreSQL连接信息的命令
  • 在本地Postgres和Supabase profile之间切换
  • 使用正确的数据库配置部署PGPM模块
  • 运行需要数据库访问权限的测试或脚本

Quick Start

快速开始

Load Environment Variables

加载环境变量

bash
eval "$(pgpm env)"
This sets the following environment variables:
  • PGHOST=localhost
  • PGPORT=5432
  • PGUSER=postgres
  • PGPASSWORD=password
  • PGDATABASE=postgres
bash
eval "$(pgpm env)"
这会设置以下环境变量:
  • PGHOST=localhost
  • PGPORT=5432
  • PGUSER=postgres
  • PGPASSWORD=password
  • PGDATABASE=postgres

Run Command with Environment

携带环境运行命令

bash
pgpm env pgpm deploy --database mydb
This runs
pgpm deploy --database mydb
with the PostgreSQL environment variables automatically set.
bash
pgpm env pgpm deploy --database mydb
这会自动设置好PostgreSQL环境变量后运行
pgpm deploy --database mydb
命令。

Profiles

Profiles

Default Profile (Local Postgres)

默认Profile(本地Postgres)

bash
eval "$(pgpm env)"
VariableValue
PGHOST
localhost
PGPORT
5432
PGUSER
postgres
PGPASSWORD
password
PGDATABASE
postgres
bash
eval "$(pgpm env)"
变量
PGHOST
localhost
PGPORT
5432
PGUSER
postgres
PGPASSWORD
password
PGDATABASE
postgres

Supabase Profile

Supabase Profile

bash
eval "$(pgpm env --supabase)"
VariableValue
PGHOST
localhost
PGPORT
54322
PGUSER
supabase_admin
PGPASSWORD
postgres
PGDATABASE
postgres
bash
eval "$(pgpm env --supabase)"
变量
PGHOST
localhost
PGPORT
54322
PGUSER
supabase_admin
PGPASSWORD
postgres
PGDATABASE
postgres

Command Reference

命令参考

Print Environment Exports

打印环境导出语句

bash
pgpm env                    # Default Postgres profile
pgpm env --supabase         # Supabase profile
Output (for shell evaluation):
bash
export PGHOST="localhost"
export PGPORT="5432"
export PGUSER="postgres"
export PGPASSWORD="password"
export PGDATABASE="postgres"
bash
pgpm env                    # 默认Postgres profile
pgpm env --supabase         # Supabase profile
输出(供shell执行):
bash
export PGHOST="localhost"
export PGPORT="5432"
export PGUSER="postgres"
export PGPASSWORD="password"
export PGDATABASE="postgres"

Execute Command with Environment

携带环境执行命令

bash
pgpm env <command> [args...]
pgpm env --supabase <command> [args...]
Examples:
bash
pgpm env createdb mydb
pgpm env pgpm deploy --database mydb
pgpm env psql -c "SELECT 1"
pgpm env --supabase pgpm deploy --database mydb
bash
pgpm env <command> [args...]
pgpm env --supabase <command> [args...]
示例:
bash
pgpm env createdb mydb
pgpm env pgpm deploy --database mydb
pgpm env psql -c "SELECT 1"
pgpm env --supabase pgpm deploy --database mydb

Common Workflows

常用工作流

Development Setup

开发环境搭建

bash
undefined
bash
undefined

Start database container

启动数据库容器

pgpm docker start
pgpm docker start

Load environment into current shell

加载环境变量到当前shell

eval "$(pgpm env)"
eval "$(pgpm env)"

Now all commands have database access

现在所有命令都拥有数据库访问权限

createdb myapp pgpm deploy --database myapp
undefined
createdb myapp pgpm deploy --database myapp
undefined

Running Tests

运行测试

bash
undefined
bash
undefined

Run tests with database environment

携带数据库环境运行测试

pgpm env pnpm test
pgpm env pnpm test

Or load into shell first

或者先将环境变量加载到shell

eval "$(pgpm env)" pnpm test
undefined
eval "$(pgpm env)" pnpm test
undefined

PGPM Deployment

PGPM部署

bash
undefined
bash
undefined

Deploy to a specific database

部署到指定数据库

pgpm env pgpm deploy --database constructive
pgpm env pgpm deploy --database constructive

Verify deployment

验证部署结果

pgpm env pgpm verify --database constructive
undefined
pgpm env pgpm verify --database constructive
undefined

Supabase Local Development

Supabase本地开发

bash
undefined
bash
undefined

Start Supabase locally (using supabase CLI)

本地启动Supabase(使用supabase CLI)

supabase start
supabase start

Load Supabase environment

加载Supabase环境变量

eval "$(pgpm env --supabase)"
eval "$(pgpm env --supabase)"

Deploy modules to Supabase

部署模块到Supabase

pgpm deploy --database postgres
undefined
pgpm deploy --database postgres
undefined

Shell Integration

Shell集成

Bash/Zsh

Bash/Zsh

Add to your shell profile for automatic loading:
bash
undefined
将以下内容添加到你的shell配置文件实现自动加载:
bash
undefined

~/.bashrc or ~/.zshrc

~/.bashrc 或 ~/.zshrc

alias pgenv='eval "$(pgpm env)"' alias pgenv-supa='eval "$(pgpm env --supabase)"'

Then use:
```bash
pgenv          # Load default Postgres env
pgenv-supa     # Load Supabase env
alias pgenv='eval "$(pgpm env)"' alias pgenv-supa='eval "$(pgpm env --supabase)"'

使用方式:
```bash
pgenv          # 加载默认Postgres环境
pgenv-supa     # 加载Supabase环境

One-liner Commands

单行命令

bash
undefined
bash
undefined

Create database and deploy in one command

一条命令完成创建数据库和部署

pgpm env bash -c "createdb mydb && pgpm deploy --database mydb"
undefined
pgpm env bash -c "createdb mydb && pgpm deploy --database mydb"
undefined

Environment Variables Reference

环境变量参考

The
pgpm env
command sets standard PostgreSQL environment variables that are recognized by:
  • psql
    and other PostgreSQL CLI tools
  • Node.js
    pg
    library
  • PGPM CLI commands
  • Any tool using libpq
VariableDescription
PGHOST
Database server hostname
PGPORT
Database server port
PGUSER
Database username
PGPASSWORD
Database password
PGDATABASE
Default database name
pgpm env
命令设置的是标准PostgreSQL环境变量,可被以下工具识别:
  • psql
    及其他PostgreSQL CLI工具
  • Node.js
    pg
  • PGPM CLI命令
  • 任何使用libpq的工具
变量说明
PGHOST
数据库服务器主机名
PGPORT
数据库服务器端口
PGUSER
数据库用户名
PGPASSWORD
数据库密码
PGDATABASE
默认数据库名称

Troubleshooting

故障排查

IssueSolution
"Connection refused"Ensure database container is running with
pgpm docker start
Wrong databaseCheck
PGDATABASE
or specify
--database
flag
Auth failedVerify password matches container settings
Supabase not connectingEnsure Supabase is running on port 54322
Env vars not persistingUse
eval "$(pgpm env)"
to load into current shell
问题解决方案
"Connection refused"执行
pgpm docker start
确保数据库容器正在运行
数据库错误检查
PGDATABASE
变量值或者指定
--database
参数
认证失败验证密码是否与容器配置匹配
Supabase连接失败确保Supabase运行在54322端口
环境变量不生效使用
eval "$(pgpm env)"
加载到当前shell中

References

参考

For related skills:
  • Docker container management: See
    pgpm-docker
    skill
  • Running tests: See
    pgpm-testing
    skill
相关技能:
  • Docker容器管理:查看
    pgpm-docker
    技能
  • 运行测试:查看
    pgpm-testing
    技能