@@ -10,35 +10,38 @@ Each blockchain is configured in `config.yaml`.
10
10
11
11
## Build & Test
12
12
13
- We use sqlx query macros to check the SQL queries at compile time. This requires
14
- a database to be available at build time. Create a ` .env ` file in the root of the project with the following content:
13
+ Fortuna uses Cargo for building and dependency management.
14
+ Simply run ` cargo build ` and ` cargo test ` to build and test the project.
15
+ To run Fortuna locally, see the [ Local Development] ( #local-development ) section below.
15
16
17
+ ### Connect a database
18
+ Fortuna stores request history in a SQL database and serves it from its explorer API.
19
+ Any SQLite or Postgres database is supported. The database connection is sourced from the ` DATABASE_URL ` env var.
20
+ Create a ` .env ` file in the root of the project with a DB connection string.
16
21
```
17
22
DATABASE_URL="sqlite:fortuna.db?mode=rwc"
18
23
```
24
+ If not provided, Fortuna will create and use a SQLite file-based database at ` ./fortuna.db ` , as in the example above.
25
+
26
+ ### Database migrations
27
+ Fortuna will automatically apply the schema migrations in the ` ./migrations ` directory when connecting to the database.
28
+ To manually administer the migrations, use the ` sqlx ` tool for cargo. The tool automatically uses the
29
+ database connection in the ` .env ` file.
19
30
20
- Install sqlx for cargo with :
31
+ Install ` sqlx ` :
21
32
``` bash
22
33
cargo install sqlx
23
34
```
24
35
25
- Next, you need to create the database and apply the schema migrations. You can do this by running:
26
-
36
+ To create the database if needed and apply the migrations:
27
37
``` bash
28
- cargo sqlx migrate run # automatically picks up the .env file
38
+ cargo sqlx migrate run
29
39
```
30
- This will create a SQLite database file called ` fortuna.db ` in the root of the project and apply the schema migrations to it.
31
- This will allow ` cargo check ` to check the queries against the existing database.
32
-
33
- Fortuna uses Cargo for building and dependency management.
34
- Simply run ` cargo build ` and ` cargo test ` to build and test the project.
35
-
36
- If you have changed any queries in the code, you need to update the .sqlx folder with the new queries:
37
40
41
+ To restore the database to a fresh state (drop, recreate, apply migrations):
38
42
``` bash
39
- cargo sqlx prepare
43
+ cargo sqlx database reset
40
44
```
41
- Please add the changed files in the ` .sqlx ` folder to your git commit.
42
45
43
46
## Command-Line Interface
44
47
@@ -124,7 +127,7 @@ To start an instance of the webserver for local testing, you first need to perfo
124
127
1 . Run ` cargo run -- setup-provider ` to register a randomness provider for this service. This command
125
128
will update the on-chain contracts such that the configured provider key is a randomness provider,
126
129
and its on-chain configuration matches ` config.yaml ` .
127
-
130
+ 1 . Review the [ Connect a database ] ( #connect-a-database ) section above. The default configuration will create a file-based DB.
128
131
Once you've completed the setup, simply run the following command to start the service:
129
132
130
133
``` bash
0 commit comments