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: docs/01-get-started/01-creating-endpoints.md
+1-2Lines changed: 1 addition & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,6 @@ serverpod create magic_recipe
20
20
21
21
:::tip
22
22
Always open the root directory of the project in your IDE. This will make it easier to navigate between the server and app packages. It will also prevent your analyzer from going out of sync when you generate code.
23
-
24
23
:::
25
24
26
25
### Add the Gemini API to your project
@@ -197,7 +196,7 @@ class MyHomePageState extends State<MyHomePage> {
197
196
## Run the app
198
197
199
198
:::tip
200
-
Before you start your server, ensure no other Serverpod server is running. Also, ensure that Docker for another project isn't running. You can see and stop containers in the Docker Desktop app.
199
+
Before you start your server, ensure no other Serverpod server is running. Also, ensure that Docker containers from other Serverpod projects aren't running to avoid port conflicts. You can see and stop containers in the Docker Desktop app.
201
200
:::
202
201
203
202
Let's try our new recipe app! First, start the server:
Copy file name to clipboardExpand all lines: docs/01-get-started/02-models-and-data.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ This will generate the code for the model and create a new file called `recipe.d
41
41
42
42
## Use the model in the server
43
43
44
-
Now that you have created the model, you can use it in your server code. Let's update the `lib/src/recipies/recipe_endpoint.dart` file to make the `generateRecipe` method to return a `Recipe` object instead of a string.
44
+
Now that you have created the model, you can use it in your server code. Let's update the `lib/src/recipes/recipe_endpoint.dart` file to make the `generateRecipe` method return a `Recipe` object instead of a string.
Copy file name to clipboardExpand all lines: docs/01-get-started/03-working-with-the-database.md
+25-15Lines changed: 25 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@ sidebar_label: 3. Working with the database
4
4
5
5
# Working with the database
6
6
7
-
In this section, we will build upon the models we created in the previous section and add a database to store our favorite recipes that we create in the app.
7
+
In this section, we will build upon the models we created in the previous section and add a database to store the recipes that users create in the app. This will allow our application to persist data between sessions.
8
8
9
9
## Object relation mapping
10
10
11
-
Any Serverpod model can be mapped to the database through Serverpod's object relation mapping (ORM). Simply add the `table` keyword to the `Recipe` model in our `recipe.spy.yaml` file. This will map the model to a new table in the database called `recipes`.
11
+
Any Serverpod model can be mapped to the database through Serverpod's object relation mapping (ORM). To enable database storage for our recipe model, simply add the `table` keyword to the `Recipe` model in our `recipe.spy.yaml` file. This will map the model to a new table in the database called `recipes`.
12
12
13
13
<!--SNIPSTART 03-table-model-->
14
14
```yaml
@@ -33,19 +33,24 @@ Check out the reference for [database models](../06-concepts/02-models.md#keywor
33
33
34
34
## Migrations
35
35
36
-
With database migrations, Serverpod makes it easy to evolve your database schema. When you make changes to your project that should be reflected in your database, you need to create a migration. A migration is a set of SQL queries that are run to update the database. To create a migration, run `serverpod create-migration` in the home directory of the server. Since we modified one of our models, make sure to also run `serverpod generate`, to update the generated code in our server.
36
+
Database migrations in Serverpod provide a way to safely evolve your database schema over time. When you make changes to your models that affect the database structure, you need to create a migration. A migration consists of SQL queries that update the database schema to match your model changes.
37
+
38
+
To create a migration, follow these two steps in order:
39
+
40
+
1. Run `serverpod generate` to update the generated code based on your model changes.
41
+
2. Run `serverpod create-migration` to create the necessary database migration.
37
42
38
43
```bash
39
44
$ cd magic_recipe/magic_recipe_server
40
45
$ serverpod generate
41
46
$ serverpod create-migration
42
47
```
43
48
44
-
You will notice that there will be a new entry in your _migrations_ folder - serverpod creates these migrations "step by step" - each time you have changes which are relevant to the database and run `serverpod create-migrations` a new migration file will be created. This is a good way to keep track of the changes you make to the database and to be able to roll back changes if needed.
49
+
Each time you run `serverpod create-migration`, a new migration file will be created in your _migrations_ folder. These step-by-step migrations provide a history of your database changes and allow you to roll back changes if needed.
45
50
46
51
## Writing to the database
47
52
48
-
Let's save all the recipes we create to the database. Because the `Recipe` now has a `table` key, it is not just a serializable model but also a `TableRow`. This means that Serverpod has generated bindings for us to the database. You can access the bindings through the static `db` field of the `Recipe`. Here, you will find the `insertRow` method, which is used to create a new entry in the database.
53
+
Now that we've added the `table` keyword to our `Recipe` model, it becomes a `TableRow` type, giving us access to database operations. Serverpod automatically generates database bindings that we can access through the static `db` field of the `Recipe` class. Let's use the `insertRow` methodto save new recipes to the database:
@@ -418,18 +423,21 @@ class ResultDisplay extends StatelessWidget {
418
423
419
424
## Run the app
420
425
421
-
First, we need to start the server and apply the migrations by adding the `--apply-migrations` flag:
426
+
To run the application with database support, follow these steps in order:
427
+
428
+
First, start the database and apply migrations:
422
429
423
430
```bash
424
431
$ cd magic_recipe/magic_recipe_server
425
-
$ docker compose up -d
426
-
$ dart bin/main.dart --apply-migrations
432
+
$ docker compose up -d# Start the database container
433
+
$ dart bin/main.dart --apply-migrations# Apply any pending migrations
427
434
```
428
435
429
436
:::tip
430
-
When developing your server, it's always safe to pass the `--apply-migrations` flag. If no migration needs to be applied, the flag is simply ignored. In a production environment, you may want to have a bit more control.
437
+
The `--apply-migrations` flag is safe to use during development - if no migrations are pending, it will simply be ignored. For production environments, you may want more controlled migration management.
431
438
:::
432
-
Now, start the Flutter app:
439
+
440
+
Next, launch the Flutter app:
433
441
434
442
```bash
435
443
$ cd magic_recipe/magic_recipe_flutter
@@ -438,12 +446,14 @@ $ flutter run -d chrome
438
446
439
447
## Summary
440
448
441
-
You now know the fundamentals of Serverpod - how to create and use endpoints with custom data models and how to store the data in a database. You have also learned how to use the generated client code to call the endpoints from your Flutter app. We cannot wait to see what you will build with Flutter and Serverpod.
449
+
You've now learned the fundamentals of Serverpod:
442
450
443
-
If you get stuck, never be afraid to ask questions in our [community on Github](https://github.com/serverpod/serverpod/discussions). The Serverpod team is very active there, and many questions are also answered by other developers.
451
+
- Creating and using endpoints with custom data models.
452
+
- Storing data persistently in a database.
453
+
- Using the generated client code in your Flutter app.
444
454
445
-
:::tip
446
-
447
-
Working with a database is an extensive subject, and Serverpod's ORM is very powerful. Learn more in the [Database](../06-concepts/06-database/01-connection.md) section.
455
+
We're excited to see what you'll build with Flutter and Serverpod! If you need help, don't hesitate to ask questions in our [community on Github](https://github.com/serverpod/serverpod/discussions). Both the Serverpod team and community members are active and ready to help.
448
456
457
+
:::tip
458
+
Database operations are a broad topic, and Serverpod's ORM offers many powerful features. To learn more about advanced database operations, check out the [Database](../06-concepts/06-database/01-connection.md) section.
Since Serverpod is written in Dart, it can be compiled into native code and runs on any platform that is supported by the [Dart tooling](https://dart.dev/get-dart#system-requirements).
9
+
Serverpod is written in Dart and compiles to native code, allowing it to run on any platform supported by the [Dart tooling](https://dart.dev/get-dart#system-requirements).
10
10
11
-
Many users will want to deploy Serverpod using Docker. There is a basic Dockerfile included in the project that can be used to build a Docker image. This image can then be run on any platform that supports Docker.
11
+
Many users prefer to deploy Serverpod using Docker. The project includes a basic Dockerfile that you can use to build a Docker image, which can then be run on any Docker-compatible platform.
12
12
13
-
If you don't use Docker, you will need [compile the Dart code](https://dart.dev/tools/dart-compile) and copy any assets and configuration files to the server since [asset bundling is not yet supported by Dart](https://github.com/dart-lang/sdk/issues/55195).
13
+
For non-Docker deployments, you'll need to [compile the Dart code](https://dart.dev/tools/dart-compile) and manually copy your assets and configuration files to the server. This manual step is necessary since [asset bundling is not yet supported by Dart](https://github.com/dart-lang/sdk/issues/55195).
14
14
15
15
## Server configuration
16
16
@@ -22,9 +22,9 @@ By default Serverpod is active on three ports:
22
22
23
23
You will also need to configure the database connection in the `config/production.yaml` file and **securely** provide the `config/passwords.yaml` file to the server.
24
24
25
-
## Health check from load balancer
25
+
## Health checks
26
26
27
-
The **8080** port returns a basic health check response. You can use this to check if the server is running and is healthy.
27
+
The server exposes a health check on the root endpoint `/` on port **8080**. Load balancers and monitoring systems can use this endpoint to verify that your server is running and healthy. The endpoint returns a basic health status response.
28
28
29
29
## Deploying with Serverpod Cloud
30
30
@@ -34,4 +34,4 @@ Serverpod Cloud is currently in private beta. Request access by [filling out thi
34
34
35
35
## Other deployment options
36
36
37
-
Checkout[choosing a deployment strategy](../07-deployments/01-deployment-strategy.md) for more information on how to deploy your Serverpod application to other platforms.
37
+
Check out[choosing a deployment strategy](../07-deployments/01-deployment-strategy.md) for more information on how to deploy your Serverpod application to other platforms.
0 commit comments