- Installation
- Setup Prettier
- Setup local Postgres database
- How to run the app
- Updating table schemas
- Linting
- Testing
To get started, follow the steps below:
git clone https://github.com/BB6-SE/se-2144-final-projectIn the root folder, run
npm run install-all- Install Prettier Extension for vscode
- Go to
File > Preferences > Settings - Search for
Formatin the search bar - Select Prettier in the
Default Formatterdropdown - Enable
Format on Save
Add a .env file in the backend folder with the following format without the square brackets:
DATABASE_URL =
"postgres://postgres:[YOUR_POSTGRES_PASSWORD]@localhost:5432/notetube_dev?sslmode=disable";In the root folder, run
npm run migrate-up- Open pgAdmin
- Make a new database named
notetube_dev - Open the query tool in the notetube_dev database
- Paste and execute
backend/database.sqlcontents except theCREATE DATABASEquery
- Open terminal
- Access your postgres db
psql -U postgresif you encounter this error: psql: command not found,
follow this tutorial
- Input your password
Password for user postgres:
- Paste and run
backend/database.sqlcontents into prompt
In the root folder
npm run appto run
frontendonlynpm run frontendto run
backendonlynpm run backend
In frontend & backend folders
to run
frontendonlycd frontend npm run devto run
backendonlycd backend npm run dev
- Navigate to the
backendfolder
cd backend- Generate a new migration file
npx dbmate new [table_name]- In
db/migrations, open your new migration file then modify it with this format:
dbmate generates migration files in this format ->
YYYYMMDDXXXX_name.sql
// -- migrate:up
// Write your SQL query to create the new table here. For example:
CREATE TABLE [table_name] (
id SERIAL PRIMARY KEY,
column1 VARCHAR(255) NOT NULL,
column2 INT NOT NULL,
...
);
// -- migrate:down
// Write your SQL query to drop the table here. For example:
DROP TABLE IF EXISTS [table_name];- Migrate the table schema to your local database
npx dbmate up-
Apply and save your changes to any of the migration files under
db/migrationsusing your IDE -
Navigate to the
backendfolder
cd backend- Roll back the latest migration to its initial state
If you want to rollback older migrations, you will need to run
npx dbmate downn times depending on its order
npx dbmate down- Migrate the updated table schema to your local database
npx dbmate upIf this is the order of migrations:
users table: 1st migration
decks table: 2nd migration
cards table: 3rd migration (latest)
- Edit the
cardsschema file contents -20241119140621_cards.sql - Roll back the migrations only once
npx dbmate down
# Output:
# Rolling back: 20241119140621_cards.sql
# Rolled back: 20241119140621_cards.sql
# Writing: ./db/schema.sql- Migrate the updated table schema to your local database
npx dbmate up
# Output:
# Applying: 20241119140621_cards.sql
# Applied: 20241119140621_cards.sql
# Writing: ./db/schema.sql-
Edit the
usersmigration file. -
Roll back the migrations three times
npx dbmate down # rolls back the cards first
# Output:
# Rolling back: 20241119140621_cards.sql
# Rolled back: 20241119140621_cards.sql
# Writing: ./db/schema.sql
npx dbmate down # then rolls back the decks
# Output:
# Rolling back: 20241119140539_decks.sql
# Rolled back: 20241119140539_decks.sql
# Writing: ./db/schema.sql
npx dbmate down # finally rolls back the users
# Output:
# Rolling back: 20241119140502_users.sql
# Rolled back: 20241119140502_users.sql
# Writing: ./db/schema.sql- Migrate the updated table schema to your local database
npx dbmate up
# Output:
# Applying: 20241119140621_cards.sql
# Applied: 20241119140621_cards.sql
# Writing: ./db/schema.sqlLint the frontend
cd frontend
npm run lintLint the backend
cd backend
npm run lintLint the frontend
npm run test-frontendor
cd frontend
npm run testLint the backend
npm run test-backendor
cd backend
npm run testTo test specific file(s), simply add a name that the test file(s) name matches or contains
npm run test-frontend [nameHere]or
npm run test-backend [nameHere]