跳到正文
Skillpedia
数据库18k · #10629

datatables

它能做什么

这个技能说明如何修改 Windmill 数据表的结构,在启用时使用有序的迁移,并讲解其角色和权限的运作方式。适合管理 Windmill 中共享数据库的人。

适用场景

  • ✓当你需要在 Windmill 数据表中添加、修改或删除列或其他结构时。
  • ✓当启用了迁移,你需要编写向上迁移及与之匹配的向下迁移时。
  • ✓当你需要为数据表设置角色或权限时。

技能链接

https://github.com/windmill-labs/windmill/blob/main/system_prompts/auto-generated/skills/datatables/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/windmill-labs/windmill/blob/main/system_prompts/auto-generated/skills/datatables/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请在 Windmill 的客户数据表中添加一个新列,并确保这次修改被记录为一次迁移。”

每周 5 个新技能,1 分钟读完。

工作原理

该技能告诉你的智能体,在启用迁移时把结构更改记录为带版本的迁移,这样更改会随工作区一起迁移,并且可以撤销。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Data tables: schema changes, migrations and permissions

A data table is a PostgreSQL database managed by Windmill and shared by the whole workspace: scripts, flows and apps reach it by name, main being the default. It is configured in the workspace settings (Data Tables), never created by SQL.

Changing the schema

A data table with migrations enabled keeps its schema as an ordered list of versioned SQL migrations, each an up and an optional down. That list is what git sync and a workspace merge carry, and what rebuilds the schema in another workspace. So first find out whether migrations are enabled on the data table:

  • Enabled: make every schema change (CREATE, ALTER, DROP, anything but row data) as a new migration. A change made with plain SQL exists in that one database only, and the history no longer describes it.
  • Not enabled: schema changes are plain SQL. Enabling migrations is a workspace admin's decision, made in the Data Tables settings, not a step to take on the way to something else.

Writing a migration:

  • Wrap the statements in BEGIN; ... END; so it applies atomically. Leave the frame out only for a statement that cannot run in a transaction, such as CREATE INDEX CONCURRENTLY: such a migration can fail half applied.
  • Give it a down that undoes the up whenever the change is reversible. Without one it cannot be rolled back.
  • Declare the schemas it changes on a leading line of its up, -- schemas sales, billing, and qualify every name with its schema (sales.orders). A migration waits only on earlier migrations whose schemas overlap its own. One that declares none applies to the whole database and every later migration waits for it, so leave the line out only for a change that really spans the database, such as an extension.
  • Migrations apply oldest first. One that is applied is not edited: correct it with a new migration.
  • Row data is not schema. Insert, update and delete rows with plain SQL, migrations or not.

wmill datatable migrate new <name> scaffolds migrations/datatable/<datatable>/<timestamp>_<name>.up.sql and .down.sql, wmill datatable migrate up pushes the local files and applies what is pending, wmill datatable migrate down rolls back the most recent one and wmill datatable migrate status lists them. All take -d <datatable> and default to main. migrate new --schemas sales,billing writes the -- schemas line, and migrate up --schema sales applies only the pending migrations declaring that schema.

A migration is not a draft

A migration is saved to the workspace and changes the database as soon as it is applied, for everything that reads those tables. To try a schema out without touching tables already in use:

  • put the new tables in a schema of their own, created by the same migration (CREATE SCHEMA IF NOT EXISTS), and point what you are building at it. A raw app names its schema in its data config, which is why a new app gets a new schema by default;
  • or work in a workspace fork whose data table was cloned when the fork was created ("Clone schema only" or "Clone schema and data"): migrations applied there change that copy alone, and reach the parent workspace when the fork is merged. A fork that kept the original data table points at the parent's database, so a migration applied in it changes the parent's tables at once.

Altering or dropping a table other scripts or apps use is neither of those: say what depends on it before doing it.

Roles and permissions

Data table roles are a self-hosted Enterprise Edition feature, for data tables on managed Postgres (the instance database or the external managed instance). Without them, and always on a data table backed by a Postgres resource, everyone who can use the data table reaches all of it: there is no per-user, per-schema or per-row access to promise.

A data table under roles is reached as a Postgres role, and Postgres enforces what that role was granted:

  • roles are assigned, per data table, to users, groups or folders. admin is the connection the data table had before roles: it owns the existing objects and ignores grants;
  • a connection either names a role (wmill.datatable('main', { role: 'analyst' }), role='analyst' in Python, datatable://main?role=analyst) and holds that role alone, or names none and is resolved from the data table's default role;
  • permission denied means the role in use lacks a grant. Say which role and which object: the grant is a data ta
常见问题

为什么不直接运行普通的 SQL?

在启用迁移的情况下,普通的 SQL 修改只存在于一个数据库中,迁移历史将无法与之匹配。

什么是向下迁移?

它是撤销向上迁移的步骤,因此更改可以被逆转。

谁决定是否启用迁移?

工作区管理员在数据表设置中决定。

详情

作者的原始描述

MUST use when changing a data table's schema, writing or running its migrations, or working with its roles and permissions.

repo: windmill-labs/windmill

热度

GitHub 星标
18k
排名
#10629
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能