|
9 | 9 |
|
10 | 10 | ## Instructions |
11 | 11 |
|
| 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 | + |
12 | 17 | 1. Create database user |
13 | 18 |
|
14 | 19 | ```shell |
|
19 | 24 |
|
20 | 25 | 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. |
21 | 26 |
|
| 27 | + An alternative using SQL: |
| 28 | + ```sql |
| 29 | + CREATE USER test_user WITH PASSWORD 'testing'; |
| 30 | + ``` |
| 31 | + |
22 | 32 | 2. Create database |
23 | 33 |
|
24 | 34 | ```shell |
25 | 35 | createdb -O test_user testing_db |
26 | 36 | ``` |
27 | 37 |
|
| 38 | + An alternative using SQL: |
| 39 | + ```sql |
| 40 | + CREATE DATABASE testing_db OWNER test_user; |
| 41 | + ``` |
| 42 | + |
28 | 43 | 3. Initialize database |
29 | 44 |
|
30 | 45 | ```shell |
|
33 | 48 |
|
34 | 49 | This step can be repeated and clears the database as it drops and recreates the schema `testing` which is used within the database. |
35 | 50 |
|
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: |
37 | 60 |
|
38 | 61 | ```ini |
39 | 62 | SERVER_ADDR=127.0.0.1:8080 |
|
45 | 68 | PG.POOL.MAX_SIZE=16 |
46 | 69 | ``` |
47 | 70 |
|
48 | | -5. Run the server: |
| 71 | +6. Run the server: |
49 | 72 |
|
50 | 73 | ```shell |
51 | 74 | cargo run |
52 | 75 | ``` |
53 | 76 |
|
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: |
55 | 78 |
|
56 | 79 | ```shell |
57 | 80 | 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 | 83 | **...or using curl...** |
61 | 84 |
|
62 | 85 | ```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 |
64 | 87 | ``` |
65 | 88 |
|
66 | 89 | A unique constraint exists for username, so sending this request twice will return an internal server error (HTTP 500). |
0 commit comments