Skip to content

Commit 8f25f87

Browse files
committed
feat: plug schema on writes
1 parent b25c875 commit 8f25f87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+712
-137
lines changed

cmd/docs_events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func NewDocEventsCommand() *cobra.Command {
3434
events.DeletedMetadata{},
3535
events.SavedMetadata{},
3636
events.RevertedTransaction{},
37+
events.UpdatedSchema{},
3738
} {
3839
schema := jsonschema.Reflect(o)
3940
data, err := json.MarshalIndent(schema, "", " ")

docs/api/README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ Accept: application/json
658658
{
659659
"action": "string",
660660
"ik": "string",
661+
"schemaVersion": "v1.0.0",
661662
"data": {
662663
"timestamp": "2019-08-24T14:15:22Z",
663664
"postings": [
@@ -701,6 +702,7 @@ Accept: application/json
701702
|continueOnFailure|query|boolean|false|Continue on failure|
702703
|atomic|query|boolean|false|Make bulk atomic|
703704
|parallel|query|boolean|false|Process bulk elements in parallel|
705+
|schemaVersion|query|string|false|Default schema version to use for validation (can be overridden per element)|
704706
|body|body|[V2Bulk](#schemav2bulk)|true|none|
705707

706708
> Example responses
@@ -1105,6 +1107,7 @@ Idempotency-Key: string
11051107
|address|path|string|true|Exact address of the account. It must match the following regular expressions pattern:|
11061108
|dryRun|query|boolean|false|Set the dry run mode. Dry run mode doesn't add the logs to the database or publish a message to the message broker.|
11071109
|Idempotency-Key|header|string|false|Use an idempotency key|
1110+
|schemaVersion|query|string|false|Schema version to use for validation|
11081111
|body|body|[V2Metadata](#schemav2metadata)|true|metadata|
11091112

11101113
#### Detailed descriptions
@@ -1531,6 +1534,7 @@ Idempotency-Key: string
15311534
|dryRun|query|boolean|false|Set the dryRun mode. dry run mode doesn't add the logs to the database or publish a message to the message broker.|
15321535
|Idempotency-Key|header|string|false|Use an idempotency key|
15331536
|force|query|boolean|false|Disable balance checks when passing postings|
1537+
|schemaVersion|query|string|false|Schema version to use for validation|
15341538
|body|body|[V2PostTransaction](#schemav2posttransaction)|true|The request body must contain at least one of the following objects:|
15351539

15361540
#### Detailed descriptions
@@ -1806,6 +1810,7 @@ Idempotency-Key: string
18061810
|id|path|integer(bigint)|true|Transaction ID.|
18071811
|dryRun|query|boolean|false|Set the dryRun mode. Dry run mode doesn't add the logs to the database or publish a message to the message broker.|
18081812
|Idempotency-Key|header|string|false|Use an idempotency key|
1813+
|schemaVersion|query|string|false|Schema version to use for validation|
18091814
|body|body|[V2Metadata](#schemav2metadata)|true|metadata|
18101815

18111816
> Example responses
@@ -1870,6 +1875,7 @@ Accept: application/json
18701875
|force|query|boolean|false|Force revert|
18711876
|atEffectiveDate|query|boolean|false|Revert transaction at effective date of the original tx|
18721877
|dryRun|query|boolean|false|Set the dryRun mode. dry run mode doesn't add the logs to the database or publish a message to the message broker.|
1878+
|schemaVersion|query|string|false|Schema version to use for validation|
18731879
|body|body|[V2RevertTransactionRequest](#schemav2reverttransactionrequest)|false|none|
18741880

18751881
> Example responses
@@ -2181,7 +2187,8 @@ Format: `<field>:<order>`, where `<field>` is the field name and `<order>` is ei
21812187
"type": "NEW_TRANSACTION",
21822188
"data": {},
21832189
"hash": "9ee060170400f556b7e1575cb13f9db004f150a08355c7431c62bc639166431e",
2184-
"date": "2019-08-24T14:15:22Z"
2190+
"date": "2019-08-24T14:15:22Z",
2191+
"schemaVersion": "v1.0.0"
21852192
}
21862193
]
21872194
}
@@ -3315,7 +3322,8 @@ This operation does not require authentication
33153322
"type": "NEW_TRANSACTION",
33163323
"data": {},
33173324
"hash": "9ee060170400f556b7e1575cb13f9db004f150a08355c7431c62bc639166431e",
3318-
"date": "2019-08-24T14:15:22Z"
3325+
"date": "2019-08-24T14:15:22Z",
3326+
"schemaVersion": "v1.0.0"
33193327
}
33203328
]
33213329
}
@@ -3836,7 +3844,8 @@ This operation does not require authentication
38363844
"type": "NEW_TRANSACTION",
38373845
"data": {},
38383846
"hash": "9ee060170400f556b7e1575cb13f9db004f150a08355c7431c62bc639166431e",
3839-
"date": "2019-08-24T14:15:22Z"
3847+
"date": "2019-08-24T14:15:22Z",
3848+
"schemaVersion": "v1.0.0"
38403849
}
38413850

38423851
```
@@ -3850,6 +3859,7 @@ This operation does not require authentication
38503859
|data|object|true|none|none|
38513860
|hash|string|true|none|none|
38523861
|date|string(date-time)|true|none|none|
3862+
|schemaVersion|string|false|none|Schema version used for validation|
38533863

38543864
#### Enumerated Values
38553865

@@ -3859,6 +3869,7 @@ This operation does not require authentication
38593869
|type|SET_METADATA|
38603870
|type|REVERTED_TRANSACTION|
38613871
|type|DELETE_METADATA|
3872+
|type|UPDATED_SCHEMA|
38623873

38633874
<h2 id="tocS_V2CreateTransactionResponse">V2CreateTransactionResponse</h2>
38643875
<!-- backwards compatibility -->
@@ -4470,6 +4481,7 @@ This operation does not require authentication
44704481
{
44714482
"action": "string",
44724483
"ik": "string",
4484+
"schemaVersion": "v1.0.0",
44734485
"data": {
44744486
"timestamp": "2019-08-24T14:15:22Z",
44754487
"postings": [
@@ -4522,7 +4534,8 @@ This operation does not require authentication
45224534
```json
45234535
{
45244536
"action": "string",
4525-
"ik": "string"
4537+
"ik": "string",
4538+
"schemaVersion": "v1.0.0"
45264539
}
45274540

45284541
```
@@ -4533,6 +4546,7 @@ This operation does not require authentication
45334546
|---|---|---|---|---|
45344547
|action|string|true|none|none|
45354548
|ik|string|false|none|none|
4549+
|schemaVersion|string|false|none|Schema version to use for validation|
45364550

45374551
<h2 id="tocS_V2BulkElement">V2BulkElement</h2>
45384552
<!-- backwards compatibility -->
@@ -4545,6 +4559,7 @@ This operation does not require authentication
45454559
{
45464560
"action": "string",
45474561
"ik": "string",
4562+
"schemaVersion": "v1.0.0",
45484563
"data": {
45494564
"timestamp": "2019-08-24T14:15:22Z",
45504565
"postings": [
@@ -4617,6 +4632,7 @@ xor
46174632
{
46184633
"action": "string",
46194634
"ik": "string",
4635+
"schemaVersion": "v1.0.0",
46204636
"data": {
46214637
"timestamp": "2019-08-24T14:15:22Z",
46224638
"postings": [
@@ -4729,6 +4745,7 @@ xor
47294745
{
47304746
"action": "string",
47314747
"ik": "string",
4748+
"schemaVersion": "v1.0.0",
47324749
"data": {
47334750
"targetId": "string",
47344751
"targetType": "TRANSACTION",
@@ -4771,6 +4788,7 @@ and
47714788
{
47724789
"action": "string",
47734790
"ik": "string",
4791+
"schemaVersion": "v1.0.0",
47744792
"data": {
47754793
"id": 0,
47764794
"force": true,
@@ -4809,6 +4827,7 @@ and
48094827
{
48104828
"action": "string",
48114829
"ik": "string",
4830+
"schemaVersion": "v1.0.0",
48124831
"data": {
48134832
"targetId": "string",
48144833
"targetType": "TRANSACTION",

docs/events/UpdatedSchema.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://github.com/formancehq/ledger/pkg/events/updated-schema",
4+
"$ref": "#/$defs/UpdatedSchema",
5+
"$defs": {
6+
"Schema": {
7+
"properties": {
8+
"version": {
9+
"type": "string"
10+
},
11+
"createdAt": {
12+
"$ref": "#/$defs/Time"
13+
}
14+
},
15+
"additionalProperties": false,
16+
"type": "object",
17+
"required": [
18+
"version",
19+
"createdAt"
20+
]
21+
},
22+
"Time": {
23+
"type": "string",
24+
"format": "date-time",
25+
"title": "Normalized date"
26+
},
27+
"UpdatedSchema": {
28+
"properties": {
29+
"ledger": {
30+
"type": "string"
31+
},
32+
"schema": {
33+
"$ref": "#/$defs/Schema"
34+
}
35+
},
36+
"additionalProperties": false,
37+
"type": "object",
38+
"required": [
39+
"ledger",
40+
"schema"
41+
]
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)