0

We're experiencing a weird problem in Hasura. We added a unique key in our postgres DB (via rails) and we can see it's there when we do a query in Hasura

SELECT tablename, indexname, indexdef
FROM pg_indexes
WHERE tablename = 'customers';


customers   customers_pkey  CREATE UNIQUE INDEX customers_pkey ON public.customers USING btree (id)
customers   customers_merchant_id_email_key CREATE UNIQUE INDEX customers_merchant_id_email_key ON public.customers USING btree (merchant_id, email)

but when we view the table it displays nothing and displays

**Unique Keys**
[Add] No unique keys

and even if adding it (by clicking [Add] button) it says it exists

**Saving unique key failed**
postgres-error : relation "customers_merchant_id_email_key" already exists

Also, upon doing an "upsert" on the table using the constraint, it says it does not exist.

mutation MyMutation {
  insert_customers(
    objects: {
      email: "asdf@gmail.com", 
      merchant_id: "5792121d-4423-4a1e-8612-7fc090f2e71a", 
      first_name: "Foobar",
      last_name: "Test"
    },
    on_conflict: {
      constraint: customers_merchant_id_email_key,
      update_columns: [first_name, last_name]
    }
  ) 
  {
    returning {
      id
    }
  }
}


{
  "errors": [
    {
      "extensions": {
        "path": "$.selectionSet.insert_customers.args.objects",
        "code": "constraint-error"
      },
      "message": "constraint \"customers_merchant_id_email_key\" for table \"customers\" does not exist"
    }
  ]
}

Are we missing something?

index
  • 3,697
  • 7
  • 36
  • 55

1 Answers1

0

I got the same issue, I created a new entity with an unique index:

CREATE UNIQUE INDEX UNIQ_92FB68E19B88AF9 ON device (fcm_token)

But unfortunaly in the Hasura console the index does not appear:

Hasura console

But compared to you I am able to add the index manualy without getting an error. So I decided to add it and export my metadata to save the change. But the index is never exported... Nothing new in my table.yaml.

So I cant make any upsert query... And add the index manualy is pretty unconfortable for my deployments processes.

Kaw
  • 21
  • 3