2022-01-06 11:38:40 +00:00
|
|
|
import { Client, Doc, DocumentQuery, Domain, FindOptions, IncOptions, ObjQueryType, PushOptions, Ref } from '@anticrm/core'
|
2021-12-07 18:45:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export type MigrateUpdate<T extends Doc> = Partial<T> & Omit<PushOptions<T>, '$move'> & IncOptions<T> & {
|
|
|
|
// For any other mongo stuff
|
|
|
|
[key: string]: any
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface MigrationResult {
|
|
|
|
matched: number
|
|
|
|
updated: number
|
|
|
|
}
|
|
|
|
|
2021-12-22 09:25:16 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export type MigrationDocumentQuery<T extends Doc> = {
|
|
|
|
[P in keyof T]?: ObjQueryType<T[P]> | null
|
|
|
|
} & {
|
|
|
|
$search?: string
|
|
|
|
// support nested queries e.g. 'user.friends.name'
|
|
|
|
// this will mark all unrecognized properties as any (including nested queries)
|
|
|
|
[key: string]: any
|
|
|
|
}
|
|
|
|
|
2021-12-07 18:45:11 +00:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
* Client to perform model upgrades
|
|
|
|
*/
|
|
|
|
export interface MigrationClient {
|
|
|
|
// Raw collection operations
|
|
|
|
|
|
|
|
// Raw FIND, allow to find documents inside domain.
|
2021-12-22 09:25:16 +00:00
|
|
|
find: <T extends Doc>(domain: Domain, query: MigrationDocumentQuery<T>, options?: Omit<FindOptions<T>, 'lookup'>) => Promise<T[]>
|
2021-12-07 18:45:11 +00:00
|
|
|
|
|
|
|
// Allow to raw update documents inside domain.
|
2021-12-22 09:25:16 +00:00
|
|
|
update: <T extends Doc>(domain: Domain, query: MigrationDocumentQuery<T>, operations: MigrateUpdate<T>) => Promise<MigrationResult>
|
2021-12-15 09:04:43 +00:00
|
|
|
|
|
|
|
// Move documents per domain
|
|
|
|
move: <T extends Doc>(sourceDomain: Domain, query: DocumentQuery<T>, targetDomain: Domain) => Promise<MigrationResult>
|
2022-01-06 11:38:40 +00:00
|
|
|
|
|
|
|
create: <T extends Doc>(domain: Domain, doc: T) => Promise<void>
|
|
|
|
delete: <T extends Doc>(domain: Domain, _id: Ref<T>) => Promise<void>
|
2021-12-07 18:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export type MigrationUpgradeClient = Client
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
export interface MigrateOperation {
|
|
|
|
// Perform low level migration
|
|
|
|
migrate: (client: MigrationClient) => Promise<void>
|
|
|
|
// Perform high level upgrade operations.
|
|
|
|
upgrade: (client: MigrationUpgradeClient) => Promise<void>
|
|
|
|
}
|