problem with sequelize db:migrate and postgres - node.js

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.

Related

Cannot connect to my databse addon on heroku

I attempted to use the command Heroku pg:psql to connect to my database addon in heroku but got a response below
--> Connecting to postgresql-regular-61345
unrecognized win32 error code: 123could not find a "psql" to execute
unrecognized win32 error code: 123could not find a "psql" to execute
psql: fatal: could not find own program executable
! psql exited with code 1
After using the heroku logs --tail command i got the following errors
sh: 1: nodemon: not found
Process exited with status 127
State changed from starting to crashed
I can also see all processes stopping with SIGTERM and the process exiting with status 143
Resolution steps I have taken
Verified that the environment variables have the path for installed postgress14 on my PC
Added a procfile to the root file in my backend code and spcified "web: node matthewfaceappback/server.js in the file"
Changed my set port to a variable port using process.env.PORT || 3000
Set all environment variable including my database url(set by default) on config variable in heroku
Verified there is a start up script
Updated all my packages using "npm update". after doing this i started expereincing the issue of processes stopping with SIGTERM and the process exiting with status 143
I moved nodemon from devDependencies to dependencies. nodemon version is 2.0.15
In package.json i inputed an engines parameter using the version of node in my case
{"engines": {
"node": "14.17.4"
}}
I restarted heroku using "heroku restart"
Below are links to the screenshots of the error
https://www.dropbox.com/s/5bdbyi9e99lbxhu/pic1.PNG?dl=0
https://www.dropbox.com/s/41euniaes5q68c9/pic2.PNG?dl=0
https://www.dropbox.com/s/50oqzbwmwrqogax/pic3.PNG?dl=0
Put nodemon back in the devDependencies and add it as a second node script in package.json:
"scripts": {
"start": "node matthewfaceappback/server.js",
"dev": "nodemon matthewfaceappback/server.js"
},
These two errors are completely unrelated.
The database connection error
The first issue, which I believe is the one you actually care about at the moment based on the title of the question, indicates that the Heroku CLI can't find a PostgreSQL client on your local machine.
The documentation makes the following recommendation
Set up Postgres on Windows
Install Postgres on Windows by using the Windows installer.
Remember to update your PATH environment variable to add the bin directory of your Postgres installation. The directory is similar to: C:\Program Files\PostgreSQL\<VERSION>\bin. Commands like heroku pg:psql depend on the PATH and do not work if the PATH is incorrect.
If you haven't already installed Postgres locally, do so. (This is a good idea anyway as you should be developing locally and you'll probably need a database.)
Then make sure to add its bin/ directory to your PATH environment variable.
The Nodemon error
The second issue is because you are trying to use nodemon in production. Heroku strips development dependencies out of Node.js applications after building them, which normally makes sense. Nodemon is a development tool, not something that should be used for production hosting.
Depending on the contents of your package.json, this might be as simple as changing your start script from nodemon some-script.js to node some-script.js. Alternatively, you can add a Procfile with the command you actually want to run on Heroku:
web: node some-script.js
See also Need help deploying a RESTful API created with MongoDB Atlas and Express

troubles deploying with diigtal ocean node sequelize

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

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'
}

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.

Meteor react on Gcloud

I am trying to deploy my Meteor React app on Google's cloud but when I try deploying it, I get the error saying that MONGO_URL needs to be specified. I build my meteor app and cd to my bundle folder where I do gcloud app deploy. Here is my package.json
{
"private": true,
"scripts": {
"start": "node main.js",
"install": "(cd programs/server && npm install)"
},
"engines": {
"node": "6.6.0"
}
}
How can I find out my meteor mongo username and password. Running regular meteor did not ask me for my username and password. And here is my app.yaml
runtime: nodejs
env: flex
threadsafe: true
automatic_scaling:
max_num_instances: 1
env_variables:
MONGO_URL: 'mongodb://[user]:[pass]#[host]:[port]/[db]'
ROOT_URL: 'https://...'
METEOR_SETTINGS: '{}'
I don't know what to put for MONGO_URL and ROOT_URL if I am deploying on gcloud. Also I have settings file for my project. Should it go under METER_SETTINGS in app.yaml? I apologize for asking too many question but this is my first time dealing with gcloud :)
This question is a little old, but it's still getting some views from Google so let's answer by parts, first you need to understand how Meteor interacts with MongoDB in development and production. When you're coding your app, just executing meteor run does all the magic, because Meteor deploys an internal MongoDB. This is not recommended for real production usage and won't work well under any container based architecture (such as Docker, Google App Engine, Heroku etc.).
Given that, you'll need to deploy a separate instance in Google Compute Engine based on MongoDB. Google has them ready to launch in the Google Cloud Launcher, just search for "MongoDB".
I recommend the Bitnami's one, which is easier to configure if you're just beginning.
Google will create an instance automatically and you'll be given a root username and password, alongside a public IP address to connect to the instance.
Run the command below to access Mongo from a terminal:
# Use this template for the command
mongo "mongodb://root:PASSWORD#IP_ADDRESS/" --authenticationDatabase admin
# For example, with sample values
mongo "mongodb://root:8sdjkfh8876#127.0.0.1/" --authenticationDatabase admin
Now, create a new user for Meteor to connect on your newly created database. Never give it the root credentials, it won't work and it's not safe. For example, naming the database as myapp.
use myapp;
db.createUser({
user: "meteor_app",
pwd: "A_SECURE_PASSWORD",
roles: [ "readWrite", "dbAdmin" ]
})
Now, you exit this connection and test your new user.
mongo "mongodb://meteor_app:A_SECURE_PASSWORD#IP_ADDRESS/myapp"
If everything is OK, you now have your MONGO_URL.
# Put this in the app.yaml file, env variables sections
MONGO_URL: "mongodb://meteor_app:A_SECURE_PASSWORD#IP_ADDRESS/myapp"

Resources