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: guides/databases/schema-evolution.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,13 +8,13 @@ Schema evolution is the capability of a database to adapt its schema (tables, co
8
8
9
9
## Drop-Create in Development
10
10
11
-
During development, schema evolution is typically handled using a "drop-create" strategy, where the existing databases or schemas are dropped and recreated based on the current CDS model. This approach is simple and effective, and most suitable for development phases, as it:
11
+
During development, schema evolution is typically handled using a "drop-create" strategy, where you drop and recreate the existing databases or schemas based on the current CDS model. This approach is simple and effective, and most suitable for development phases, as it:
12
12
13
-
-allows developers to quickly iterate on their data models
14
-
-with incompatible changes being the standard, such as
15
-
- adding, removing, or renaming entities and fields
13
+
-Allows you to quickly iterate on your data models
14
+
-Makes incompatible changes the standard, such as:
15
+
- Adding, removing, or renaming entities and fields
16
16
17
-
We see that in action when running`cds deploy`, which generates the necessary SQL statements to drop existing tables and recreate them or new ones according to the current CDS definitions:
17
+
You can see this in action when you run`cds deploy`, which generates the necessary SQL statements to drop existing tables and recreate them or new ones according to the current CDS definitions:
18
18
19
19
```shell
20
20
cds deploy --dry
@@ -38,7 +38,7 @@ In addition to dropping and recreating tables in-place, you can and should also
38
38
## Schema Evolution by CAP
39
39
40
40
41
-
In production environments, a drop-create strategy is not feasible, as it would result in data loss. CAP provides mechanisms to handle schema evolution in a more controlled manner, by generating migration scripts that can be reviewed and applied to the database.
41
+
In production environments, you can't use a drop-create strategy, as it would result in data loss. CAP provides mechanisms to handle schema evolution in a more controlled manner, by generating migration scripts that you can review and apply to the database.
42
42
43
43
Let's simulate the workflow with the [@capire/bookshop](https://github.com/capire/bookshop) example.
44
44
@@ -47,7 +47,7 @@ Let's simulate the workflow with the [@capire/bookshop](https://github.com/capir
47
47
cds deploy --dry --model-only -o former.csn
48
48
```
49
49
50
-
2. Make changes to our models, for example let's edit `db/schema.cds` like this:
50
+
2. Make changes to your models. For example, edit `db/schema.cds` like this:
51
51
52
52
::: code-group
53
53
```cds [db/schema.cds]
@@ -113,17 +113,17 @@ Let's simulate the workflow with the [@capire/bookshop](https://github.com/capir
113
113
114
114
### Disallowed Changes
115
115
116
-
Some changes to the CDS model are considered disallowed in the context of schema evolution, as they could lead to data loss or inconsistencies. Examples of such changes include:
116
+
Some changes to the CDS model are considered disallowed in the context of schema evolution, as they could lead to data loss or inconsistencies. The following list shows examples of such changes:
117
117
118
118
- Renaming entities or fields (instead, add new ones and migrate data)
119
119
- Changing data types in incompatible ways (e.g., from String to Integer)
120
120
- Removing entities or fields (instead, consider deprecating them first)
121
121
- Reducing the length of strings or binary fields
122
122
- Reducing the precision of numeric fields
123
123
124
-
When such disallowed changes are detected during the generation of migration scripts, `cds deploy --script` will print a warning, and also add corresponding comments to the generated SQL script, which can then be reviewed and addressed manually.
124
+
When `cds deploy --script` detects such disallowed changes during the generation of migration scripts, it prints a warning and adds corresponding comments to the generated SQL script, which you can then review and address manually.
125
125
126
-
For example, if we would rename the `descr` field to `details` like that:
126
+
For example, if you rename the `descr` field to `details` like this:
127
127
128
128
::: code-group
129
129
```cds [db/schema.cds]
@@ -171,14 +171,14 @@ You can enable automatic schema evolution in your `db` configuration:
171
171
```
172
172
:::
173
173
174
-
This will enable automatic schema migration when running `cds deploy` in production-like environments as follows:
174
+
This enables automatic schema migration when you run `cds deploy` in production-like environments. The migration process works as follows:
175
175
176
-
- Whenever a `cds deploy`is executed successfully, the resulting state of the database schema is stored in an internal table.
176
+
- Whenever you execute `cds deploy` successfully, CAP stores the resulting state of the database schema in an internal table.
177
177
178
-
- Before applying any changes, CAP compares the new state of the CDS models with the stored state. Any differences are translated into appropriate SQL statements to migrate the schema.
178
+
- Before applying any changes, CAP compares the new state of the CDS models with the stored state and translates any differences into appropriate SQL statements to migrate the schema.
179
179
180
180
> [!important]
181
-
> Only non-lossy changes are applied automatically. If lossy changes are detected, `cds deploy`will abort with respective errors and include comments in the generated SQL script, similar to the general approach described above.
181
+
> CAP applies only non-lossy changes automatically. If it detects lossy changes, `cds deploy`aborts with respective errors and includes comments in the generated SQL script, similar to the general approach described above.
182
182
183
183
184
184
## Schema Evolution by HDI
@@ -193,6 +193,6 @@ Learn more about that in the [SAP HANA](hana.md) guide, section [HDI Schema Evol
193
193
194
194
## Liquibase for Java Projects
195
195
196
-
For Java-based CAP projects, you can also use [Liquibase](https://www.liquibase.org/) to control when, where, and how database changes are deployed.
196
+
For Java-based CAP projects, you can also use [Liquibase](https://www.liquibase.org/) to control when, where, and how you deploy database changes.
197
197
198
198
Learn more about that in the [PostgreSQL](postgres.md) guide, section [Using Liquibase (Java)](postgres#using-liquibase-java).
0 commit comments