Skip to content

Commit a7a7f08

Browse files
authored
Update databases/postgres/README.md (actix#554)
* Update databases/postgres/README.md Add sudo -u postgres to relevant commands Add privilege granting step for new user Add -i flag to curl command to show HTTP response code * Update databases/postgres/README.md Add more options for accomplishing tasks Add note regarding
1 parent b459225 commit a7a7f08

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

databases/postgres/README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
## Instructions
1111

12+
### NOTE:
13+
14+
You may need to ensure that you are running the commands with the correct SQL user.
15+
On many Linux distributions you may prefix the shell commands with `sudo -u postgres`
16+
1217
1. Create database user
1318

1419
```shell
@@ -19,12 +24,22 @@
1924

2025
This step is **optional** and you can also use an existing database user for that. Just make sure to replace `test_user` by the database user of your choice in the following steps and change the `.env` file containing the configuration accordingly.
2126

27+
An alternative using SQL:
28+
```sql
29+
CREATE USER test_user WITH PASSWORD 'testing';
30+
```
31+
2232
2. Create database
2333

2434
```shell
2535
createdb -O test_user testing_db
2636
```
2737

38+
An alternative using SQL:
39+
```sql
40+
CREATE DATABASE testing_db OWNER test_user;
41+
```
42+
2843
3. Initialize database
2944

3045
```shell
@@ -33,7 +48,15 @@
3348

3449
This step can be repeated and clears the database as it drops and recreates the schema `testing` which is used within the database.
3550

36-
4. Create `.env` file:
51+
4. Grant privileges to new user
52+
53+
```sql
54+
GRANT ALL PRIVILEGES ON SCHEMA testing TO test_user;
55+
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA testing TO test_user;
56+
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA testing TO test_user;
57+
```
58+
59+
5. Create `.env` file:
3760

3861
```ini
3962
SERVER_ADDR=127.0.0.1:8080
@@ -45,13 +68,13 @@
4568
PG.POOL.MAX_SIZE=16
4669
```
4770

48-
5. Run the server:
71+
6. Run the server:
4972

5073
```shell
5174
cargo run
5275
```
5376

54-
6. Using a different terminal send an HTTP POST request to the running server:
77+
7. Using a different terminal send an HTTP POST request to the running server:
5578

5679
```shell
5780
echo '{"email": "ferris@thecrab.com", "first_name": "ferris", "last_name": "crab", "username": "ferreal"}' | http -f --json --print h POST http://127.0.0.1:8080/users
@@ -60,7 +83,7 @@
6083
**...or using curl...**
6184

6285
```shell
63-
curl -d '{"email": "ferris@thecrab.com", "first_name": "ferris", "last_name": "crab", "username": "ferreal"}' -H 'Content-Type: application/json' http://127.0.0.1:8080/users
86+
curl -i -d '{"email": "ferris@thecrab.com", "first_name": "ferris", "last_name": "crab", "username": "ferreal"}' -H 'Content-Type: application/json' http://127.0.0.1:8080/users
6487
```
6588

6689
A unique constraint exists for username, so sending this request twice will return an internal server error (HTTP 500).

0 commit comments

Comments
 (0)