liquibase / liquibase-mongodb

MongoDB extension for Liquibase
Apache License 2.0
54 stars 45 forks source link

Does YAML support raw JSON Parser? #129

Open Bashayam opened 3 years ago

Bashayam commented 3 years ago

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:

  1. I tried the same changeset in JSON and XML format, and it seems to be working fine.
  2. I have added the following jar files to liquibase/lib folder:

in addition to the liquibase maven extension jar and mongo java driver jar.

┆Issue is synchronized with this Jira Bug by Unito

psylence303 commented 2 years ago

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: devopsbilling@cloud.ionos.com
      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)