Skip to content

Commit ee690e4

Browse files
committed
ai-supported edit
1 parent 0b51630 commit ee690e4

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

guides/databases/initial-data.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Adding Initial Data
22

3-
You can add `.csv` files to fill your database with initial data and/or test data. These files are automatically loaded whenever a database gets bootstrapped in or you run `cds watch` at development time, or when deployed or upgraded for production.
3+
You can add `.csv` files to fill your database with initial data and test data. The runtime automatically loads these files whenever you bootstrap a database, run `cds watch` in development, or deploy and upgrade for production.
44
{.abstract}
55

66
[[toc]]
77

88

99
## Using `cds add data`
1010

11-
Use `cds add data` to generate empty `.csv` files, with column headers based on the entities in your CDS model. For example, if we do so in our [*@capire/bookshop*](../../get-started/bookshop) sample project, we'd see output as shown below:
11+
Use `cds add data` to generate empty `.csv` files, with column headers based on the entities in your CDS model. For example, if you run this in the [*@capire/bookshop*](../../get-started/bookshop) sample project, you can see the following output:
1212

1313
```shell
1414
cds add data
@@ -25,7 +25,7 @@ Adding facet: data
2525
Successfully added features to your project
2626
```
2727

28-
By default, the generated files are placed in the _db/data_ folder of your project structure:
28+
By default, the command generates the files in the _db/data_ folder of your project structure:
2929

3030
```zsh
3131
cap/bookshop/
@@ -35,7 +35,7 @@ cap/bookshop/
3535
...
3636
```
3737

38-
You can also specify other folders by providing the `--out` option, e.g.:
38+
You can also specify other folders by providing the `--out` option, for example:
3939

4040
```shell
4141
cds add data -o test/data
@@ -45,7 +45,7 @@ Each file contains a CSV header line reflecting the structure of the entity to w
4545

4646
## Editing `.csv` Files
4747

48-
Go ahead and fill these files with initial data by editing them in your favorite editor. For example, the content of _db/data/sap.capire.bookshop-Books.csv_ looks like that:
48+
Fill these files with initial data by editing them in your preferred editor. For example, the content of _db/data/sap.capire.bookshop-Books.csv_ looks like this:
4949

5050
::: code-group
5151

@@ -72,7 +72,7 @@ cds add data --records 10
7272
7373

7474

75-
Common rules apply to text content in `.csv` files, like:
75+
The following table shows common rules that apply to text content in `.csv` files:
7676

7777
| Condition | Handling |
7878
|------------------------------------------------------------------|-----------------------------|
@@ -85,7 +85,7 @@ Common rules apply to text content in `.csv` files, like:
8585

8686
## Initial vs Test Data
8787

88-
Quite frequently, you need to distinguish between _(real) initial data_, that is data meant for production, such as configuration, code lists, and _test data_, meant for development and testing purposes only. CAP supports this by putting respective .csv files in two major places:
88+
You need to distinguish between _(real) initial data_ meant for production (configuration, code lists) and _test data_ meant for development and testing purposes only. CAP supports this by organizing CSV files in two locations:
8989

9090
```zsh
9191
cap/bookshop/
@@ -99,13 +99,15 @@ cap/bookshop/
9999
...
100100
```
101101

102+
The following table describes the purpose and deployment scope of each location:
103+
102104
| Location | Purpose | Deployed... |
103105
|-----------------|---------------------|----------------------|
104106
| **`db/data`** | (real) initial data | always, dev and prod |
105107
| **`test/data`** | test data | in development only |
106108

107109
::: details Bookshop data is actually test data...
108-
Note that the initial data provided in the [_@capire/bookshop_](../../get-started/bookshop) sample is actually test data, and hence should have been placed in the _test/data_ folder. But for simplicity, it's placed in _db/data_, also because the whole purpose of that project is to be a _sample_.
110+
Note that the initial data provided in the [_@capire/bookshop_](../../get-started/bookshop) sample is actually test data, and hence we would typically place it in the _test/data_ folder. But for simplicity, it's placed in _db/data_, also because the whole purpose of that project is to be a _sample_.
109111
::::
110112

111113
> [!danger] Don't let users modify productive initial data
@@ -114,7 +116,7 @@ Note that the initial data provided in the [_@capire/bookshop_](../../get-starte
114116

115117
### Custom Folders
116118

117-
You can also configure other folders to read data from in different profiles. Use config option <Config>cds.requires.db.data</Config> to do so. The default configuration is like that, which you can override in your `package.json` or `.cdsrc.yaml` file as appropriate:
119+
You can also configure other folders to read data from in different profiles. Use config option <Config>cds.requires.db.data</Config> to do so. The default configuration is as follows, which you can override in your `package.json` or `.cdsrc.yaml` file as appropriate:
118120

119121
::: code-group
120122
```json [package.json]
@@ -144,7 +146,7 @@ cds env requires.db.data --profile development
144146

