liquibase-mongodb
liquibase-mongodb copied to clipboard
Does YAML support raw JSON Parser?
I am working on liquibase for mongodb, and tried using YAML format as a changeset for my database. (This is because YAML is the preferred format used across other services in the project)
This is the sample changeset:
- changeSet:
id: 4384721482
author: bashayam
comment: Create foo validator
changes:
- createCollection:
collectionName: foo
options:
$rawJson:
validator:
$jsonSchema:
bsonType: object
required:
- bar
- foobar
properties:
bar:
bsonType: string
description: foo
foobar:
bsonType: string
description: bar
validationAction: error
validationLevel: strict
With the above YAML changeset what happened was, the parsing was successful until the createCollection. So, the collection was created successfully, but the validation rules were not applied, since the YAML wasn't able to parse $rawJson.
Is there a way that this can be achieved? (The parsing should work successfully and the validator must be updated with the rules specified in YAML).
PS:
- I tried the same changeset in JSON and XML format, and it seems to be working fine.
- I have added the following jar files to liquibase/lib folder:
- jackson-annotations-2.11.3.jar,
- jackson-core-2.11.3.jar,
- jackson-databind-2.11.3.jar
- snakeyaml-1.27.jar
- mongodb-driver-sync-2.3.jar
- mongodb-driver-core-2.3.jar
in addition to the liquibase maven extension jar and mongo java driver jar.
This seems still not to work. I'm trying to create a view instead of a collection and provide the corresponding options. It seems to work in JSON and XML but doesn't work in YAML e.g.:
databaseChangeLog:
- changeSet:
id: 1
author: alevik
comment: drop leads view if exists
runAlways: true
failOnError: true
changes:
- dropCollection:
collectionName: leads
- changeSet:
id: 2
author: [email protected]
comment: create leads view
runAlways: true
failOnError: true
changes:
- createCollection:
collectionName: leads
options:
- $rawjson:
- viewOn: leadevents
The changeset above works, however, the options are being ignored which could be seen in the debug messages of liquibase:
[2022-09-01 12:01:22] FINE [liquibase.util] Computed checksum for createCollection:[
collectionName="leads"
] as e586c47353eda5910766997768da6600
Collection is being created as a regular collection, not a view since the corresponding options are being ignored (in the real example I also provide the pipeline for the view creation but omitted it here for brevity)