pythia-table
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTables, Columns, Comments
表、列与注释
Announce at start: "Using pythia-table — reading the table and its neighbours before designing DDL."
Phase: Learn → Ask → Do — the table as it is, the decisions that are the developer's, then one ordered script
A table outlives every program that reads it. Its columns are a contract
with every report, interface and procedure in the schema, and structural DDL
has almost no undo: is permanent, a renamed column breaks every
caller at once. Five minutes of design is the cheapest step there is.
DROP COLUMN开始时宣告:「正在使用 pythia-table——先读取目标表及其相关对象,再设计 DDL。」
阶段: 学习 → 询问 → 执行 —— 先了解表当前的状态,再明确应由开发者决定的事项,最后生成一个有序脚本
表的生命周期长于读取它的每一个程序。它的列是 schema 中每份报表、接口和存储过程共同遵守的契约,而结构性 DDL 几乎没有撤销手段: 是永久性的,重命名列则会同时破坏所有调用方。投入五分钟做设计,是成本最低的一步。
DROP COLUMNThe Iron Law
铁律
NO TABLE OR COLUMN WITHOUT ITS COMMENT, ITS CONSTRAINTS AND ITS IMPACT KNOWNNO TABLE OR COLUMN WITHOUT ITS COMMENT, ITS CONSTRAINTS AND ITS IMPACT KNOWNThe Workflow
工作流
- Learn the table and its neighbours.
- ·
pythia cols T·pythia comments T— what exists, what is documented, which foreign keys lack an index.pythia stats T - before any ALTER — every program that recompiles.
pythia impact T - and
pythia similar T_<NAME>— how this house already builds tables: PK style, audit columns, tablespace, naming. Readpythia ddl TABLE <NEIGHBOUR>and.pythia/conventions.md.pythia conventions
- Ask what is the developer's (through ): what is kept or deleted, nullability of existing rows and the backfill value, retention, who writes the table (an API package, a trigger, an interface), identity column vs sequence when the house has no rule. Never invent a business default for a NOT NULL column.
pythia-spec - Write one ordered script — has the template and the datatype rules:
reference/ddl-standards.md- name every constraint (,
PK_,FK_,UK_unless the house says otherwise); a primary key on every table; an index on every FK column;CK_ - text as — a Vietnamese character can take 3 bytes; money as
VARCHAR2(n CHAR), never FLOAT;NUMBER(p,s)orDATEby need;TIMESTAMP - and
COMMENT ON TABLEfor every new table and column: meaning, unit, allowed values, source. Vietnamese is fine here —COMMENT ON COLUMNtakes a literal only (noCOMMENT ... IS), and pythia sends UTF-8 exactly;unistrwarns if the character set cannot hold it.pythia doctor --db
- name every constraint (
- Lint it: (one run, so the comments file counts) — missing comments, unnamed constraints, unindexed FKs,
pythia lint script.sql comments.sqlwithout a default, byte-semantics text, missing house columns. Errors are fixed, not argued.ADD ... NOT NULL - Land it with (
pythia-deploy): every statement previewed, one approval, run in order, stopped at the first failure. A single statement can go throughpythia deploy script.sqlas usual.pythia applyisstructuralby default — relay the refusal; the developer decides (deny, or an autopilot lease namingpythia policy set structural confirm).structural - Verify ():
pythia-verify,pythia cols T(0 missing),pythia comments Tagainst the baseline.pythia invalid
- 了解目标表及其相关对象。
- ·
pythia cols T·pythia comments T—— 了解现有对象、已有文档,以及哪些外键缺少索引。pythia stats T - 任何 之前执行
ALTER——确认所有会重新编译的程序。pythia impact T - 和
pythia similar T_<NAME>—— 了解内部规范中现有的建表方式:PK 样式、审计列、表空间和命名规则。读取pythia ddl TABLE <NEIGHBOUR>并运行.pythia/conventions.md。pythia conventions
- 通过 询问应由开发者决定的事项: 保留还是删除什么、现有行是否允许为
pythia-spec以及回填值、保留期限、由谁写入该表(API package、trigger 或 interface),以及当内部规范没有相关规则时使用 identity column 还是 sequence。绝不能擅自为NULL列设定业务默认值。NOT NULL - 编写一个有序脚本——提供了模板和数据类型规则:
reference/ddl-standards.md- 为每个约束命名(、
PK_、FK_、UK_,除非内部规范另有规定);每张表都要有主键;每个 FK 列都要有索引;CK_ - 文本使用 ——一个越南语字符可能占用 3 字节;金额使用
VARCHAR2(n CHAR),绝不使用NUMBER(p,s);根据需要使用FLOAT或DATE;TIMESTAMP - 为每一张新表和每一个新列编写 和
COMMENT ON TABLE:含义、单位、允许值和来源。这里可以使用越南语——COMMENT ON COLUMN只接受字面量(不能使用COMMENT ... IS),并且 pythia 会原样发送 UTF-8;unistr会在字符集无法容纳这些内容时发出警告。pythia doctor --db
- 为每个约束命名(
- 执行 lint:(只运行一次,这样 comments 文件也会被计入)——检查缺失的注释、未命名的约束、未建立索引的 FK、没有默认值的
pythia lint script.sql comments.sql、使用字节语义的文本,以及缺少内部规范要求的列。发现错误应修复,而不是争辩。ADD ... NOT NULL - 使用 落地执行(
pythia-deploy):预览每一条语句,只需一次批准,按顺序执行,并在首次失败时停止。单条语句也可以照常通过pythia deploy script.sql执行。pythia apply默认设为structural——应如实转达拒绝结果;由开发者决定(deny,或使用指定了pythia policy set structural confirm的 autopilot lease)。structural - 验证():运行
pythia-verify、pythia cols T(缺失数为 0),并对照基线运行pythia comments T。pythia invalid
Changing a live table — expand, then contract
修改在线表——先扩展,再收缩
| Change | Safe shape |
|---|---|
| New mandatory column | |
| Rename | Never in place on a shared schema: add the new column, copy, move the callers, drop the old one later — a separate, destructive approval. |
| Type change | Widening ( |
| New FK on existing data | |
| Drop | Destructive: its own preview, its own approval, never inside an autopilot lease unless the card said so. Check the Recycle Bin is on and never add |
Big tables (millions of rows): with a default is
metadata-only, but , index builds and backfills are not — ask about
a window, and index builds need Enterprise Edition. Partitioning
and compression are separately licensed options: name that before
proposing them.
ALTER TABLE ... ADDMODIFYONLINE| 变更 | 安全做法 |
|---|---|
| 新增必填列 | |
| 重命名 | 在共享 schema 中绝不原地执行:添加新列、复制数据、迁移调用方,之后再删除旧列——作为一项独立的破坏性操作审批。 |
| 类型变更 | 扩宽( |
| 在现有数据上添加 FK | 先执行 |
| 删除 | 破坏性操作:单独预览、单独审批,除非任务卡中明确说明,否则绝不能放在 autopilot lease 内执行。确认 Recycle Bin 已开启,未经要求绝不能添加 |
对于数百万行的大表:带默认值的 仅修改元数据,但 、索引构建和回填并非如此——应询问可操作的维护窗口,而 索引构建需要 Enterprise Edition。分区和压缩是单独授权的选项:提出这些方案前应先说明这一点。
ALTER TABLE ... ADDMODIFYONLINEIs rollback real?
回滚真的有效吗?
| Statement | Undo |
|---|---|
| Yes — the previous comment is snapshotted; |
| A |
| |
| No. Flashback is a DBA's job, if retention allows it. |
| 语句 | 撤销方式 |
|---|---|
| 是——旧注释已保存快照; |
| 执行 |
| 执行 |
| 不能。 如果保留期允许,Flashback 由 DBA 负责处理。 |
Red Flags — STOP if you catch yourself thinking
危险信号——发现自己在有以下想法时立即停止
| Thought | Reality |
|---|---|
| "Comments later, once it works" | Later never comes; the dictionary is the only documentation that survives. Same script. |
| "The FK index is an optimisation" | Without it, deleting a parent locks the whole child table. It is correctness under load. |
| "VARCHAR2(100) is plenty" | 100 bytes is ~33 Vietnamese characters in AL32UTF8. Say |
| "I'll default the NOT NULL column to 0" | That is a business decision made silently. Ask. |
| "Rename is one statement" | And one broken caller per reference. Expand, then contract. |
| "The table is new, impact is zero" | Say so with |
| 想法 | 现实情况 |
|---|---|
| 「能运行之后再补注释」 | 「以后」永远不会到来;数据字典是唯一能够长期留存的文档。必须在同一个脚本中完成。 |
| 「FK 索引只是一项优化」 | 没有它,删除父表记录会锁住整个子表。这在负载下属于正确性问题,而不只是性能优化。 |
「 | 在 AL32UTF8 中,100 字节约等于 33 个越南语字符。应使用 |
「我会把 | 这是未经说明的业务决策。必须询问。 |
| 「重命名只需一条语句」 | 每处引用都会因此产生一个损坏的调用方。先扩展,再收缩。 |
| 「这是新表,影响范围为零」 | 运行 |
When NOT to use this skill
哪些情况下不要使用此 skill
- Changing code that reads the table → /
pythia-write.pythia-package - A slow query on an existing table → (an index is still designed here once tuning asks for it).
pythia-tune - Data fixes (/
UPDATE) →DELETE; they arepythia-apply.data_dml
- 修改读取该表的代码 → /
pythia-write。pythia-package - 现有表上的慢查询 → (但当调优提出要求时,索引仍应在此处设计)。
pythia-tune - 数据修复(/
UPDATE)→DELETE;它们属于pythia-apply。data_dml