---
# System prepended metadata

title: Preporation for lab 8

---

# Preporation for lab 8

## 1 Create db faker

Study presented python script and be reardy to use it during next lab.

### Short manual

Before the lab you should familiar to make some fake data within a shout time. One of the way is to use the following `create_faker.py` python script:
```python=
# create db
# psql -d template1
import psycopg2
from faker import Faker
# https://stackabuse.com/working-with-postgresql-in-python/
con = psycopg2.connect(database="dbcourse", user="user",
                       password="pwd", host="127.0.0.1", port="5000")

print("Database opened successfully")
cur = con.cursor()
cur.execute('''CREATE TABLE CUSTOMER
       (ID INT PRIMARY KEY     NOT NULL,
       Name           TEXT    NOT NULL,
       Address            TEXT     NOT NULL,
       review        TEXT);''')
print("Table created successfully")
fake = Faker()
for i in range(1000):
    print(i)
    cur.execute("INSERT INTO CUSTOMER (ID,Name,Address,review) VALUES ('"+ str(i)+"','"+fake.name()+"','"+fake.address()+"','"+fake.text()+"')")
    con.commit()
```

This script requres`psycopg2-binary` and `faker` to be installed:
```shell
pip install psycopg2-binary faker
```




The presented `create_faker.py` python script works well with any istalled postgreSQL. The presented connect configurations were done for the following `docker-compose.yml` configuration.

```docker-compose
version: '3'
services:

  postgresql:
    container_name: postgresql
    image: postgres
    environment:
       - POSTGRES_USER=user
       - POSTGRES_PASSWORD=pwd
       - POSTGRES_DB=dbcourse
    restart: always
    ports:
      - 5000:5432
    networks:
      - local_net
    volumes:
      - $PWD/pgdata:/var/lib/postgresql/data

  adminer:
    container_name: adminer
    image: adminer
    restart: always
    ports:
      - 8000:8080
    networks:
      - local_net

networks:
  local_net: {}
```


## 2 Import DVD rental database

Using the DVD rental database (available on Moodle), import in on your local database following the guide provided.

https://www.postgresqltutorial.com/postgresql-getting-started/load-postgresql-sample-database/