sealos-database

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Sealos Database

Sealos Database

Identity and Discovery

身份与识别

  • Owner:
    sealos-database
    (
    /sealos-database
    and database create, connect, backup, logs, or access requests).
  • Class:
    cloud-local-mutation
    through
    sealos-cli
    , with an optional redacted handoff to deployment.
  • Canaries:
    DB-REUSE-ENV
    ,
    DB-CONFIRM-PUBLIC
    , and
    DB-REDACT-CONNECT
    .
  • 归属方:
    sealos-database
    (负责
    /sealos-database
    及数据库创建、连接、备份、日志或访问请求相关操作)。
  • 类别: 通过
    sealos-cli
    执行的
    cloud-local-mutation
    操作,可选择性将脱敏后的信息交接至部署流程。
  • 标记项:
    DB-REUSE-ENV
    DB-CONFIRM-PUBLIC
    DB-REDACT-CONNECT

Scope and Boundaries

范围与边界

Accept a project path and database intent. Analyze first, list existing databases, create or reuse the selected type, and wire only the existing application env key. Preserve prior env values and local Compose rollback; private access is the default. Database deletion, public access, backup deletion, restore collisions, and disabling active access remain gated operations.
接收项目路径和数据库需求。先进行分析,列出已有数据库,创建或复用选定类型的数据库,并仅接入现有应用的环境变量键。保留原有环境变量值和本地Compose回滚能力;默认采用私有访问。数据库删除、公网访问、备份删除、恢复冲突以及禁用活跃访问仍为受限操作。

Risk and Confirmation

风险与确认

Never print passwords, full connection strings, kubeconfig, auth files, or copied env values. Ask before public access or destructive operations and state the private alternative. Parse JSON CLI output and keep the selected workspace, namespace, database, and env mutation scoped to the request.
绝不能打印密码、完整连接字符串、kubeconfig、认证文件或复制的环境变量值。开启公网访问或执行破坏性操作前需征得用户同意,并说明私有访问的替代方案。解析CLI的JSON输出,确保所选工作区、命名空间、数据库及环境变量变更仅限定在当前请求范围内。

Lifecycle Workflow

生命周期工作流

For each request, resolve the project, analyze its database need, confirm CLI/auth/region/workspace, list before create/reuse, fetch connection details, wire the existing env key, and verify connectivity or migrations. Emit request-scoped
success
,
stopped
, or
error
; the existing analyzer-first workflow remains the domain extension below. Workspace ambiguity, an unavailable credential response, or a tracked env target stops the request before mutation.
针对每个请求,先解析项目,分析其数据库需求,确认CLI/认证/区域/工作区信息,在创建/复用前列出已有数据库,获取连接详情,接入现有环境变量键,并验证连接或迁移情况。输出请求范围内的
success
stopped
error
状态;现有“先分析”工作流作为下方的领域扩展。若工作区存在歧义、凭证不可用或环境变量目标已被追踪,将在变更前终止请求。

Request Contract

请求契约

yaml
input:
  project: local path or repository source
  intent: database type, purpose, and create-or-reuse preference
  access: private by default; public only after confirmation
preconditions:
  - analyzer evidence names the database signal and env key
  - sealos-cli/auth/region/workspace are resolved
  - the selected env file is ignored and the key is known
The ordered action is
analyze -> resolve account/workspace -> list -> create or reuse -> wait -> fetch -> wire -> verify
. The selected workspace, namespace, database identity, and env mutation remain request-scoped.
yaml
input:
  project: local path or repository source
  intent: database type, purpose, and create-or-reuse preference
  access: private by default; public only after confirmation
preconditions:
  - analyzer evidence names the database signal and env key
  - sealos-cli/auth/region/workspace are resolved
  - the selected env file is ignored and the key is known
执行顺序为
分析 -> 解析账户/工作区 -> 列出数据库 -> 创建或复用 -> 等待就绪 -> 获取信息 -> 接入环境变量 -> 验证
。所选工作区、命名空间、数据库标识及环境变量变更均限定在当前请求范围内。

Progressive Disclosure

渐进式披露

Load the analyzer, CLI, env-wiring, and connectivity procedures one level deep when their phase is reached. Keep credential-handling and public/destructive confirmation visible here even when detailed commands live in owned scripts or references.
当进入对应阶段时,逐层加载分析器、CLI、环境变量接入及连接验证流程。即使详细命令存于自有脚本或参考文档中,凭证处理及公网/破坏性操作确认环节仍需清晰展示。

Output, Stop, and Error States