145147
## Next to `.cds` Files
146148

147-
In addition to the [configured](#custom-folders) folders for initial data and test data that is `db/data` and `test/data` by default, you can place `.csv` files into `data` folders anywhere next to your CDS model source files. For example:
149+
In addition to the [configured](#custom-folders) folders for initial data and test data (that is, `db/data` and `test/data` by default), you can place `.csv` files into `data` folders anywhere next to your CDS model source files. For example:
148150

149151
```zsh
150152
myproject/
@@ -157,16 +159,16 @@ myproject/
157159
...
158160
```
159161

160-
All `db/data/*.csv` and `srv/data/*.csv` files are automatically loaded, because they are located in a `data` folder next to `.cds` model sources.
162+
The runtime automatically loads all `db/data/*.csv` and `srv/data/*.csv` files located in a `data` folder next to `.cds` model sources.
161163

162-
This is especially useful for remote service definitions imported with `cds import` (by default into `srv/external/`) so that data for such services can also be served when mocking.
164+
This is especially useful for remote service definitions imported with `cds import` (by default into `srv/external/`), allowing you to serve mock data for external services.
163165

164166

165167
## From Reuse Packages
166168

167-
The [_in-the-neighborhood-of-models_](#next-to-cds-files) technique enables reuse packages whose main purpose is to provide initial data.
169+
The [_in-the-neighborhood-of-models_](#next-to-cds-files) technique enables reuse packages that provide initial data.
168170

169-
Find an example for such a content reuse package at [*@capire/common*](https://github.com/capire/common) which showcases how one could provide ISO reuse data for `Countries`, `Currencies` and `Languages` code lists, as defined in [`@sap/cds/common`](../../cds/common). It essentially consists of these files as content:
171+
An example of such a content reuse package is [*@capire/common*](https://github.com/capire/common), which showcases how to provide ISO reuse data for `Countries`, `Currencies`, and `Languages` code lists, as defined in [`@sap/cds/common`](../../cds/common). It essentially consists of these files as content:
170172

171173
```zsh
172174
@capire/common
@@ -182,8 +184,8 @@ Find an example for such a content reuse package at [*@capire/common*](https://g
182184
└── package.json
183185
```
184186

185-
Such packages get installed via `npm` or `mvn`, and hence their content will reside under `node_modules` folders, or Maven `target` folders.
186-
As long as they also enclose reuse models, like the `index.cds` above, the .csv files in the `data` folder next to it will be automatically found and loaded into a consuming application's database.
187+
Install such packages via `npm` or `mvn`. Their content will reside under `node_modules` folders or Maven `target` folders.
188+
When packages include reuse models (like `index.cds` above), the runtime automatically discovers and loads CSV files from the adjacent `data` folder into the consuming application's database.
187189

188190
> [!tip] How to 'enable' reuse packages
189191
>
@@ -199,12 +201,12 @@ As long as they also enclose reuse models, like the `index.cds` above, the .csv
199201
> }
200202
> ```
201203
>
202-
> In absence of such a plugin configuration, you could add a `using from '@capire/common';` clause to one of your cds files.
204+
> Without such plugin configuration, add a `using from '@capire/common';` clause to one of your CDS files.
203205

204206

205-
## Plug-and-Play Reuse
207+
## Plug-and-Play Reuse
206208

207-
Reuse packages, such as the `@capire/common` one described above, can be consumed in any CAP project by simply installing them via `npm` or `mvn`, as shown in the [`@capire/bookstore`](https://github.com/capire/bookstore) sample project:
209+
You can consume reuse packages, such as the `@capire/common` one described above, in any CAP project by simply installing them via `npm` or `mvn`, as shown in the [`@capire/bookstore`](https://github.com/capire/bookstore) sample project:
208210

209211
```json [package.json]
210212
{
@@ -217,7 +219,7 @@ Reuse packages, such as the `@capire/common` one described above, can be consume
217219
}
218220
```
219221

220-
When running `cds watch`, the `@capire/common/index.cds` model file is automatically picked up, and so are all `.csv` files in its `data` folder, as indicated in the following output:
222+
When you run `cds watch`, the runtime automatically picks up the `@capire/common/index.cds` model file and all CSV files in its `data` folder, as shown in the following output:
221223

222224
```zsh
223225
[cds] - loaded model from 27 file(s):

0 commit comments

Comments
 (0)