Skip to content

Commit b893c13

Browse files
authored
feat: Move change id type out of experimental. (#299)
1 parent 6ec9860 commit b893c13

File tree

2 files changed

+46
-47
lines changed

2 files changed

+46
-47
lines changed

docs/06-concepts/06-database/02-models.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,45 @@ fields:
5353
```
5454

5555
For a complete guide on how to work with relations see the [relation section](relations/one-to-one).
56+
57+
## Change ID type
58+
59+
Changing the type of the `id` field allows you to customize the identifier type for your database tables. This is done by declaring the `id` field on table models with one of the supported types. If the field is omitted, the id field will still be created with type `int`, as have always been.
60+
61+
The following types are supported for the `id` field:
62+
63+
| **Type** | Default | Default Persist options | Default Model options | Description |
64+
| :------------ | :------ | :---------------------- | :-------------------- | :--------------------- |
65+
| **int** | serial | serial (optional) | - | 64-bit serial integer. |
66+
| **UuidValue** | random | random | random | UUID v4 value. |
67+
68+
### Declaring a Custom ID Type
69+
70+
To declare a custom type for the `id` field in a table model file, use the following syntax:
71+
72+
```yaml
73+
class: UuidIdTable
74+
table: uuid_id_table
75+
fields:
76+
id: UuidValue?, defaultPersist=random
77+
```
78+
79+
```yaml
80+
class: IntIdTable
81+
table: int_id_table
82+
fields:
83+
id: int?, defaultPersist=serial // The default keyword for 'int' is optional.
84+
```
85+
86+
#### Default Uuid model value
87+
88+
For UUIDs, it is possible to configure the `defaultModel` value. This will ensure that UUIDs are generated as soon as the object is created, rather than when it is persisted to the database. This is useful for creating objects offline or using them before they are sent to the server.
89+
90+
```yaml
91+
class: UuidIdTable
92+
table: uuid_id_table
93+
fields:
94+
id: UuidValue, defaultModel=random
95+
```
96+
97+
When using `defaultModel=random`, the UUID will be generated when the object is created. Since an id is always assigned the `id` field can be non-nullable.

docs/06-concepts/21-experimental.md

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ $ serverpod generate --experimental-features=all
2626

2727
The current options you can pass are:
2828

29-
| **Feature** | Description |
30-
| :--------------- | :----------------------------------------------------------------------------------------- |
31-
| **all** | Enables all available experimental features. |
32-
| **inheritance** | Allows using the `extends` keyword in your model files to create class hierarchies. |
33-
| **changeIdType** | Allows declaring the `id` field in table model files to change the type of the `id` field. |
29+
| **Feature** | Description |
30+
| :-------------- | :---------------------------------------------------------------------------------- |
31+
| **all** | Enables all available experimental features. |
32+
| **inheritance** | Allows using the `extends` keyword in your model files to create class hierarchies. |
3433

3534
## Inheritance
3635

@@ -101,48 +100,6 @@ class ChildClass extends ParentClass {
101100
All files in a sealed hierarchy need to be located in the same directory.
102101
:::
103102

104-
## Change ID type
105-
106-
Changing the type of the `id` field allows you to customize the identifier type for your database tables. This is done by declaring the `id` field on table models with one of the supported types. If the field is omitted, the id field will still be created with type `int`, as have always been.
107-
108-
The following types are supported for the `id` field:
109-
110-
| **Type** | Default | Default Persist options | Default Model options | Description |
111-
| :------------ | :------ | :---------------------- | :-------------------- | :--------------------- |
112-
| **int** | serial | serial (optional) | - | 64-bit serial integer. |
113-
| **UuidValue** | random | random | random | UUID v4 value. |
114-
115-
### Declaring a Custom ID Type
116-
117-
To declare a custom type for the `id` field in a table model file, use the following syntax:
118-
119-
```yaml
120-
class: UuidIdTable
121-
table: uuid_id_table
122-
fields:
123-
id: UuidValue?, defaultPersist=random
124-
```
125-
126-
```yaml
127-
class: IntIdTable
128-
table: int_id_table
129-
fields:
130-
id: int?, defaultPersist=serial // The default keyword for 'int' is optional.
131-
```
132-
133-
#### Default Uuid model value
134-
135-
For UUIDs, it is possible to configure the `defaultModel` value. This will ensure that UUIDs are generated as soon as the object is created, rather than when it is persisted to the database. This is useful for creating objects offline or using them before they are sent to the server.
136-
137-
```yaml
138-
class: UuidIdTable
139-
table: uuid_id_table
140-
fields:
141-
id: UuidValue, defaultModel=random
142-
```
143-
144-
When using `defaultModel=random`, the UUID will be generated when the object is created. Since an id is always assigned the `id` field can be non-nullable.
145-
146103
## Exception monitoring
147104

148105
Serverpod allows you to monitor exceptions in a central and flexible way by using the new diagnostic event handlers.

0 commit comments

Comments
 (0)