Export / Import from CLI?

I’d like to bootstrap my app with some predefined data via CLI so that the first time it is installed the data is already there.

I’d like to automate it so I don’t have to push any buttons in Strapi.

Is this possible?

Thanks

Hi @Phero!

I’ve built a plugin that does just that for Strapi v4 called config-sync.
https://github.com/boazpoolman/strapi-plugin-config-sync.

You would have to push the buttons in Strapi once.
Setting up permissions, settings and what not.
Then you can export that data to JSON files and import them on any other environment.

All through the CLI or Strapi admin GUI :slight_smile:

Excellent! Strange that it didn’t come up during my searches but I’ll make sure to check it out. This could be exactly what I need.

So this plugin import the endpoint permission that you have set after installation?

Yep!

With this plugin you can export the permissions you’ve set after installation.

Then you can add the exported files to your codebase (git), and import them everywhere.

1 Like

Hi, I have installed this plugin and it see it in Strapi 4 admin panel under Settings → Admin → Config Sync → Tool. I see the initial blue button to Export and when I do so, I see that it has created a folder /config/sync with many .json files.

I’m wondering if it’s possible to import data using this plugin? I have a file /sample.json that I would like to import into a pre-existing content type.

Thanks very much for your time and effort with this plugin!

Hi @avidrunner !

With this plugin you can export your pre-existing data records to JSON files to easily migrate them across environments. To make it work you can register a content type to be synced in the plugin.

That being said, this is really a all-or-noting approach. Once the type has been registerred all it’s records will be included in the sync process of this plugin. Meaning that all changes that might happen over time will be tracked with this plugin. Those changes can then be exported and added to version controll, or imported which will revert it back to the previous state.

I’m not certain what it is you’re trying to achieve. But if you’re looking to do a one-time import from the sample.json file to the database you are probably better of creating a custom migration script that imports from this file.

If you are looking to version control all the current and future records of your content type this plugin might be for you.

Hope that helps :slight_smile: