[RFC] @graphile/lds2
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, postgresql, typescript
调研方向
首先检查当前的 @graphile/lds 实现及其被 @graphile/subscriptions-lds 使用的方式,然后比较此处描述的 wal2json version-format 1 和 2 定义。完成的标准是提供一个实用的 @graphile/lds2 package,支持所需的 wal2json 行为和 watch 能力,并处理相关的 subscription 集成。
由索引模型根据 Issue 内容生成。
描述
Feature description
The new package @graphile/lds2 is in essence a copy of the current implementation with two changes (1 & 2) and one addition (3):
-
Minimal required version of wal2json is at this time of writing 2.3, due to requiring the
include-pkparameter to be available. This is required for@graphile/subscriptions-ldsto properly work in cases whereREPLICA IDENTITY FULLis enabled on a table. -
Dropping support for
version-format 1, and moving toversion-format 2which no longer reports changes on a transaction level, but on a tuple level. Additional bonus is that in my opinion the json object is structured more like what the industry standard is today. -
Adding watch capability much to what I believe
graphile-buildhas for building it schema. Currently@graphile/ldsis not able to actively listen to schema changes, adding this would allow us to circumvent the need for theinclude-pkparameter and as such also keep supportingversion-format 1and wal2json <= 2.3, yet this is not the main goal of this addition.I believe the most useful purpose of adding a watch capability is to be able to support subscriptions on native pg >=11 partitioned tables and timescale hypertables. These table structures are providing a
virtualtable that one can doinsert,update,delete,selectupon, but in actuality these operations are redirected to one or more sub tables (partitions). wal2json does NOT report changes on this (virtual) parent table level, but on the actual subtable that the change occurred. This makes it impossible to subscribe to these type of tables with the current implementation of@graphile/lds. I am aware of the fact that native pg >= 11 partitioned tables are NOT very well supported inpostgraphileatm (Only the partitions are showing up in the schema, not the virtual table), but due to the different technical implementation of timescale hypertables these are actually coming out in the generated schema just fine (No partitions are shown, just the parent table).Having this watch capability allows us to figure out that when a change occurs in one of these sub tables, we also need to fabricate a same change for the (
virtual) parent table.
Motivating example
Motivation for this alternative version is twofold, being that the the current implementation of @graphile/lds:
-
Assumes that the primary key information of a change is always included in the property
oldkeysif the propertyoldkeysis included. This is NOT always the case due to the possibilty of enablingREPLICA IDENTITY FULLon a table which changes the contents ofoldkeysfrom not only containing the primary key(s), but to containing the entire record as it was before said change (much like theOLDvalue in update/delete triggers). As such, enabling this feature on a table breaks the current implementation of@graphile/lds.Fixing the above issue requires the use of a parameter
include-pkwhich is only available in version >=2.3 of wal2json, and as of right now we haven't been able to find a method to detect which version of wal2json is installed. The only way seems to be that oftry {} catch {}the code with the parameter and falling back on one without if it fails with a parameter unknown error. Problem I have with this approach is that we'd have to resort to string matching to determine the cause, which feels a bit too iffy to me. -
Is built on
version-format 1of wal2json which produces a JSON object per transaction. All of the new/old tuples are available in the JSON object. Whereas the newerversion-format 2produces a JSON object per tuple, supports thetruncateoperation and provides in my opinion a more logical constructed object.Below are both formats as defined in
typescriptdefinitions, these are both the default format which can be augmented with additional metadata based on parameters. One of which is the much neededinclude-pkwhich is only available in wal2json >= 2.3format-version 1:export interface Change { kind: Kind; schema: string; table: string; columnnames?: string[]; columntypes?: string[]; columnvalues?: Columnvalue[]; oldkeys?: Oldkeys; } enum Kind { Insert = 'insert', Update = 'update', Delete = 'delete' } export type Columnvalue = any; export interface Oldkeys { keynames: string[]; keytypes: string[]; keyvalues: Keyvalue[]; } export type Keyvalue = string;format-version 2:export interface Change { action: Action; schema: string; table: string; columns?: Column[]; identity?: Column[]; } enum Action { Insert = 'I', Update = 'U', Delete = 'D', Truncate = 'T' } export interface Column { name: string; type: string; value: Value; } export type Value = any;
As we discussed in Discord fixing/adding the above 2 points would result in such breaking changes that are whole new package is warranted. This new package @graphile/lds2 would have more strict requirements on which version of wal2json is used.
Breaking changes
None, because it is a new package. Yet, in order to make this package useful an update to @graphile/subscription-lds or alternative package that does the same but using @graphile/lds2 is required.
Supporting development
I [tick all that apply]:
- am interested in building this feature myself
- am interested in collaborating on building this feature
- am willing to help testing this feature before it's released
- am willing to write a test-driven test suite for this feature (before it exists)
- am a Graphile sponsor ❤️
- have an active support or consultancy contract with Graphile
- 主要语言
- JavaScript
- 星标
- 764
- 派生
- 128
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
graphile/graphile-engine 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 35/100
graphile/graphile-engine#869 · 1 条评论 · 1 个 reaction ·
-
Provide a type guard to distinguish between ResolveTree and FieldsByTypeName可能重新可做 关联的 PR 已关闭且未合并。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 45/100
graphile/graphile-engine#849 · 2 条评论 · 1 个 reaction ·
-
🐛 bug help wanted
难度 3/5 1-2 天 新手友好度 35/100
graphile/graphile-engine#818 ·
-
Race condition when closing LDS可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 32/100
graphile/graphile-engine#755 · 2 条评论 ·
-
难度 5/5 一周以上 新手友好度 15/100
graphile/graphile-engine#725 · 17 条评论 · 5 个 reaction ·
查看 graphile/graphile-engine 的全部 Issue
相似的 Issue
-
FEATURE REQUEST
难度 2/5 1-3 小时 新手友好度 67/100
linuxmint/cinnamon-spices-applets#9356 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
needs-triage Platform(Default)
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 63/100
维护者通常 1 天内回复