输出、终止与错误状态

  • success
    : database identity/status, region/workspace, env file and key names, redacted connectivity or migration evidence, confirmation state, and any follow-up access state.
  • stopped
    : ambiguous workspace, unavailable credential readiness, tracked env target, public/destructive confirmation boundary, or missing precondition with the safe next action; no gated mutation is claimed.
  • error
    : analyzer, CLI, connection, or env-write step, sanitized diagnostic category, affected artifact, and recovery action with passwords, URLs, auth values, and complete connection strings redacted.
  • success
    :数据库标识/状态、区域/工作区、环境文件及键名、脱敏后的连接或迁移证据、确认状态,以及后续访问状态。
  • stopped
    :工作区歧义、凭证未就绪、环境变量目标已被追踪、公网/破坏性操作确认边界、或缺少前置条件并提供安全后续操作;未执行受限变更。
  • error
    :分析器、CLI、连接或环境变量写入步骤出错,提供脱敏后的诊断类别、受影响的工件,以及恢复操作(密码、URL、认证值及完整连接字符串均已脱敏)。

Handoffs

交接流程

An optional deployment handoff uses the complete tuple below. The receiver re-checks deployment scope and runtime evidence.
yaml
target: sealos-deploy
inputArtifact: redacted database identity, private-access status, approved env-key contract, and connectivity/migration evidence
allowedAction: consume approved Secret/env references within the selected deployment scope
failureReturn: sanitized analyzer, CLI, env, or connectivity diagnostic with the failed phase
responseOwner: sealos-database
Direct database requests use
target: none
and keep the same evidence fields.
可选的部署交接使用以下完整元组。接收方需重新检查部署范围及运行时证据。
yaml
target: sealos-deploy
inputArtifact: redacted database identity, private-access status, approved env-key contract, and connectivity/migration evidence
allowedAction: consume approved Secret/env references within the selected deployment scope
failureReturn: sanitized analyzer, CLI, env, or connectivity diagnostic with the failed phase
responseOwner: sealos-database
直接数据库请求使用
target: none
,并保留相同的证据字段。

Verification

验证

Use
analyze-project-database.mjs
,
sealos-cli
JSON output, app migration/connectivity evidence, and baseline cases
database-positive-reuse-redacted-connectivity
and
database-violating-unconfirmed-public-or-destructive
. Verify env preservation and redaction before accepting success.
Use this skill to give a project a real Sealos Cloud database during development. The default outcome is: identify the app's database need, create or reuse a Sealos database with
sealos-cli
, fetch connection details, wire only the needed local env vars, and verify the app can connect.
使用
analyze-project-database.mjs
sealos-cli
的JSON输出、应用迁移/连接证据,以及基准用例
database-positive-reuse-redacted-connectivity
database-violating-unconfirmed-public-or-destructive
。在确认成功前,需验证环境变量保留情况及脱敏处理。
使用此技能可为开发中的项目提供真实的Sealos Cloud数据库。默认流程为:识别应用的数据库需求,通过
sealos-cli
创建或复用Sealos数据库,获取连接详情,仅接入所需的本地环境变量,并验证应用能否连接。

Safety Rules

安全规则

  1. Never print database passwords or full connection strings in the final answer.
  2. Do not overwrite an existing env value without confirming or preserving the old value.
  3. Do not commit
    .env
    ,
    .env.local
    , connection strings, passwords, kubeconfig, or Sealos auth files.
  4. Ask before enabling public database access. Prefer private connections when the app runs inside Sealos/Devbox.
  5. Ask before destructive operations:
    database delete
    ,
    backup-delete
    , restoring over a name that may collide, or disabling access that an active app depends on.
  6. Use JSON output from
    sealos-cli
    by default and parse it instead of scraping table output.
  1. 最终回复中绝不能打印数据库密码或完整连接字符串。
  2. 未经确认或未保留原有值的情况下,不得覆盖现有环境变量值。
  3. 不得提交
    .env
    .env.local
    、连接字符串、密码、kubeconfig或Sealos认证文件。
  4. 开启数据库公网访问前需征得用户同意。当应用在Sealos/Devbox内运行时,优先采用私有连接。
  5. 执行破坏性操作前需征得用户同意:
    database delete
    backup-delete
    、覆盖可能存在冲突的名称进行恢复,或禁用活跃应用依赖的访问权限。
  6. 默认使用
    sealos-cli
    的JSON输出,并进行解析,而非抓取表格输出。

Workflow

工作流

1. Resolve the target project

1. 解析目标项目

