1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

Remove shell script and add more verbose instructions to README

This commit is contained in:
Michael P. Jung 2020-01-16 19:21:17 +01:00
parent b94ab2165f
commit ac7931fd27
3 changed files with 34 additions and 17 deletions

View File

@ -9,13 +9,36 @@
## Instructions
1. Set up the testing database by running the included script:
1. Create database user
```shell
./sql/create_db.sh
createuser -P test_user
```
2. Create `.env` file:
Enter a password of your choice. The following instructions assume you
used `testing` as password.
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.
2. Create database
```shell
createdb -O test_user testing_db
```
3. Initialize database
```shell
psql -f sql/schema.sql testing_db
```
This step can be repeated and clears the database as it drops and
recreates the schema `testing` which is used within the database.
4. Create `.env` file:
```ini
SERVER_ADDR=127.0.0.1:8080
@ -27,17 +50,23 @@
PG.POOL.MAX_SIZE=16
```
3. Run the server:
5. Run the server:
```shell
cargo run
```
4. Using a different terminal send a HTTP POST request to the running server:
6. Using a different terminal send an HTTP POST request to the running server:
```shell
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
```
**...or using curl...**
```shell
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
```
A unique constraint exists for username, so sending this request twice
will return an internal server error (HTTP 500).

View File

@ -1,3 +0,0 @@
#!/bin/bash
psql -U postgres -h 127.0.0.1 -f setup_db_and_user.sql

View File

@ -1,15 +1,6 @@
DROP DATABASE IF EXISTS testing_db;
CREATE USER test_user WITH PASSWORD 'testing';
CREATE DATABASE testing_db OWNER test_user;
\connect testing_db;
DROP SCHEMA IF EXISTS testing CASCADE;
CREATE SCHEMA testing;
CREATE TABLE testing.users (
id BIGSERIAL PRIMARY KEY,
email VARCHAR(200) NOT NULL,