fix: revert document content field rename (#6955)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov
2024-10-16 22:52:46 +07:00
committed by GitHub
parent d1bf10b1d9
commit dea31012b5
10 changed files with 136 additions and 53 deletions
+19 -20
View File
@@ -41,7 +41,7 @@ import {
} from '@hcengineering/model'
import attachment, { TAttachment } from '@hcengineering/model-attachment'
import chunter from '@hcengineering/model-chunter'
import core, { TCard, TTypedSpace } from '@hcengineering/model-core'
import core, { TDoc, TTypedSpace } from '@hcengineering/model-core'
import { createPublicLinkAction } from '@hcengineering/model-guest'
import { generateClassNotificationTypes } from '@hcengineering/model-notification'
import preference, { TPreference } from '@hcengineering/model-preference'
@@ -69,24 +69,24 @@ export class TDocumentEmbedding extends TAttachment implements DocumentEmbedding
declare attachedToClass: Ref<Class<Document>>
}
@Model(document.class.Document, core.class.Card, DOMAIN_DOCUMENT)
@Model(document.class.Document, core.class.Doc, DOMAIN_DOCUMENT)
@UX(document.string.Document, document.icon.Document, undefined, 'name', undefined, document.string.Documents)
export class TDocument extends TCard implements Document, Todoable {
export class TDocument extends TDoc implements Document, Todoable {
@Prop(TypeString(), document.string.Name)
@Index(IndexKind.FullText)
title!: string
@Prop(TypeCollaborativeDoc(), document.string.Document)
content!: CollaborativeDoc
@Prop(TypeRef(document.class.Document), document.string.ParentDocument)
declare parent: Ref<Document>
parent!: Ref<Document>
@Prop(TypeRef(core.class.Space), core.string.Space)
@Index(IndexKind.Indexed)
@Hidden()
declare space: Ref<Teamspace>
@Prop(TypeString(), document.string.Name)
@Index(IndexKind.FullText)
declare title: string
@Prop(TypeCollaborativeDoc(), document.string.Document)
declare description: CollaborativeDoc
@Prop(TypeRef(core.class.Account), document.string.LockedBy)
@Hidden()
lockedBy?: Ref<Account>
@@ -125,12 +125,9 @@ export class TDocument extends TCard implements Document, Todoable {
rank!: Rank
}
@Model(document.class.DocumentSnapshot, core.class.Card, DOMAIN_DOCUMENT)
@Model(document.class.DocumentSnapshot, core.class.Doc, DOMAIN_DOCUMENT)
@UX(document.string.Version)
export class TDocumentSnapshot extends TCard implements DocumentSnapshot {
@Prop(TypeRef(document.class.Document), document.string.ParentDocument)
declare parent: Ref<Document>
export class TDocumentSnapshot extends TDoc implements DocumentSnapshot {
@Prop(TypeRef(core.class.Space), core.string.Space)
@Index(IndexKind.Indexed)
@Hidden()
@@ -138,11 +135,13 @@ export class TDocumentSnapshot extends TCard implements DocumentSnapshot {
@Prop(TypeString(), document.string.Name)
@Index(IndexKind.FullText)
declare title: string
title!: string
@Prop(TypeCollaborativeDocVersion(), document.string.Document)
@Hidden()
declare description: CollaborativeDoc
content!: CollaborativeDoc
@Prop(TypeRef(document.class.Document), document.string.ParentDocument)
parent!: Ref<Document>
}
@Model(document.class.SavedDocument, preference.class.Preference)
@@ -444,7 +443,7 @@ function defineDocument (builder: Builder): void {
allowedForAuthor: false,
label: document.string.Document,
group: document.ids.DocumentNotificationGroup,
field: 'description',
field: 'content',
txClasses: [core.class.TxUpdateDoc],
objectClass: document.class.Document,
defaultEnabled: false,
+69 -3
View File
@@ -13,7 +13,7 @@
// limitations under the License.
//
import { DOMAIN_TX, MeasureMetricsContext, SortingOrder } from '@hcengineering/core'
import { type CollaborativeDoc, DOMAIN_TX, MeasureMetricsContext, SortingOrder } from '@hcengineering/core'
import { type DocumentSnapshot, type Document, type Teamspace } from '@hcengineering/document'
import {
tryMigrate,
@@ -111,7 +111,7 @@ async function migrateContentField (client: MigrationClient): Promise<void> {
for (const document of documents) {
try {
const ydoc = await loadCollaborativeDoc(storage, client.workspaceId, document.description, ctx)
const ydoc = await loadCollaborativeDoc(storage, client.workspaceId, document.content, ctx)
if (ydoc === undefined) {
ctx.error('document content not found', { document: document.title })
continue
@@ -123,7 +123,7 @@ async function migrateContentField (client: MigrationClient): Promise<void> {
yDocCopyXmlField(ydoc, '', 'content')
await saveCollaborativeDoc(storage, client.workspaceId, document.description, ydoc, ctx)
await saveCollaborativeDoc(storage, client.workspaceId, document.content, ydoc, ctx)
} catch (err) {
ctx.error('error document content migration', { error: err, document: document.title })
}
@@ -202,6 +202,68 @@ async function renameFields (client: MigrationClient): Promise<void> {
}
}
async function renameFieldsRevert (client: MigrationClient): Promise<void> {
const ctx = new MeasureMetricsContext('renameFieldsRevert', {})
const storage = client.storageAdapter
type ExDocument = Document & {
description: CollaborativeDoc
}
const documents = await client.find<ExDocument>(DOMAIN_DOCUMENT, {
_class: document.class.Document,
description: { $exists: true }
})
for (const document of documents) {
await client.update(
DOMAIN_DOCUMENT,
{ _id: document._id },
{
$rename: {
description: 'content'
}
}
)
if (document.description.includes('%description:')) {
try {
const ydoc = await loadCollaborativeDoc(storage, client.workspaceId, document.description, ctx)
if (ydoc === undefined) {
continue
}
if (!ydoc.share.has('description') || ydoc.share.has('content')) {
continue
}
yDocCopyXmlField(ydoc, 'description', 'content')
await saveCollaborativeDoc(storage, client.workspaceId, document.description, ydoc, ctx)
} catch (err) {
ctx.error('error document content migration', { error: err, document: document.title })
}
}
}
const snapshots = await client.find<DocumentSnapshot>(DOMAIN_DOCUMENT, {
_class: document.class.DocumentSnapshot,
description: { $exists: true }
})
for (const snapshot of snapshots) {
await client.update(
DOMAIN_DOCUMENT,
{ _id: snapshot._id },
{
$rename: {
description: 'content'
}
}
)
}
}
export const documentOperation: MigrateOperation = {
async migrate (client: MigrationClient): Promise<void> {
await tryMigrate(client, documentId, [
@@ -234,6 +296,10 @@ export const documentOperation: MigrateOperation = {
func: async (client: MigrationClient): Promise<void> => {
await client.update(DOMAIN_DOCUMENT, { '%hash%': { $exists: true } }, { $set: { '%hash%': null } })
}
},
{
state: 'renameFieldsRevert',
func: renameFieldsRevert
}
])
},