-1

I'm using Strapi my content management system, hosted on Heroku. However, I'd like to be able to edit content directly on the Heroku server, and pull those changes to my local environment at a later date, when more extensive CMS development is required.

It is well documented how to deploy changes from local -> Heroku, but not the other way around. Can somebody point me in the right direction?

Muhammad Ahmod
  • 649
  • 4
  • 15
jnstn
  • 191
  • 1
  • 2
  • 10

1 Answers1

1

Not entirely sure what you asking but I'm going to try...

Lets first understand the two main moving parts in Strapi.

  1. The content-type-builder (use the content-type builder to create a content type eg. books)
  • 1.1) You should always create your content-types using the content-type-builder in your local environment and then push it to your host(Heroku) This is also recommended by Strapi and to enforce it they have disabled the content- type-builder plugin when NODE_ENV is set to production.
  1. The content-type-data (use the above created books-content-type to create a book)
  • 2.1) As of writing this Strapi v3.1.4 Strapi cannot move your content-type-data between environments for you. ie. If you create a books content-type and you use it to create a book in your localhost environment then that book will only exist in your local environment.

If you do need/want to move your content-type-data between environments you need to develop a migration mechanism that will seed the data from one database to the next.

as a rough example: In your ./config/functions/bootstrap.js file you can create a module that gets content-type-data from your heroku instance via the public api and seeds that into your local database. For this to work you need to set the content-types' permission for read access in the heroku app.

example bootstrap.js

const productionSeed= require('./seeds');
module.exports = async () => {
    if (process.env.NODE_ENV == "development") {
    await productionSeed.seedData();
    }
};

example seed.js

module.exports.seedData= async () => {
    try {
        //Sudo code:
        var books = GET http://{heroku-app-name}/books
    
        foreach(book in books){
            await strapi.services.books.create({
            name: book.name;
        });
    } catch (error) {
        console.error(error);
    }
};

This is the long way of doing it when the use case is simple. A Production database should be migrated using a migration script which you can call and use in the same way.

If you want to move the actual content-type then you will have to clone your heroku git repository, you can do so using heroku git:clone -a {app name}

N.B A Heroku app’s Git repository is intended for deployment purposes only. Cloning from this repository is not officially supported as a feature and should be attempted only as a last resort.

you can find out more here: https://devcenter.heroku.com/articles/git-clone-heroku-app

Muhammad Ahmod
  • 649
  • 4
  • 15
  • Thanks for the input. I was hoping that heroku would allow for a `heroku git:commit -am "commit message"` type command that would allow the platform to commit changes back to the repository. Certainly, there is a lot of information there to get started. Thank you – jnstn Sep 01 '20 at 21:14
  • If you feel my answer did clear things up for you or helped in anyway, please could vote on it and mark it as the correct answer, thank you – Muhammad Ahmod Sep 01 '20 at 21:17
  • Also I think you Aubrey mid understanding that command. Heroku’s version control repository is not the same as your github version control Repository... – Muhammad Ahmod Sep 01 '20 at 21:20