Checks when creating/altering a FK need to correctly handle revision DBs
- Dominant language
- Go
- Stars
- 24.4k
- Forks
- 873
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 108
Description
A Hosted Dolt customer had a problem running this query in the Workbench, but it works correctly when logged in through a `mysql` client in the terminal:
```sql
ALTER TABLE t ADD CONSTRAINT fk1 FOREIGN KEY (id) REFERENCES other_table(id);
```
The error returned from the Workbench is:
```
only foreign keys on the same database are currently supported
```
We believe this happens because the Hosted Dolt Workbench runs `use /` before each query to make sure the branch selected in the UI is being used for the query. This should be reproducable outside of the Hosted Dolt Workbench by running the same command first.
The foreign key checking code validates that the database for the table being altered (`t` in the example above) as well as the table that is being referenced (`other_table` in the example above) are from the same database, but when a revision database is the active database, this check throws an error when it should not. [See tables.go for more details](https://github.com/dolthub/dolt/blob/4b5e243c4724a2bd1e23ae46f5fbc5c6977911c0/go/libraries/doltcore/sqle/tables.go#L2019).
We should debug through a repro and validate this is indeed what's happening. Assuming the above is correct, then the FK check above should be expanded to work correctly when a revision database is in use.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.