当前位置: 首页 > Skill >

Insforge Cli

Insforge Cli

Insforge Cli

当用户需要后端基础设施管理时使用此技能——创建数据库表、执行SQL、部署无服务器函数、管理存储

0.1.0 2026.11.26 333
获取Skill文件查看使用说明
作 者:顾川 许可证: 更新时间:2026.11.26
本文目录展开

InsForge CLI

Command-line tool for managing InsForge Backend-as-a-Service projects.

Critical: Session Start Checks

First, ensure the CLI is installed. Run insforge whoami — if the command is not found, install it:

npm install -g @insforge/cli

Then verify authentication and project:

insforge whoami    # verify authentication
insforge current   # verify linked project

If not authenticated: insforge login If no project linked: insforge create (new) or insforge link (existing)

Global Options

Flag Description
--json Structured JSON output (for scripts and agents)
-y, --yes Skip confirmation prompts

Exit Codes

Code Meaning
0 Success
1 General error (e.g., HTTP 400+ from function invoke)
2 Not authenticated
3 Project not linked
4 Resource not found
5 Permission denied

Environment Variables

Variable Description
INSFORGE_ACCESS_TOKEN Override stored access token
INSFORGE_PROJECT_ID Override linked project ID
INSFORGE_EMAIL Email for non-interactive login
INSFORGE_PASSWORD Password for non-interactive login

Commands

Authentication

  • insforge login — OAuth (browser) or --email for password login. See references/login.md
  • insforge logout — clear stored credentials
  • insforge whoami — show current user

Project Management

  • insforge create — create new project. See references/create.md
  • insforge link — link directory to existing project
  • insforge current — show current user + linked project
  • insforge list — list all orgs and projects
  • insforge metadata — show backend metadata (auth config, database tables, storage buckets, edge functions, AI models, realtime channels). Use --json for structured output. Run this first to discover what's configured before building features.

Database — insforge db

  • insforge db query <sql> — execute raw SQL. See references/db-query.md
  • insforge db tables / indexes / policies / triggers / functions — inspect schema
  • insforge db rpc <fn> [--data <json>] — call database function (GET if no data, POST if data)
  • insforge db export — export schema/data. See references/db-export.md
  • insforge db import <file> — import from SQL file. See references/db-import.md

Edge Functions — insforge functions

  • insforge functions list — list deployed functions
  • insforge functions code <slug> — view function source
  • insforge functions deploy <slug> — deploy or update. See references/functions-deploy.md
  • insforge functions invoke <slug> [--data <json>] [--method GET|POST] — invoke function

Storage — insforge storage

  • insforge storage buckets — list buckets
  • insforge storage create-bucket <name> [--private] — create bucket (default: public)
  • insforge storage delete-bucket <name> — delete bucket and all its objects (destructive)
  • insforge storage list-objects <bucket> [--prefix] [--search] [--limit] [--sort] — list objects
  • insforge storage upload <file> --bucket <name> [--key <objectKey>] — upload file
  • insforge storage download <objectKey> --bucket <name> [--output <path>] — download file

Deployments — insforge deployments

  • insforge deployments deploy [dir] — deploy frontend app. See references/deployments-deploy.md
  • insforge deployments list — list deployments
  • insforge deployments status <id> [--sync] — get deployment status (--sync fetches from Vercel)
  • insforge deployments cancel <id> — cancel running deployment

Secrets — insforge secrets

  • insforge secrets list [--all] — list secrets (values hidden; --all includes deleted)
  • insforge secrets get <key> — get decrypted value
  • insforge secrets add <key> <value> [--reserved] [--expires <ISO date>] — create secret
  • insforge secrets update <key> [--value] [--active] [--reserved] [--expires] — update secret
  • insforge secrets delete <key> — soft delete (marks inactive; restore with --active true)

Schedules — insforge schedules

  • insforge schedules list — list all scheduled tasks (shows ID, name, cron, URL, method, active, next run)
  • insforge schedules get <id> — get schedule details
  • insforge schedules create --name --cron --url --method [--headers <json>] [--body <json>] — create a cron job (5-field cron format only)
  • insforge schedules update <id> [--name] [--cron] [--url] [--method] [--headers] [--body] [--active] — update schedule
  • insforge schedules delete <id> — delete schedule (with confirmation)
  • insforge schedules logs <id> [--limit] [--offset] — view execution logs

