how to execute a .sql script on heroku?

后端 未结 4 547
醉梦人生
醉梦人生 2020-12-12 13:02

I have a .sql file with a bunch of insert commands that I want to execute on my postgres database on heroku. But I don\'t know how to do it:-

If I had access to post

4条回答
  •  死守一世寂寞
    2020-12-12 13:26

    I'm going to suggest another approach, since I was already benefited from this question and I looked for better options to do that (in terms of speediness).

    I conditioned the database seeding to an environment variable. With Sequelize is going to be something like this (the code bellow is only to demonstrate the conditioning):

    // Node.js app
    if (process.env.RESTARTDB) {
      sequelize.sync({ force: true }).then(() => {
        // "init" is a raw SQL query
        sequelize.query(init);
      });
    }
    

    This method is not recommended if you don't want to restart your app every time you want to query that SQL file, but it is so much faster than doing by using heroku pg:psql.

    Here you can find more info on how to config your vars.

提交回复
热议问题