Implement "migrationActions" to allow migration of data / data conversions between syncActions updates
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- javascript, nodejs
调研方向
该 issue 没有指明仓库文件、测试或现有的迁移入口。首先定位 syncActions 的实现和相关 issue #355,然后确定当前如何处理自定义字段和产品属性。完成的要求是具备已达成一致的迁移设计、转换行为、清理操作,以及对受支持资源类型的覆盖。
由索引模型根据 Issue 内容生成。
描述
Hi,
wouldn't it be awesome if we could update custom types or product types field definitions with a migration strategy to prevent data loss? As far I know, It doesn't exist any assistant in migrating, for example, a ProductVariant attribute between different field types.
Scope:
It will affect custom field definitions (Types, ProductTypes). That means migration support for product attributes, custom attributes of all supported resources. For the base fields, it's not necessary since the type will never change.
Use cases:
- A user might want to change the field
StringtoLocalizedString - A user might want to change the field
StringtoNumber - A user might want to change the field
StringtoSetOfStrings
With migrationActions I think about a companion to control how the old data is preserved.
That feature request comes from the daily practice experience with CT. Our product is very new and the model is constantly evolving.
I think this feature would bring a lot of value to the platform because it allows writing migrations scripts in a convenient and safe way.
That migration tool can be implemented in a very generic way so we don't need to respect every resource type individually.
It would require that "syncActions" can handle changes in custom attributes. I have seen that the current implementation respects only base fields or the implementation is just not complete.
Out of scope:
Updates in base fields are covered by sync-actions whereby the implementation doesn't cover all cases e.g there is no support for custom fields in types or product-types. That half complete implementation is really hard to track.
It's also really hard to find out what sync really means in the context of the "resourceType". As a customer, I would expect that sync checks EVERYTHING or at least the documentation should clarify the exact behavior.
Related issues:
https://github.com/commercetools/nodejs/issues/355
Some code to illustrate the migration approach:
1. Determine attribute changes
import { typeConversionMap } from '@commercetools/migration-actions';
const updateActions = productTypeSync.buildActions(next, previous, { preservePreviousFields: true });
// for example the attribute type has changed from "String" to "Number"
// we will create a new field to hold the new value + saving type and name differences in the attribute name
updateActions = [
{
action: 'addAttributeDefinition',
attribute: {
name: 'previous-attribute-name__string-number__next-attribute-name',
type: { name: 'Number' }
}
}
];
2. Apply changes and create temporary fields to hold the new value + conversion information
client.execute(updates);
3. Fetch records which should be migrated
// for example
const productA = {
attributes: [
{ name: 'previous-attribute-name__string-number__next-attribute-name', value: null },
{ name: 'previous-attribute-name', value: '2' }
]
};
4. We will create actions to migrate all fields
With the convention "old__string-number__new" or even "old__oldType-newType__old" we know how to convert that field.
const typeConversionHelper = {
[[typeConversionMap.String][typeConversionMap.Number]]: old => parseInt(old),
[[typeConversionMap.String][typeConversionMap.ListString]]: old => [old.toString()],
[[typeConversionMap.String][typeConversionMap.LocalizedString]]: old => { en: old }
};
const dataActions = migrationSync.buildActions([productA], { conversionHelper });
dataActions = {
url: 'https://api/products/....',
body: {
actions: [
{
action: 'setAttribute',
name: 'previous-attribute-name__string-number__next-attribute-name',
value: 2
}
]
}
};
5. Determine changes based on the naming convention and remove old fields and rename temporary fields
const dataActions = migrationSync.migrationCleanActions([productA]);
dataActions = [
{
action: 'removeAttributeDefinition',
name: 'previous-attribute-name'
},
{
action: 'changeAttributeName',
attributeName: 'previous-attribute-name__string-number__next-attribute-name',
newAttributeName: 'next-attribute-name'
}
];
- 主要语言
- JavaScript
- 星标
- 77
- 派生
- 70
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
commercetools/nodejs 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 35/100
commercetools/nodejs#1901 ·
-
难度 2/5 1-3 小时 新手友好度 45/100
commercetools/nodejs#1895 · 1 条评论 ·
-
难度 1/5 1-3 小时 新手友好度 55/100
commercetools/nodejs#1891 ·
-
难度 5/5 一周以上 新手友好度 20/100
commercetools/nodejs#1889 ·
-
难度 3/5 1-2 天 新手友好度 35/100
commercetools/nodejs#1884 · 4 个 reaction ·
查看 commercetools/nodejs 的全部 Issue
相似的 Issue
-
[Bug] @deck.gl/arcgis dist import resolves to unpublished @deck.gl/core source path (9.3.11, 9.4.0)未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
stac-utils/stac-fields#42 ·
-
agent/security hive/hosted-available-lke648397-260827-5n31 security
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
channels:add check:passed
难度 1/5 1 小时以内 新手友好度 75/100
维护者通常 2 天内回复