Confirm the working directory with
pwd
or
git rev-parse --show-toplevel
.
Run the analyzer when a project directory is available:
bash
node <SKILL_DIR>/scripts/analyze-project-database.mjs <project-dir>
Use the analyzer result as a starting point, then inspect the real files it cites before editing anything. It intentionally avoids printing secret values.
通过
pwd
git rev-parse --show-toplevel
确认工作目录。
当项目目录可用时运行分析器:
bash
node <SKILL_DIR>/scripts/analyze-project-database.mjs <project-dir>
以分析器结果为起点,在编辑任何内容前先检查它引用的真实文件。分析器会刻意避免打印敏感值。

2. Check
sealos-cli

2. 检查
sealos-cli

Prefer an existing
sealos-cli
binary:
bash
sealos-cli --version
sealos-cli database --help
sealos-cli whoami
If it is not installed, use
npx -y sealos-cli@latest ...
for one-off commands. Ask before installing it globally.
If auth is missing or expired, run:
bash
sealos-cli login <region>
sealos-cli workspace list
sealos-cli workspace current
Use the workspace the user expects. If multiple workspaces exist and the target is ambiguous, ask before provisioning.
优先使用已有的
sealos-cli
二进制文件:
bash
sealos-cli --version
sealos-cli database --help
sealos-cli whoami
若未安装,可使用
npx -y sealos-cli@latest ...
执行一次性命令。全局安装前需征得用户同意。
若缺失认证或认证过期,运行:
bash
sealos-cli login <region>
sealos-cli workspace list
sealos-cli workspace current
使用用户期望的工作区。若存在多个工作区且目标不明确,需在配置前征得用户同意。

3. Choose create or reuse

3. 选择创建或复用

List existing databases first:
bash
sealos-cli database list -o json
Reuse an existing database when the name, type, and purpose match. Create a new one when the project has no suitable database or the user asks for a fresh dev database.
Use conservative development defaults unless the project clearly needs more:
bash
sealos-cli database create postgresql --name <app-dev-db> --cpu 1 --memory 1 --storage 3 --replicas 1 -o json
Before creating, check supported versions if version choice matters:
bash
sealos-cli database versions --type postgresql -o json
Supported CLI database types include
postgresql
,
mongodb
,
mysql
,
apecloud-mysql
,
redis
,
kafka
,
qdrant
,
nebula
,
weaviate
,
milvus
,
pulsar
, and
clickhouse
. Use the type detected from the project; default to
postgresql
only when the project has no database-specific signals.
先列出已有数据库:
bash
sealos-cli database list -o json
当名称、类型及用途匹配时,复用已有数据库。当项目无合适数据库或用户请求全新开发数据库时,创建新数据库。
除非项目明确需要更高配置,否则采用保守的开发默认值:
bash
sealos-cli database create postgresql --name <app-dev-db> --cpu 1 --memory 1 --storage 3 --replicas 1 -o json
创建前,若版本选择重要,需检查支持的版本:
bash
sealos-cli database versions --type postgresql -o json
CLI支持的数据库类型包括
postgresql
mongodb
mysql
apecloud-mysql
redis
kafka
qdrant
nebula
weaviate
milvus
pulsar
clickhouse
。使用从项目中检测到的类型;仅当项目无数据库特定信号时,默认使用
postgresql

4. Wait for readiness and fetch connection data

4. 等待就绪并获取连接数据

Poll details until the database is running or connection data is present:
bash
sealos-cli database get <name> -o json
sealos-cli database connection <name> -o json
Read
references/sealos-cli-database.md
for the current command contract and response handling.
轮询详情,直到数据库运行或连接数据可用:
bash
sealos-cli database get <name> -o json
sealos-cli database connection <name> -o json
查阅
references/sealos-cli-database.md
获取当前命令契约及响应处理方式。

5. Wire the development environment

5. 接入开发环境

Map the connection into the env var the project already uses:
Project signalPreferred env key
Prisma, Drizzle, TypeORM, generic Postgres
DATABASE_URL
MySQL app with existing MySQL-specific config
DATABASE_URL
or existing
MYSQL_URL
MongoDB app
MONGODB_URI
Redis cache/queue
REDIS_URL
Use the existing local env convention:
  1. Prefer
    .env.local
    for Next.js and frontend-adjacent projects.
  2. Prefer
    .env
    only when the repo already uses it for local development and it is gitignored.
  3. Treat
    .env.example
    as documentation only; never write real secrets there.
  4. Preserve comments and unrelated keys.
