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
{{ message }}
Repository navigation
Commit a4428de
Browse filesBrowse the repository at this point in the historyBrowse files
`Fresh::map` maps each value of `TAddedElement` to a distinct new entity ID.
123
+
Using an algebraic data type with multiple constructors allows several distinct
124
+
entities to be created for the same source entity.
125
+
126
+
The query is compiled against the source schema, so a fresh ID cannot belong to
127
+
an entity type that exists only in the target schema. Define a union of the
128
+
appropriate source-schema type and `Fresh::EntityId`, then use a class extending
129
+
that union in the output predicates:
130
+
131
+
```ql
132
+
class TNewElement = @element or Fresh::EntityId;
133
+
134
+
class NewElement extends TNewElement {
135
+
string toString() { none() }
136
+
}
137
+
138
+
query predicate new_wrappers(NewElement wrapper, Element element) {
139
+
wrapper = Fresh::map(TWrapper(element))
140
+
}
141
+
```
142
+
143
+
Run the predicate to populate a relation in the target schema:
144
+
145
+
```properties
146
+
wrappers.rel: run upgrade.qlo new_wrappers
147
+
```
148
+
149
+
The target relation's column type determines the database type of each fresh
150
+
ID. Emit every target relation needed to describe the new entity, including
151
+
relationships such as its parent, location, or type. When rewriting an existing
152
+
relation, its output predicate will usually need to preserve all existing rows
153
+
as well as add rows containing the fresh IDs. Reuse the same
154
+
`Fresh::map(...)` expression in each predicate that refers to a particular new
155
+
entity.
156
+
104
157
### Testing your scripts
105
158
106
159
Although we have some automated testing of the scripts (e.g. to test that you can upgrade databases all the way from an initial dbscheme to the newest, and back), it's essential that you apply some more rigorous testing for any non-trivial upgrade or downgrade. You might do so as follows:
0 commit comments