troubles deploying with diigtal ocean node sequelize - node.js

Im trying to make a deploy in Digital Ocean when i try to make a migration using sequelize cli but wehn i do it
npx sequelize db:migrate
its says a error in the terminal and says
ERROR: Cannot find "/home/deploy/app/config/config.json". Have you run "sequelize init"?
then i tri using
npx sequelize init
and create all the folders (migrations - models - config - seeders, etc) THEN i move my migrations to the folder created to try to fix the issue, then in the config/config.json y config all the bd config, and try it again but says the same issue all the time
how can i fix that please i need to make this deploy can someone helps me?

I have solved it using
npx sequelize db:migrate WORKDIR /myapp/path

Related

Please make sure your database server is running at `localhost`:`5432` - Prisma Nest js -Down migration error

I am using Nest js + Prisma + Postgres in the Backend of my website. I am trying to down migrate
by following the document https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/generating-down-migrations it is working fine until it reached this command.
npx prisma db execute --file ./down.sql --schema prisma/schema.prisma
And it is throwing this error
Error: P1001
Can't reach database server at localhost:5432
Please make sure your database server is running at localhost:5432.
I am using Prisma 3.15 .all other commands work fine I am getting this error when I run
npx prisma db execute --file ./down.sql --schema prisma/schema.prisma

Sequelize Credentials for Deploying Node.js App to Heroku

I am currently learning Node.js (with Express, Postgres, Sequelize) and have a very simple (API) app running locally (it's working, tried with Postman) I now want to deploy to Heroku. I have some basic Heroku knowledge as I've used Rails in the past, but I am stuck with some things Rails handles behind the scenes.
I've set up a config.js file with some production credentials generated when running npx sequelize-cli init, I've updated my local settings (this works!) but what do I need to add as my production credentials? Do I need to provide them on my own? Or are those provided by Heroku?
Please note — I've already setup my pipeline and app as well as Postgres on Heroku but when trying to connect to my app via the cli, e.g. heroku run bash --app name-of-my-app and running npx sequelize-cli db:create it gives me the following error:
Loaded configuration file "config/config.js".
Using environment "production".
TypeError: Cannot read property 'replace' of undefined
at Object.removeTicks (/app/node_modules/sequelize/lib/utils.js:347:12)
at Object.quoteIdentifier (/app/node_modules/sequelize/lib/dialects/abstract/query-generator/helpers/quote.js:50:35)
at PostgresQueryGenerator.quoteIdentifier (/app/node_modules/sequelize/lib/dialects/abstract/query-generator.js:891:24)
at getCreateDatabaseQuery (/app/node_modules/sequelize-cli/lib/commands/database.js:77:50)
at Object.exports.handler (/app/node_modules/sequelize-cli/lib/commands/database.js:45:17)
Further notes:
I am using Node 14.0.0 and sequelize 6.3.0
I've added "engines": { "node": "14.x" } to my package.json
I don't have a procfile as Heroku states it's not needed anymore
My app entrypoint is app.js
Putting this up here, in case someone else is having similar troubles:
Just figured it out, it's actually pretty straight forward but I was a bit confused by the default config.js setup provided when running npx sequelize-cli init.
this is what my production settings look like:
production: {
use_env_variable: 'DATABASE_URL',
dialect: 'postgres'
}

problem with sequelize db:migrate and postgres

i'm a beginner and i'm trying to deploy a back-end application. I'm using an aws EC2 with ubuntu server and the problem is as follows. in the application on my machine the command "yarn sequelize db: migrate" runs normally, executes the migrations and creates the tables. but not on the server. I already changed the environment variables, even put the information directly in the code, even so it does not run the migrations. the most it does is: deploy#ip-xxx.xxx.xxx.xxx: ~ / app / server $ yarn sequelize db: migrate
yarn run v1.22.4
$ /home/deploy/app/server/node_modules/.bin/sequelize db: migrate
Sequelize CLI [Node: 14.4.0, CLI: 5.5.1, ORM: 5.21.6]
Loaded configuration file "src / config / database.js".
Done in 0.54s.
It is as if I did not enter the migrations folder for any reason
i'm using postgres on docker image.
TL;DR: try to use the latest version for all the dependencies for sequelize-cli, as shown in the last code block of this response.
I am not 100% sure if this is the same issue I encountered. But I have been stuck in a similar situation for 2 days. Basically when I run "npx sequelize db:migrate", it will show the following,
Sequelize CLI [Node: 14.4.0, CLI: 5.5.1, ORM: 5.21.6]
Loaded configuration file "src / config / database.js".
Using environment "development".
Then it just stopped there! I dived deep into the sequelize-cli library and put some console log statements in to see what's failing. Eventually I found that somehow it's failing in
return sequelize.authenticate().then(() => {
this line in the /sequelize-cli/lib/core/migrator.js
Eventually, it got me wondering if this is an external dependency issue. Then I use the latest dependencies, as following in my package.json
"dependencies": {
"pg": "^8.2.1",
"sequelize": "^5.21.13",
"sequelize-cli": "^5.5.1"
},
I realized that I was previously using "pg": "^7.18.2". Then this fixed the issue for me.

Nest.js throw an error when run main.js in production

I am using Nest.js to develop a web backend.
When I use npm run build, the cmd shows success.
Error Image here
But when I use node dist/main.js, the cmd shows error. But I'm sure this file exist and in develop mode (npm run start), everything's ok.
Here is how I have imported things in my code:
Code snapshot
Here is entities code in typeorm:
entities: [__dirname + '/../**/*.entity.ts']
Try to do something like entities: [__dirname + '/**/**/*.entity{.ts,.js}'].
The error is about paths. My guess though.

How to make heroku play nice with sequelize.js + postgres?

I'm most of the way there, has anyone gotten it to succesfully work? I only have the database working locally, after I git push heroku master the connection to the database fails.
Add 'Heroku Postgres' either through the Heroku CLI or under your project's Resources tab. It should also give you a DATABASE_URL variable which you need for later.
Add pg module from Heroku. See the documentation here.
$ npm install --save --save-exact pg
Then, on the server, use the DATABASE_URL we just got.
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: true,
});
client.connect();
Put "use_env_variable": "DATABASE_URL" on the config.json file under "production". Should look like
"production": {
"use_env_variable": "DATABASE_URL"
...
}
Run migrations on Heroku. An option if you want to use sequelize-cli is:
$ npm install sequelize-cli --save
$ heroku run sequelize db:migrate
And it should work.

Resources