Sunday 21 May 2017

Run Sequelize migration after deployment to App Engine

I have create a sample project for myself to try Node.js with Sequelize on Google App Engine.

I can run the project locally and it works fine, however when I deploy it to App Engine gcloud app deploy

I get the following error:

{
    name: "SequelizeDatabaseError",
    message: "ER_NO_SUCH_TABLE: Table 'sql8175762.Likes' doesn't exist",
    parent: {
        code: "ER_NO_SUCH_TABLE",
        errno: 1146,
        sqlState: "42S02",
        index: 0,
        sql: "SELECT `id`, `code`, `likes`, `createdAt`, `updatedAt` FROM `Likes` AS `Likes`;"
    },
    original: {
        code: "ER_NO_SUCH_TABLE",
        errno: 1146,
        sqlState: "42S02",
        index: 0,
        sql: "SELECT `id`, `code`, `likes`, `createdAt`, `updatedAt` FROM `Likes` AS `Likes`;"
    },
    sql: "SELECT `id`, `code`, `likes`, `createdAt`, `updatedAt` FROM `Likes` AS `Likes`;"
}

Thats because the Sequelize migration doesnt run however I do have it specified in npm start command:

"scripts": {
    "deploy": "gcloud app deploy",
    "start": "npm install & sequelize db:migrate & NODE_ENV=production node ./bin/www"
},

I have never used app engine for node deployment and I am not even sure if the steps I am talking are correct to deploy, migrate and run the app.

Does anyone have any tips regarding this?



via adrian_88

No comments:

Post a Comment