If a connection string is not directly returned in the desired form, compose it from
host
,
port
,
username
, and
password
fields from
sealos-cli database connection
.
将连接信息映射到项目已在使用的环境变量:
项目信号首选环境变量键
Prisma, Drizzle, TypeORM, 通用Postgres
DATABASE_URL
带有现有MySQL特定配置的MySQL应用
DATABASE_URL
或现有
MYSQL_URL
MongoDB应用
MONGODB_URI
Redis缓存/队列
REDIS_URL
遵循现有本地环境约定:
  1. Next.js及前端相关项目优先使用
    .env.local
  2. 仅当仓库已将
    .env
    用于本地开发且已加入git忽略时,才优先使用
    .env
  3. .env.example
    仅视为文档;绝不在其中写入真实敏感信息。
  4. 保留注释及无关键值。
若未直接返回所需格式的连接字符串,可从
sealos-cli database connection
返回的
host
port
username
password
字段组合生成。

6. Verify application connectivity

6. 验证应用连接

Run the project's normal verification path, not just the CLI command:
  1. Run migrations or introspection if the project has a clear command (
    prisma migrate
    ,
    drizzle-kit migrate
    ,
    db:migrate
    ,
    db:push
    ).
  2. Start the app or run the smallest test that opens a DB connection.
  3. If the app runs outside Sealos and cannot reach the private endpoint, ask before enabling public access:
bash
sealos-cli database enable-public <name> -o json
sealos-cli database connection <name> -o json
Disable public access after testing if it is no longer needed:
bash
sealos-cli database disable-public <name> -o json
运行项目常规验证流程,而非仅执行CLI命令:
  1. 若项目有明确命令(如
    prisma migrate
    drizzle-kit migrate
    db:migrate
    db:push
    ),执行迁移或 introspection。
  2. 启动应用或运行最小规模的测试以打开数据库连接。
  3. 若应用在Sealos外运行且无法访问私有端点,需征得用户同意后开启公网访问:
bash
sealos-cli database enable-public <name> -o json
sealos-cli database connection <name> -o json
若不再需要公网访问,测试后关闭:
bash
sealos-cli database disable-public <name> -o json

7. Report the result

7. 报告结果

Summarize:
  1. Database name, type, region/workspace, and status.
  2. Env file and key updated, without revealing the secret value.
  3. Verification command and outcome.
  4. Any public access state and follow-up action.
总结内容:
  1. 数据库名称、类型、区域/工作区及状态。
  2. 更新的环境文件及键名,不泄露敏感值。
  3. 验证命令及结果。
  4. 公网访问状态及后续操作建议。

Common Tasks

常见任务

Connect an existing project to a Sealos database

将现有项目连接到Sealos数据库

  1. Run the analyzer.
  2. Inspect the env/config files it cites.
  3. List existing Sealos databases.
  4. Create or reuse the matching database.
  5. Fetch connection details.
  6. Write the expected env key.
  7. Run the app's DB verification.
  1. 运行分析器。
  2. 检查它引用的环境/配置文件。
  3. 列出已有Sealos数据库。
  4. 创建或复用匹配的数据库。
  5. 获取连接详情。
  6. 写入预期的环境变量键。
  7. 运行应用的数据库验证流程。

Replace a local Compose database for development

用Sealos数据库替代本地Compose数据库进行开发

  1. Identify the app service env vars that point at
    postgres
    ,
    mysql
    ,
    mongo
    , or
    redis
    compose services.
  2. Provision the equivalent Sealos database.
  3. Update only the app's local env file, not the compose file, unless the user asks to remove the local service.
  4. Keep local Compose rollback simple: the original compose service remains available.
  1. 识别指向
    postgres
    mysql
    mongo
    redis
    Compose服务的应用服务环境变量。
  2. 配置对应的Sealos数据库。
  3. 仅更新应用的本地环境文件,而非Compose文件,除非用户要求移除本地服务。
  4. 简化本地Compose回滚:保留原有Compose服务可用。

Add a database to a Devbox workflow

为Devbox工作流添加数据库

  1. Use private database connection details when the Devbox runs in the same Sealos workspace.
  2. Write env vars into the Devbox/app environment expected by the repo.
  3. Restart or reload the Devbox process only after env vars are in place.
  1. 当Devbox在同一Sealos工作区运行时,使用私有数据库连接详情。
  2. 将环境变量写入仓库预期的Devbox/应用环境中。
  3. 仅在环境变量配置完成后重启或重载Devbox进程。

References

参考资料

  • scripts/analyze-project-database.mjs
    - read-only project database intent analyzer.
  • references/sealos-cli-database.md
    -
    sealos-cli database
    command contract.
  • references/env-integration.md
    - safe env-file editing and connection-string mapping.
  • scripts/analyze-project-database.mjs
    - 只读型项目数据库需求分析器。
  • references/sealos-cli-database.md
    -
    sealos-cli database
    命令契约。
  • references/env-integration.md
    - 安全的环境文件编辑及连接字符串映射指南。