Export / Import Models and Content

Hey hey,
we want to export our Content and Models sorted in JSON Files. We are able to use this (Exporting data and backups - DatoCMS) but thats only for all content unfiltered and not for the models. So what can i do with that? How can i import it to datoCMS without having the models?
Is there any way to export the Schema and the Content? And import both?
Thank you very much!
Have a nice day.
Best regards

hello @m.wiskow96 to export the models you need to write a similar script, listing all models: https://www.datocms.com/docs/content-management-api/resources/item-type/instances and fields: List all fields - Field - Content Management API

For the import instead is a different story, you need to write a script yourself, but it’s a bit more complex.

The example export was more meant as a way to backup all your content out of DatoCMS, not as an export/import functionality.

What’s your use case for that?

Is it possible to export the models into the migrations format.
So that the current state of the model is exported as a migration create file?

Hello @K-user and welcome to Community!

The migration files are just JS scripts in which you write the steps that should happen in the “migration”, the actual change of schema and possibly content as well.

If you want to export the models, you can use the REST API here: Model/Block - Content Management API to get the models list and then you can retrieve the fields: Field - Content Management API

You can save the JSON of the models/fields and reuse them in another instance. Makes sense?

Thx for the explanation.

1 Like

@mat_jack1 (I’m new to DatoCMS, but am liking what I see.)

I’m also interested in duplicating models and fields (the schema, if you like) from one project into another project. My usecase is as follows:

We’re building a set of branded portal websites for use by our sales partners. The codebase for the websites is the same for each portal, the only difference is the configuration with which a specific instance of the portal is deployed. The configuration includes the DatoCMS API token for the brand that is represented by the portal instance. Styling, content, and assets for the brand are then retrieved from the CMS.

My idea is to create a project with an initial model and set of associated fields, and use the REST API methods you mention in your post to extract the definitions. I assume that I can list all models, and then iterate the retrieved models to get the associated field definitions. Is that right?

Can I then use the extracted JSON definitions, as is, to load as the models and fields into a new project, to seed the structure, using the REST API?

That is, dropping the id field from each definition, would I iterate the field definitions first, and then iterate the model definitions, connecting the created models to the created fields, using the returned id attributes? Or is there a simpler approach?

Thanks for your help.

Cheers, S t u a r t .

1 Like

Hello @stuart5begg_datocms01

There is a built in way to duplicate a project, and you may choose to duplicate only the schema (models and fields), as we can see in this documentation link.

You can find this at the bottom of the project description, on the project owner account.

Would that fit your use case?

1 Like

Hi, @m.finamor

Thanks for your reply; very much appreciated.

I think that link you sent will be a great help for bootstrapping new brands into a new project from an existing reference brand.

I’m also thinking longer term, about a mechanism to propagate changes to the schema across all existing projects over time. That is, if we want to add/update/remove a model across all exisiting brand projects. I’m guessing that we’ll need to go via the Content Management API to synchronise these kind of changes.

We use tools (like liquibase and flyway) for our relational database change migrations, and may have to roll our own similar system for DatoCMS it seems.

Unless you have other great ideas?

Thanks, again, and cheers, S t u a r t .

1 Like

@stuart5begg_datocms01 that seems like the better idea, using the Content Management API you can easily make a script that gets all the models (and consequentially fields) from your boilerplate project, and synchronizes them with the other projects

Let me know if you run into any problems while implementing this solution.

Thank you for contacting us!

1 Like