Skip to content

BB6-SE/se-2144-final-project

Repository files navigation

SE 2144 FINAL PROJECT

Table of Contents

Resources

Installation

To get started, follow the steps below:

Clone the repository

git clone https://github.com/BB6-SE/se-2144-final-project

Install all dependencies

In the root folder, run

npm run install-all

Setup Prettier for code formatting

  1. Install Prettier Extension for vscode
  2. Go to File > Preferences > Settings
  3. Search for Format in the search bar
  4. Select Prettier in the Default Formatter dropdown
  5. Enable Format on Save

Set up local Postgres database

Add database connection link

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";

Using dbmate

In the root folder, run

npm run migrate-up

Using pgAdmin

  1. Open pgAdmin
  2. Make a new database named notetube_dev
  3. Open the query tool in the notetube_dev database
  4. Paste and execute backend/database.sql contents except the CREATE DATABASE query

Using terminal

  1. Open terminal
  2. Access your postgres db
psql -U postgres

if you encounter this error: psql: command not found, follow this tutorial

  1. Input your password
Password for user postgres:
  1. Paste and run backend/database.sql contents into prompt

How to run the app

In the root folder

npm run app

to run frontend only

npm run frontend

to run backend only

npm run backend

In frontend & backend folders

to run frontend only

cd frontend
npm run dev

to run backend only

cd backend
npm run dev

Updating table schemas

Adding a table schema

  1. Navigate to the backend folder
cd backend
  1. Generate a new migration file
npx dbmate new [table_name]
  1. 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];
  1. Migrate the table schema to your local database
npx dbmate up

Updating a table schema

  1. Apply and save your changes to any of the migration files under db/migrations using your IDE

  2. Navigate to the backend folder

cd backend
  1. Roll back the latest migration to its initial state

If you want to rollback older migrations, you will need to run npx dbmate down n times depending on its order

npx dbmate down
  1. Migrate the updated table schema to your local database
npx dbmate up

Example

If this is the order of migrations:

users table: 1st migration
decks table: 2nd migration
cards table: 3rd migration (latest)

Updating the cards table schema (Latest Migration):

  1. Edit the cards schema file contents - 20241119140621_cards.sql
  2. Roll back the migrations only once
npx dbmate down

# Output:
# Rolling back: 20241119140621_cards.sql
# Rolled back: 20241119140621_cards.sql
# Writing: ./db/schema.sql
  1. 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

Modifying the users table schema (1st Migration):

  1. Edit the users migration file.

  2. 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
  1. 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

Linting

Lint the frontend

cd frontend
npm run lint

Lint the backend

cd backend
npm run lint

Testing

Lint the frontend

npm run test-frontend

or

cd frontend
npm run test

Lint the backend

npm run test-backend

or

cd backend
npm run test

To 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]

About

A web app that generates related videos, flashcards, and a summary from your notes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7