You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/src/content/docs/contributing/labrinth.md
+20-39Lines changed: 20 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,59 +3,41 @@ title: Labrinth (API)
3
3
description: Guide for contributing to Modrinth's backend
4
4
---
5
5
6
-
This project is part of our [monorepo](https://github.com/modrinth/code). You can find it in the `apps/labrinth` directory.
6
+
This project is part of our [monorepo](https://github.com/modrinth/code). You can find it in the `apps/labrinth` directory. The instructions below assume that you have switched your working directory to the `apps/labrinth` subdirectory.
7
7
8
8
[labrinth] is the Rust-based backend serving Modrinth's API with the help of the [Actix](https://actix.rs) framework. To get started with a labrinth instance, install docker, docker-compose (which comes with Docker), and [Rust]. The initial startup can be done simply with the command `docker-compose up`, or with `docker compose up` (Compose V2 and later). That will deploy a PostgreSQL database on port 5432 and a MeiliSearch instance on port 7700. To run the API itself, you'll need to use the `cargo run` command, this will deploy the API on port 8000.
9
9
10
10
To get a basic configuration, copy the `.env.local` file to `.env`. Now, you'll have to install the sqlx CLI, which can be done with cargo:
From there, you can create the database and perform all database migrations with one simple command:
16
+
From there, you can create the database and set up its schema with one simple command:
17
17
18
-
```bash
19
-
sqlx database setup
18
+
```sh
19
+
cargo sqlx database setup
20
20
```
21
21
22
-
To enable labrinth to create a project, you need to add two things.
22
+
To enable labrinth to create projects and serve useful metadata to the frontend build scripts, you'll need to seed the database with several key entities:
23
23
24
-
1. An entry in the `loaders` table.
25
-
2. An entry in the `loaders_project_types` table.
24
+
1. Categories, in the `categories` table.
25
+
2. Loaders and their fields, in the `loaders`, `loader_fields`, `loader_field_enums`, `loader_field_enum_values`, and `loader_fields_loaders` tables.
26
+
3. Project types and their allowed loaders and games, in the `project_types`, `loaders_project_types`, and `loaders_project_types_games` tables.
27
+
4. Optionally, to moderate projects from the frontend, an admin user, in the `users` table.
26
28
27
-
A minimal setup can be done from the command line with [psql](https://www.postgresql.org/docs/current/app-psql.html):
29
+
The most convenient way to do this seeding is with the [psql](https://www.postgresql.org/docs/current/app-psql.html) command line tool and the pre-existing seed data fixture. This fixture was generated by dumping the official staging environment database at a specific point in time, and defines an admin user with email `admin@modrinth.invalid` and password `admin`:
28
30
29
-
```bash
30
-
psql --host=localhost --port=5432 -U <username, default is labrinth> -W
The default password for the database is `labrinth`. Once you've connected, run
34
-
35
-
```sql
36
-
INSERT INTO loaders VALUES (0, 'placeholder_loader');
37
-
INSERT INTO loaders_project_types VALUES (0, 1); -- modloader id, supported type id
38
-
INSERT INTO categories VALUES (0, 'placeholder_category', 1); -- category id, category, project type id
39
-
```
40
-
41
-
This will initialize your database with a modloader called 'placeholder_loader', with id 0, and marked as supporting mods only. It will also create a category called 'placeholder_category' that is marked as supporting mods only
42
-
If you would like 'placeholder_loader' to be marked as supporting modpacks too, run
43
-
44
-
```sql
45
-
INSERT INTO loaders_project_types VALUES (0, 2); -- modloader id, supported type id
46
-
```
47
-
48
-
If you would like 'placeholder_category' to be marked as supporting modpacks too, run
49
-
50
-
```sql
51
-
INSERT INTO categories VALUES (0, 'placeholder_category', 2); -- modloader id, supported type id
52
-
```
53
-
54
-
You can find more example SQL statements for seeding the database in the `apps/labrinth/tests/files/dummy_data.sql` file.
36
+
You can find more example SQL statements for seeding the database in the `tests/files/dummy_data.sql` file.
55
37
56
38
The majority of configuration is done at runtime using [dotenvy](https://crates.io/crates/dotenvy) and the `.env` file. Each of the variables and what they do can be found in the dropdown below. Additionally, there are three command line options that can be used to specify to MeiliSearch what you want to do.
57
39
58
-
During development, you might notice that changes made directly to entities in the PostgreSQL database do not seem to take effect. This is often because the Redis cache still holds outdated data. To ensure your updates are reflected, clear the cache by e.g. running `redis-cli FLUSHALL`, which will force Labrinth to fetch the latest data from the database the next time it is needed.
40
+
During development, you might notice that changes made directly to entities in the PostgreSQL database do not seem to take effect. This is often because the Redis cache still holds outdated data. To ensure your updates are reflected, clear the cache by e.g. running `redis-cli FLUSHALL`, which will force labrinth to fetch the latest data from the database the next time it is needed.
59
41
60
42
<details>
61
43
<summary>.env variables & command line options</summary>
@@ -109,14 +91,13 @@ The OAuth configuration options are fairly self-explanatory. For help setting up
109
91
110
92
If you're prepared to contribute by submitting a pull request, ensure you have met the following criteria:
111
93
112
-
-`cargo fmt` has been run.
113
-
-`cargo clippy` has been run.
114
-
-`cargo check` has been run.
94
+
-`cargo fmt --all` has been run.
95
+
-`cargo clippy --all-targets` has been run.
115
96
-`cargo sqlx prepare` has been run.
116
97
117
98
> Note: If you encounter issues with `sqlx` saying 'no queries found' after running `cargo sqlx prepare`, you may need to ensure the installed version of `sqlx-cli` matches the current version of `sqlx` used [in labrinth](https://github.com/modrinth/labrinth/blob/master/Cargo.toml).
0 commit comments