albertocorrias / sudoku

0 stars 0 forks source link

Dealing with PostgreSQL #1

Closed albertocorrias closed 2 years ago

albertocorrias commented 2 years ago

Steps done after checking out the repository

Installation

Installed PostgreSQL

sudo apt install postgresql postgresql-contrib

Then, I installed the following needed Python package

sudo apt-get install python3-psycopg2

Then I logged in as postgres user with (CTRL-D to quit)

sudo -u postgres -i

Then,to be able to type SQL commands

psql

which will get the postgres=# command prompt (\q to quit) . Here I did CREATE DATABASE sudoku; then CREATE USER sudoku_user WITH PASSWORD '***********************'; and GRANT ALL PRIVILEGES ON DATABASE sudoku TO sudoku_user;

Having Django and tests to run

After that, I quit the postgres=# command prompt (\q), then CTRL+D to quit the postgre user and I run the Django migrations

python3 manage.py migrate

Then, finally

python3 manage.py runserver

worked.

To be able to run the tests, additional steps was required in order to allow the test framework to create the test databases for testing purposes. The additional steps are.

  1. Re-login potgres with sudo -u postgres -i and psql
  2. ALTER USER sudoku_user CREATEDB;

DUMP and restore

Login postgres with (CTRL-D to quit)

sudo -u postgres -i

Dump with

pg_dump sudoku > sudoku.dump

The dump file is located at /var/lib/postgresql

albertocorrias commented 2 years ago

This is a wiki, not an issue.