pgpm-env
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePGPM Env
PGPM Env
Manage PostgreSQL environment variables with profile support using the command.
pgpm env使用命令管理PostgreSQL环境变量,支持多profile。
pgpm envWhen 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=localhostPGPORT=5432PGUSER=postgresPGPASSWORD=passwordPGDATABASE=postgres
bash
eval "$(pgpm env)"这会设置以下环境变量:
PGHOST=localhostPGPORT=5432PGUSER=postgresPGPASSWORD=passwordPGDATABASE=postgres
Run Command with Environment
携带环境运行命令
bash
pgpm env pgpm deploy --database mydbThis runs with the PostgreSQL environment variables automatically set.
pgpm deploy --database mydbbash
pgpm env pgpm deploy --database mydb这会自动设置好PostgreSQL环境变量后运行命令。
pgpm deploy --database mydbProfiles
Profiles
Default Profile (Local Postgres)
默认Profile(本地Postgres)
bash
eval "$(pgpm env)"| Variable | Value |
|---|---|
| |
| |
| |
| |
| |
bash
eval "$(pgpm env)"| 变量 | 值 |
|---|---|
| |
| |
| |
| |
| |
Supabase Profile
Supabase Profile
bash
eval "$(pgpm env --supabase)"| Variable | Value |
|---|---|
| |
| |
| |
| |
| |
bash
eval "$(pgpm env --supabase)"| 变量 | 值 |
|---|---|
| |
| |
| |
| |
| |
Command Reference
命令参考
Print Environment Exports
打印环境导出语句
bash
pgpm env # Default Postgres profile
pgpm env --supabase # Supabase profileOutput (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 mydbbash
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 mydbCommon Workflows
常用工作流
Development Setup
开发环境搭建
bash
undefinedbash
undefinedStart 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
undefinedcreatedb myapp
pgpm deploy --database myapp
undefinedRunning Tests
运行测试
bash
undefinedbash
undefinedRun tests with database environment
携带数据库环境运行测试
pgpm env pnpm test
pgpm env pnpm test
Or load into shell first
或者先将环境变量加载到shell
eval "$(pgpm env)"
pnpm test
undefinedeval "$(pgpm env)"
pnpm test
undefinedPGPM Deployment
PGPM部署
bash
undefinedbash
undefinedDeploy to a specific database
部署到指定数据库
pgpm env pgpm deploy --database constructive
pgpm env pgpm deploy --database constructive
Verify deployment
验证部署结果
pgpm env pgpm verify --database constructive
undefinedpgpm env pgpm verify --database constructive
undefinedSupabase Local Development
Supabase本地开发
bash
undefinedbash
undefinedStart 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
undefinedpgpm deploy --database postgres
undefinedShell 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 envalias pgenv='eval "$(pgpm env)"'
alias pgenv-supa='eval "$(pgpm env --supabase)"'
使用方式:
```bash
pgenv # 加载默认Postgres环境
pgenv-supa # 加载Supabase环境One-liner Commands
单行命令
bash
undefinedbash
undefinedCreate database and deploy in one command
一条命令完成创建数据库和部署
pgpm env bash -c "createdb mydb && pgpm deploy --database mydb"
undefinedpgpm env bash -c "createdb mydb && pgpm deploy --database mydb"
undefinedEnvironment Variables Reference
环境变量参考
The command sets standard PostgreSQL environment variables that are recognized by:
pgpm env- and other PostgreSQL CLI tools
psql - Node.js library
pg - PGPM CLI commands
- Any tool using libpq
| Variable | Description |
|---|---|
| Database server hostname |
| Database server port |
| Database username |
| Database password |
| Default database name |
pgpm env- 及其他PostgreSQL CLI工具
psql - Node.js 库
pg - PGPM CLI命令
- 任何使用libpq的工具
| 变量 | 说明 |
|---|---|
| 数据库服务器主机名 |
| 数据库服务器端口 |
| 数据库用户名 |
| 数据库密码 |
| 默认数据库名称 |
Troubleshooting
故障排查
| Issue | Solution |
|---|---|
| "Connection refused" | Ensure database container is running with |
| Wrong database | Check |
| Auth failed | Verify password matches container settings |
| Supabase not connecting | Ensure Supabase is running on port 54322 |
| Env vars not persisting | Use |
| 问题 | 解决方案 |
|---|---|
| "Connection refused" | 执行 |
| 数据库错误 | 检查 |
| 认证失败 | 验证密码是否与容器配置匹配 |
| Supabase连接失败 | 确保Supabase运行在54322端口 |
| 环境变量不生效 | 使用 |
References
参考
For related skills:
- Docker container management: See skill
pgpm-docker - Running tests: See skill
pgpm-testing
相关技能:
- Docker容器管理:查看技能
pgpm-docker - 运行测试:查看技能
pgpm-testing