Skip to content

kylewehrung/chit-chat

Repository files navigation

Project Setup Guide

Introduction

In case anyone reads this, this guide is mainly for my reference during development.

Frontend

Starting the Frontend

In the root project directory, you can run:

npm install --prefix client

Next, you can change to the 'client' directory and run:

npm start

To kill all PID's in client directory run:

sudo lsof -ti:4000 | xargs sudo kill -9

Backend

Installing Dependencies

From the chit-chat project directory run:

pip install -r requirements.txt

Managing Dependencies

Check if dependencies are outdated:

pip list --outdated

Upgrade dependencies with:

pip install --upgrade package-name

Uninstall dependencies with:

pip uninstall package-name

PostgreSQL Setup

Change to the server directory: Check if the PostgreSQL server is online by running:

sudo service postgresql status

If it's offline, start the server with:

sudo service postgresql start

Environment Variables

Set up/create environment variables, largely for endpoints:

Set environment variables to development:

source set_env_vars.sh development

Set environment variables to production:

source set_env_vars.sh production

Database Connection

Check PostgreSQL database connection:

Change into the 'server directory' then

python test_db_connection.py

Test password hashing:

 python test_password_hashing.py

Switching between production and development workflow:

Development environment:

The alembic directory and alembic.ini file should be in the server directory. In the env.py file, change the import from import server.models as models to import models as models. Next generate alembic.ini file if needed using script, make sure this alembic.ini is in .gitignore. Run migratiions and check if they run correctly using psql. May have to manually do it using psql commands.

Production environment:

For production development, the alembic directory and alembic.ini file should be in the root project directory. Alembic.ini can be generated using script, does not need to be hidden in .gitignore as no sensitive information is in it. Change import in env.py file to import server.models as models. Run migrations using heroku commands, doing it manually if needed as well.

Generate Alembic.ini file to run migrations

Navigate to 'server' directory:

For local database migrations:

 python localdb_generate_alembic_ini.py

For heroku database migrations:

 python heroku_generate_alembic_ini.py

Run migrations:

Locally:

alembic revision --autogenerate -m "Your migration message here"
alembic upgrade head

With Heroku:

heroku run alembic upgrade head --app chit-chat-backend

Check Heroku database:

heroku pg:psql --app chit-chat-backend

Checking database list and roles:

Enter postgres shell:

```bash
sudo -u postgres psql
```

Check database and roles:

```bash
\du
\l
```

Check users table:

```bash
SELECT table_name FROM information_schema.tables WHERE table_name = 'users';
```

List tables:

```bash
psql -U db-username -d db-name -h localhost -W
```

Enter password for db-username, then:

    ```bash
    \dt
    ```

Running the Backend Server locally

Spin up the backend server in the 'chit-chat' directory with:

gunicorn -w 4 -b 0.0.0.0:5555 server.app:app

If it won't spin up, see if it's already running with:

pgrep gunicorn

Kill these PIDs with:

pkill -9 gunicorn

Then re-run the gunicorn command:

gunicorn -w 4 -b 0.0.0.0:5555 server.app:app

Heroku commands:

Check heroku logs:

 heroku logs --tail --app chit-chat-backend

Scale/run dyno:

heroku ps:scale web=1 --app chit-chat-backend

Stop dyno

heroku ps:scale web=0 --app chit-chat-backend

Restart dyno:

heroku ps:restart --app chit-chat-backend

Setting up awscli version 2 to be used over version 1:

export PATH="/usr/local/bin:$HOME/Development/code/bag-talk/chit-chat:$PATH"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published