Skip to content

Database Cheatsheet

Muhammad Sameer Amin edited this page Sep 4, 2024 · 2 revisions

As we are using PostgreSQL in our project this wiki contains instructions for creating and maintaining databases and debugging issues.

Database setup (PostgreSQL)

  1. Install PostgreSQL:

    • On macOS:

      brew install postgresql@16
      
    • On Windows: Download and install from the official website.

  2. Start the PostgreSQL service:

    • On macOS:

      brew services start postgresql@16
      
    • On Windows: Start the PostgreSQL service from the Services management console.

  3. Create a new database user:

    createuser -s -P postgres
    

    When prompted, enter the following:

    • Enter password for new role:
  4. Create a new database:

    createdb -O postgres meal_mentor
    
  5. Set the DATABASE_URL environment variable:

    export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/meal_mentor"
    
  6. Run the migrations:

    alembic upgrade head
    

Accessing DB via terminal (MacOS)

  1. Start the PostgreSQL service:

    brew services start postgresql@16
    
  2. Connect to the database:

    psql -d meal_mentor -U postgres
    
  3. View tables:

    \dt
    
  4. Exit:

    \q
    
  5. Change the database user password:

    alter user postgres with password 'postgres';
    

Clone this wiki locally