Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migrations for contact fields #142

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions migrations/1732891349_contacts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Client } from "@datocms/cli/lib/cma-client-node";

export default async function (client: Client) {
const itemTypes = await client.itemTypes.list();
const menuItemType = itemTypes.find(
(itemType: { api_key: string }) => itemType.api_key === "menu"
) || { id: "" };

const fields = await client.fields.list(menuItemType.id);
const findField = (label: string) =>
fields.find((field: any) => field.label === label);

const errorNotificationContactsField = findField(
"Error notification contacts"
);
if (!errorNotificationContactsField) {
console.log(
'Create Multiple links field "Error notification contacts" (`error_notification_contacts`) in model "Menu" (`menu`)'
);
await client.fields.create(menuItemType.id, {
id: "GlLvpmJFTBup26dDM2OMuQ",
label: "Error notification contacts",
field_type: "links",
api_key: "error_notification_contacts",
validators: {
items_item_type: {
on_publish_with_unpublished_references_strategy: "fail",
on_reference_unpublish_strategy: "delete_references",
on_reference_delete_strategy: "delete_references",
item_types: [menuItemType.id],
},
},
appearance: { addons: [], editor: "links_select", parameters: {} },
default_value: null,
});
}

const feedbackContactsField = findField("Feedback contacts");
if (!feedbackContactsField) {
console.log(
'Create Multiple links field "Feedback contacts" (`feedback_contacts`) in model "Menu" (`menu`)'
);
await client.fields.create(menuItemType.id, {
id: "CPxFkf5cRPKm0ORLakLX3Q",
label: "Feedback contacts",
field_type: "links",
api_key: "feedback_contacts",
validators: {
items_item_type: {
on_publish_with_unpublished_references_strategy: "fail",
on_reference_unpublish_strategy: "delete_references",
on_reference_delete_strategy: "delete_references",
item_types: [menuItemType.id],
},
},
appearance: { addons: [], editor: "links_select", parameters: {} },
default_value: null,
});
}
}
Loading