Logs — insforge logs

  • insforge logs <source> [--limit <n>] — fetch backend container logs (default: 20 entries)
Source Description
insforge.logs Main backend logs
postgREST.logs PostgREST API layer logs
postgres.logs PostgreSQL database logs
function.logs Edge function execution logs

Source names are case-insensitive: postgrest.logs works the same as postgREST.logs.

Documentation — insforge docs

  • insforge docs — list all topics
  • insforge docs instructions — setup guide
  • insforge docs <feature> <language> — feature docs (db / storage / functions / auth / ai / realtime × typescript / swift / kotlin / rest-api)

For writing application code with the InsForge SDK, use the insforge (SDK) skill instead, and use the insforge docs <feature> <language> to get specific SDK documentation.

Non-Obvious Behaviors

Functions invoke URL: invoked at {oss_host}/functions/{slug} — NOT /api/functions/{slug}. Exits with code 1 on HTTP 400+.

Secrets delete is soft: marks the secret inactive, not destroyed. Restore with insforge secrets update KEY --active true. Use --all with secrets list to see inactive ones.

Storage delete-bucket is hard: deletes the bucket and every object inside it permanently.

db rpc uses GET or POST: no --data → GET; with --data → POST.

Schedules use 5-field cron only: minute hour day month day-of-week. 6-field (with seconds) is NOT supported. Headers can reference secrets with ${{secrets.KEY_NAME}}.

Common Workflows

Set up database schema

insforge db query "CREATE TABLE posts (
  id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
  title TEXT NOT NULL,
  content TEXT,
  author_id UUID REFERENCES auth.users(id),
  created_at TIMESTAMPTZ DEFAULT now()
)"
insforge db query "ALTER TABLE posts ENABLE ROW LEVEL SECURITY"
insforge db query "CREATE POLICY "public_read" ON posts FOR SELECT USING (true)"
insforge db query "CREATE POLICY "owner_write" ON posts FOR INSERT WITH CHECK (auth.uid() = author_id)"

FK to users: always auth.users(id). RLS current user: auth.uid().

Deploy an edge function

# Default source path: insforge/functions/{slug}/index.ts
insforge functions deploy my-handler
insforge functions invoke my-handler --data '{"action": "test"}'

Deploy frontend

Always verify the local build succeeds before deploying. Local builds are faster to debug and don't waste server resources.

# 1. Build locally first
npm run build

# 2. Deploy
insforge deployments deploy ./dist --env '{"VITE_API_URL": "https://my-app.us-east.insforge.app"}'

Environment variable prefix by framework:

Framework Prefix Example
Vite VITE_ VITE_INSFORGE_URL
Next.js NEXT_PUBLIC_ NEXT_PUBLIC_INSFORGE_URL
Create React App REACT_APP_ REACT_APP_INSFORGE_URL
Astro PUBLIC_ PUBLIC_INSFORGE_URL
SvelteKit PUBLIC_ PUBLIC_INSFORGE_URL

Pre-deploy checklist:

  • npm run build succeeds locally
  • All required env vars configured with correct framework prefix
  • Edge function directories excluded from frontend build (if applicable)
  • Never include node_modules, .git, .env, .insforge, or build output in the zip
  • Build output directory matches framework's expected output (dist/, build/, .next/, etc.)

Backup and restore database

insforge db export --output backup.sql
insforge db import backup.sql

Schedule a cron job

# Create a schedule that calls a function every 5 minutes
insforge schedules create 
  --name "Cleanup Expired" 
  --cron "*/5 * * * *" 
  --url "https://my-app.us-east.insforge.app/functions/cleanup" 
  --method POST 
  --headers '{"Authorization": "Bearer ${{secrets.API_TOKEN}}"}'

# Check execution history
insforge schedules logs <id>

Cron Expression Format

InsForge uses 5-field cron expressions (pg_cron format). 6-field expressions with seconds are NOT supported.

┌─────────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌─────────── day of month (1-31)
│ │ │ ┌───────── month (1-12)
│ │ │ │ ┌─────── day of week (0-6, Sunday=0)
│ │ │ │ │
* * * * *
Expression Description
* * * * * Every minute
*/5 * * * * Every 5 minutes
0 * * * * Every hour (at minute 0)
0 9 * * * Daily at 9:00 AM
0 9 * * 1 Every Monday at 9:00 AM
0 0 1 * * First day of every month at midnight
30 14 * * 1-5 Weekdays at 2:30 PM

