circles-learning-labs / ecto_adapters_dynamodb

DynamoDB adapter for Elixir's Ecto Database layer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle multi-index migrations

darrenklein opened this issue · comments

Production DynamoDB does not allow for the simultaneous creation of multiple indexes - so the migration

    alter table(:testing,
      options: [
        global_indexes: [
          [index_name: "foo",
            keys: [:foo],
            create_if_not_exists: true],
          [index_name: "bar",
            keys: [:bar],
            create_if_not_exists: true]
        ]
      ]) do

      add :foo, :string, hash_key: true
      add :bar,  :string, hash_key: true
    end

will fail with the error

{:error, {\"LimitExceededException\", \"Subscriber limit exceeded: Only 1 online index can be created or deleted simultaneously per table\"}}

However, the local development version of DynamoDB will not provide an error or warning, it will just hang until it times out.

This needs some consideration - do we want to devise a way to support multi-index migrations, or just adhere to Dynamo's default behavior? Regardless, we need some way to detect this when running against local DDB.

Not every error or behaviour needs to be handled if incorrect input is provided by the user, as long as what we do support is explicit. We already state that only what we explicitly support should be considered supported.

We can decide to scrap this whole thing - but I didn't want to forget it.

Turns out this isn't an issue - local DynamoDB does correctly report this error. It looked to me like local DDB was hanging when trying to migrate two indexes simultaneously, but it's actually just because we've disabled :info logging when running tests - what I thought was a hang was actually just the function correctly recursing until the timeout expired.