-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
499 additions
and
343 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"environmentId": "", | ||
"apiKey": "", | ||
"migrationsPath": "./Migrations" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { MigrationModule } from "@kontent-ai/data-ops"; | ||
import { CollectionModels } from "@kontent-ai/management-sdk"; | ||
|
||
import { collectionHealthTechExtId } from "./constants/externalIds.js"; | ||
|
||
const migration: MigrationModule = { | ||
order: 1, | ||
run: async client => { | ||
const setCollectionsData: CollectionModels.ISetCollectionData[] = [ | ||
{ | ||
op: "addInto", | ||
value: { | ||
name: "healthtech", | ||
codename: "healthtech", | ||
externalId: collectionHealthTechExtId, | ||
}, | ||
}, | ||
{ | ||
op: "replace", | ||
reference: { codename: "default" }, | ||
property_name: "name", | ||
value: "common", | ||
}, | ||
]; | ||
|
||
await client | ||
.setCollections() | ||
.withData(setCollectionsData) | ||
.toPromise(); | ||
}, | ||
rollback: async client => { | ||
const setCollectionsData: CollectionModels.ISetCollectionData[] = [ | ||
{ | ||
op: "remove", | ||
reference: { codename: "healthtech" }, | ||
} as unknown as CollectionModels.ISetCollectionData, | ||
{ | ||
op: "replace", | ||
reference: { codename: "default" }, | ||
property_name: "name", | ||
value: "default", | ||
}, | ||
]; | ||
|
||
await client | ||
.setCollections() | ||
.withData(setCollectionsData) | ||
.toPromise(); | ||
}, | ||
}; | ||
|
||
export default migration; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { MigrationModule } from "@kontent-ai/data-ops"; | ||
|
||
const migration: MigrationModule = { | ||
order: 2, | ||
run: async client => { | ||
client as never; | ||
// TODO: | ||
}, | ||
rollback: async client => { | ||
client as never; | ||
// TODO: | ||
}, | ||
}; | ||
|
||
export default migration; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { MigrationModule } from "@kontent-ai/data-ops"; | ||
import { TaxonomyModels } from "@kontent-ai/management-sdk"; | ||
|
||
import { taxonomyArticleTypeExtId } from "./constants/externalIds.js"; | ||
|
||
const migration: MigrationModule = { | ||
order: 3, | ||
run: async client => { | ||
const taxonomyData: TaxonomyModels.IAddTaxonomyRequestModel = { | ||
name: "Article Type", | ||
codename: "article_type", | ||
external_id: taxonomyArticleTypeExtId.taxonomyGroup, | ||
terms: [ | ||
{ | ||
name: "Blog Post", | ||
codename: "blog_post", | ||
external_id: taxonomyArticleTypeExtId.terms.blogPost, | ||
terms: [], | ||
}, | ||
{ | ||
name: "news", | ||
codename: "news", | ||
external_id: taxonomyArticleTypeExtId.terms.news, | ||
terms: [], | ||
}, | ||
], | ||
}; | ||
|
||
await client | ||
.addTaxonomy() | ||
.withData(taxonomyData) | ||
.toPromise(); | ||
}, | ||
rollback: async client => { | ||
await client | ||
.deleteTaxonomy() | ||
.byTaxonomyExternalId(taxonomyArticleTypeExtId.taxonomyGroup) | ||
.toPromise(); | ||
}, | ||
}; | ||
|
||
export default migration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { MigrationModule } from "@kontent-ai/data-ops"; | ||
import { AssetFolderModels, ManagementClient, SharedContracts } from "@kontent-ai/management-sdk"; | ||
import * as fsPromises from "fs/promises"; | ||
import path from "path"; | ||
|
||
import { assetFoldersImagesExtId, assetKontentExternalId } from "./constants/externalIds.js"; | ||
|
||
const migration: MigrationModule = { | ||
order: 4, | ||
run: async client => { | ||
const assetFoldersData: AssetFolderModels.IAddAssetFoldersData = { | ||
folders: [ | ||
{ name: "Images", external_id: assetFoldersImagesExtId, folders: [] }, | ||
], | ||
}; | ||
|
||
await client | ||
.addAssetFolders() | ||
.withData(assetFoldersData) | ||
.toPromise(); | ||
|
||
await addAsset(client, { | ||
fileName: "kontent-ai.png", | ||
externalId: assetKontentExternalId, | ||
contentType: "image/png", | ||
collection: { codename: "default" }, | ||
}); | ||
}, | ||
rollback: async client => { | ||
await client | ||
.modifyAssetFolders() | ||
.withData([{ | ||
op: "remove", | ||
reference: { external_id: assetFoldersImagesExtId }, | ||
}] as unknown as AssetFolderModels.IModifyAssetFolderData[]) | ||
.toPromise(); | ||
|
||
await client | ||
.deleteAsset() | ||
.byAssetExternalId(assetKontentExternalId) | ||
.toPromise(); | ||
}, | ||
}; | ||
|
||
type AddAssetParams = Readonly<{ | ||
fileName: string; | ||
externalId: string; | ||
contentType: string; | ||
collection: SharedContracts.IReferenceObjectContract; | ||
folderExternalId?: string; | ||
descriptions?: Readonly<Record<string, string>>; | ||
}>; | ||
|
||
const addAsset = async (client: ManagementClient, params: AddAssetParams) => { | ||
const binaryData = await fsPromises.readFile(path.resolve(process.cwd(), `./src/assets/${params.fileName}`)); | ||
|
||
const fileRef = await client | ||
.uploadBinaryFile() | ||
.withData({ | ||
filename: params.fileName, | ||
binaryData, | ||
contentType: params.contentType, | ||
contentLength: binaryData.length, | ||
}) | ||
.toPromise() | ||
.then(res => res.data); | ||
|
||
return client | ||
.addAsset() | ||
.withData(() => ({ | ||
external_id: params.externalId, | ||
folder: params.folderExternalId ? { external_id: params.folderExternalId } : undefined, | ||
collection: { reference: params.collection }, | ||
file_reference: fileRef, | ||
descriptions: params.descriptions | ||
? Object.entries(params.descriptions).map(([codename, description]) => ({ | ||
language: { codename }, | ||
description, | ||
})) | ||
: undefined, | ||
})) | ||
.toPromise() | ||
.then(res => res.data); | ||
}; | ||
|
||
export default migration; |
Oops, something went wrong.