Secret References in Headers

Headers can reference secrets stored in InsForge using the syntax ${{secrets.KEY_NAME}}.

{
  "headers": {
    "Authorization": "Bearer ${{secrets.API_TOKEN}}",
    "X-API-Key": "${{secrets.EXTERNAL_API_KEY}}"
  }
}

Secrets are resolved at schedule creation/update time. If a referenced secret doesn't exist, the operation fails with a 404 error.

Best Practices

  1. Use 5-field cron expressions only

    • pg_cron does not support seconds (6-field format)
    • Example: */5 * * * * for every 5 minutes
  2. Store sensitive values as secrets

    • Use ${{secrets.KEY_NAME}} in headers for API keys and tokens
    • Create secrets first via the secrets API before referencing them
  3. Target InsForge functions for serverless tasks

    • Use the function URL format: https://your-project.region.insforge.app/functions/{slug}
    • Ensure the target function exists and has status: "active"
  4. Monitor execution logs

    • Check logs regularly to ensure schedules are running successfully
    • Look for non-200 status codes and failed executions

Common Mistakes

Mistake Solution
Using 6-field cron (with seconds) Use 5-field format only: minute hour day month day-of-week
Referencing non-existent secret Create the secret first via secrets API
Targeting non-existent function Verify function exists and is active before scheduling
Schedule not running Check isActive is true and cron expression is valid

Recommended Workflow

1. Create secrets if needed     -> `insforge secrets add KEY VALUE`
2. Create/verify target function -> `insforge functions list`
3. Create schedule              -> `insforge schedules create`
4. Verify schedule is active    -> `insforge schedules get <id>`
5. Monitor execution logs       -> `insforge schedules logs <id>`

Debug with logs

insforge logs function.logs          # function execution issues
insforge logs postgres.logs          # database query problems
insforge logs insforge.logs          # API / auth errors
insforge logs postgrest.logs --limit 50

Best Practices

  1. Start with function.logs for function issues

    • Check execution errors, timeouts, and runtime exceptions
  2. Use postgres.logs for query problems

    • Debug slow queries, constraint violations, connection issues
  3. Check insforge.logs for API errors

    • Authentication failures, request validation, general backend errors

Common Debugging Scenarios

Problem Check
Function not working function.logs
Database query failing postgres.logs, postgREST.logs
Auth issues insforge.logs
API returning 500 errors insforge.logs, postgREST.logs

Non-interactive CI/CD

INSFORGE_EMAIL=$EMAIL INSFORGE_PASSWORD=$PASSWORD insforge login --email -y
insforge link --project-id $PROJECT_ID --org-id $ORG_ID -y
insforge db query "SELECT count(*) FROM users" --json

Project Configuration

After create or link, .insforge/project.json is created:

{
  "project_id": "...",
  "appkey": "...",
  "region": "us-east",
  "api_key": "ik_...",
  "oss_host": "https://{appkey}.{region}.insforge.app"
}

oss_host is the base URL for all SDK and API operations. api_key is the admin key for backend API calls.

Never commit this file to version control or share it publicly. Do not edit this file manually. Use insforge link to switch projects.

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,034
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,018
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,013
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,013
Skill 文件
  • SKILL.md
    • InsForge CLI
    • Critical: Session Start Checks
    • Global Options
    • Exit Codes
    • Environment Variables
    • Commands
      • Authentication
      • Project Management
      • Database — insforge db
      • Edge Functions — insforge functions
      • Storage — insforge storage
      • Deployments — insforge deployments
      • Secrets — insforge secrets
      • Schedules — insforge schedules
      • Logs — insforge logs
      • Documentation — insforge docs
    • Non-Obvious Behaviors
    • Common Workflows
      • Set up database schema
      • Deploy an edge function
      • Deploy frontend
      • Backup and restore database
      • Schedule a cron job
        • Cron Expression Format
        • Secret References in Headers
        • Best Practices
        • Common Mistakes
        • Recommended Workflow
      • Debug with logs
        • Best Practices
        • Common Debugging Scenarios
      • Non-interactive CI/CD
    • Project Configuration
  • 项目或源文件

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期