An overhaul of Colt Steele's YelpCamp project to use Postgres instead of MongoDB. A great demonstration of the contrast between relational and non-relational databases and their implementation in CRUD apps.
Deployed Website: https://yelpcamp-0qtg.onrender.com
- "sequelize": "^6.31.1" Object-Relational Mapper to interact with the database (replacing mongoose)
- "bcrypt": "^5.1.0" To encrypt the registered user's password before storing it in the database (replacing passport-local-mongoose)
- "pg": "^8.10.0", To interact with PostgreSQL databases using raw SQL queries.
- "connect-pg-simple": "^8.0.0" To store the Session data in the database (replacing connect-mongo)
- "mongoose": "^7.0.1"
- "passport-local-mongoose": "^8.0.0",
- "connect-mongo": "^5.0.0",
- "express-mongo-sanitize": "^2.2.0"
- "./passportConfig.js" (Passport.js configuration file).
- "./database/database.js" (Sequilize configuration file).
- "./database/db.js" (pg configuration file).
- "./models/models.js" (Postgres Models file).
- "./public/scripts/bootstrap.bundle.min.js, bootstrap.bundle.min.js.map, bootstrap.min.js, bootstrap.min.js.map" (bootstrap local files CDN is not needed).
- "./public/stylesheets/bootstrap.min.css, bootstrap.min.css" (bootstrap local files CDN is not needed).
- "./models/campground.js, user.js, review.js" (MongoDB schemas no longer needed).
- "./public/stylesheets/app.css".
- Changed the name of "./public/javascripts" to "./public/scripts".
- pgadmin (GUI to interact with Postgres Databases) https://www.pgadmin.org/
-Local:-
-
Install Postgres https://www.postgresql.org/download/
-
Start the server
sudo systemctl start postgresql
or
sudo pg_ctlcluster 15 main start
-
Connect to the server using default credintals
sudo -u postgres psql -p 5432
-
Create a new user and grant it the required priveleges to create a database
CREATE USER newser WITH PASSWORD 'newpass' CREATEDB; -
Register your server and connect to the newly created user using pgadmin

-Or we could set up a cloud database using render and connect to it in the same manner:-
After connecting to the database a couple extensions have to be installed in order to provide spatial database capabilities, including support for geographic data types. We use the Query Tool in pgadmin to install them.
- postgis
- postgis-topology
We set up our database tables and the necessary relations between them using the following SQL queries and pgadmin's Query Tool.
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
"createdAt" TIMESTAMP,
"updatedAt" TIMESTAMP
);
CREATE TABLE campgrounds (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
price FLOAT NOT NULL,
images JSONB[] NOT NULL,
geometry GEOGRAPHY(POINT) NOT NULL,
description VARCHAR(255) NOT NULL,
location VARCHAR(255) NOT NULL,
authorid INTEGER NOT NULL REFERENCES users (id),
"createdAt" TIMESTAMP,
"updatedAt" TIMESTAMP
);
CREATE TABLE reviews (
id SERIAL PRIMARY KEY,
body VARCHAR(255) NOT NULL,
rating INTEGER NOT NULL,
"createdAt" TIMESTAMP,
"updatedAt" TIMESTAMP,
campgroundid INTEGER NOT NULL REFERENCES campgrounds (id),
authorid INTEGER NOT NULL REFERENCES users (id)
);
*Now we are good to go. Feel free to ask any questions.







