hasura / hasura/graphql-engine

Database source reverts to default when executing schema-altering SQL from the console that you mark as not a migration

Open
#9,657 3 comments 1 reaction 0 assignees View on GitHub
c/console estimate/M k/bug
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Server Version: 2.25.0
CLI Version (for CLI related issue): 2.25.0

### Environment

OSS

### What is the current behaviour?

When executing schema-altering SQL from the SQL page on the CLI console that you mark as not a migration, the source in the resulting query is removed, causing Hasura to try and execute the sql on the default source or give an error if there is no source named as such.

### What is the expected behaviour?

The source should remain set to the source selected in the dropdown on the SQL page in the CLI console.

### How to reproduce the issue?

1. Have a database with a name that is not default with no database named default
2. Open the SQL page in the console and ensure a database whose name is not default is selected
3. Enter schema-altering SQL
4. Disable the _This is a migration_ checkbox
5. Run the SQL
6. In the following warning dialog, accept that the SQL is not a migration and run
7. The error `source with name "default" does not exist` appears

### Please provide any traces or logs that could help here.

**Error Case with Migration Disabled**

`{"detail":{"http_info":{"content_encoding":null,"http_version":"HTTP/1.1","ip":"172.21.0.1","method":"POST","status":400,"url":"/v2/query"},"operation":{"error":{"code":"not-exists","error":"source with name \"default\" does not exist","path":"$[0]"},"query":{"args":[{"args":{"cascade":false,"read_only":false,"sql":"DROP FUNCTION IF EXISTS detach_recurring();"},"type":"run_sql"}],"type":"bulk"},"request_id":"9b218c77-6d2f-4ee3-aaf6-253fa7979617","request_mode":"error","response_size":89,"uncompressed_response_size":89,"user_vars":{"x-hasura-role":"admin"}},"request_id":"9b218c77-6d2f-4ee3-aaf6-253fa7979617"},"level":"error","timestamp":"2023-05-20T17:48:59.394+0000","type":"http-log"}`

**Success Case with Migration Enabled**

`{"detail":{"http_info":{"content_encoding":null,"http_version":"HTTP/1.1","ip":"172.21.0.1","method":"POST","status":200,"url":"/v2/query"},"operation":{"query":{"args":[{"args":{"cascade":false,"read_only":false,"source":"TCS","sql":"DROP FUNCTION IF EXISTS test_function();"},"type":"run_sql"}],"type":"bulk"},"query_execution_time":0.514101641,"request_id":"82a66104-c1a4-4317-b2d5-ace0dda360b4","request_mode":"non-graphql","request_read_time":9.4e-7,"response_size":43,"uncompressed_response_size":43,"user_vars":{"x-hasura-role":"admin"}},"request_id":"82a66104-c1a4-4317-b2d5-ace0dda360b4"},"level":"info","timestamp":"2023-05-20T18:03:16.670+0000","type":"http-log"}`

Note that the source field is missing in the error case.

### Any possible solutions/workarounds you're aware of?

Obviously, just executing non-migration SQL outside of the console still works.

### Keywords

sql
migration
default

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.