Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typesense_collection does not support auto schema #22

Open
jon-flowers opened this issue Apr 28, 2022 · 0 comments
Open

typesense_collection does not support auto schema #22

jon-flowers opened this issue Apr 28, 2022 · 0 comments

Comments

@jon-flowers
Copy link

Typesense allows you to use an auto-detected schema (see https://typesense.org/docs/0.22.2/api/collections.html#with-auto-schema-detection)

With this Terraform provider, you can create a collection with an auto schema fairly easily, using something like the code below

resource "typesense_collection" "test_collection" {
  name = "test_collection"

  fields {
    name = ".*"
    type = "auto"
    optional = true
  }
}

This will create fine. However, once you start populating documents into Typesense, the schema will add fields. When this happens, future Terraform applies will result in the new fields being called out as needing to be removed, and the whole collection will be replaced. This causes all documents to get deleted. Example, where the new documents had a single location field that was added to the schema:

  # typesense_collection.test_collection must be replaced
-/+ resource "typesense_collection" "test_collection" {
      ~ id            = "test_collection" -> (known after apply)
        name          = "test_collection"
      ~ num_documents = 14 -> (known after apply)

      ~ fields {
          ~ facet    = false -> (known after apply)
            index    = true
            name     = ".*"
            optional = true
            type     = "auto"
        }
      - fields {
          - facet    = false -> null
          - index    = true -> null
          - name     = "location" -> null
          - optional = true -> null
          - type     = "string" -> null # forces replacement
        }

I noticed this because I was creating the collection with the auto schema, and then creating the typesense_sync document that backfilled the data. On the next apply, which should have had no changes, it indicated my collection would need to be replaced. The backfill will then not occur again until you update or replace the sync document, in which case the process starts over.

Is there a way to do this so that auto schema will work with this Terraform provider? Or will only a pre-defined schema work as expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant