Create Postgres database for development in Docker for Prisma

I’m taking these notes so I don’t forget these lines about how to create my testdb and test user for my local development environment.

Also I’m giving my test user CREATEDB permission so Prisma can create shadow databases when migrations are run in development.

docker exec -it postgresdb psql -U postgres
postgres=# create database testdb;
postgres=# create user test with encrypted password 'test';
postgres=# grant all privileges on database testdb to test;
postgres=# \l
                               Listado de base de datos
  Nombre   |  Dueño   | Codificación |  Collate   |   Ctype    |      Privilegios      
-----------+----------+--------------+------------+------------+-----------------------
 postgres  | postgres | UTF8         | es_ES.utf8 | es_ES.utf8 | 
 template0 | postgres | UTF8         | es_ES.utf8 | es_ES.utf8 | =c/postgres          +
           |          |              |            |            | postgres=CTc/postgres
 template1 | postgres | UTF8         | es_ES.utf8 | es_ES.utf8 | =c/postgres          +
           |          |              |            |            | postgres=CTc/postgres
 testdb    | postgres | UTF8         | es_ES.utf8 | es_ES.utf8 | =Tc/postgres         +
           |          |              |            |            | postgres=CTc/postgres+
           |          |              |            |            | test=CTc/postgres
(4 filas)

postgres=#ALTER USER test CREATEDB;
postgres=# \q

Cheers