@@ -10,35 +10,38 @@ Each blockchain is configured in `config.yaml`.
1010
1111## Build & Test
1212
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.
1516
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.
1621```
1722DATABASE_URL="sqlite:fortuna.db?mode=rwc"
1823```
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.
1930
20- Install sqlx for cargo with :
31+ Install ` sqlx ` :
2132``` bash
2233cargo install sqlx
2334```
2435
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:
2737``` bash
28- cargo sqlx migrate run # automatically picks up the .env file
38+ cargo sqlx migrate run
2939```
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:
3740
41+ To restore the database to a fresh state (drop, recreate, apply migrations):
3842``` bash
39- cargo sqlx prepare
43+ cargo sqlx database reset
4044```
41- Please add the changed files in the ` .sqlx ` folder to your git commit.
4245
4346## Command-Line Interface
4447
@@ -124,7 +127,7 @@ To start an instance of the webserver for local testing, you first need to perfo
1241271 . Run ` cargo run -- setup-provider ` to register a randomness provider for this service. This command
125128 will update the on-chain contracts such that the configured provider key is a randomness provider,
126129 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.
128131Once you've completed the setup, simply run the following command to start the service:
129132
130133``` bash
0 commit comments