explorerhq / explorerhq/sql-explorer
Bug: Removing default connection breaks the app
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 373
- PR merge metrics
- No merged PRs in 30d
Description
## What's the issue
1. As a developer hosting a site using SQL Explorer, for security purposes, I want to use a Read/write database connection for my django app, but I want to only use a Read only database connection for SQL Explorer. In my experience so far, there is no functioning way to do this. Specifically, if I delete the default connection, the query detail pages doesn't allow me to choose another connection.
2. If I try to rename the default connection (or any other connection?) for the view in the UI via EXPLORER_CONNECTIONS, it doesn't seem to do anything. You can play with that pretty easily by modifying the values of that dictionary with the app running, so I didn't provide an example here.
## How to reproduce the issue:
- clone repo
- edit test_app/settings.py:
```
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "tmp",
"TEST": {
"NAME": "tmp"
}
},
"TestSQLite2": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "tmp2",
"TEST": {
"NAME": "tmp2"
}
}
}
EXPLORER_CONNECTIONS = {
"Primary": "default",
"TestSQLite2": "TestSQLite2",
}
EXPLORER_DEFAULT_CONNECTION = "TestSQLite2"
EXPLORER_SQL_BLACKLIST = []
```
- Also Modify `EXPLORER_CHARTS_ENABLED = False` (because it errored out on my machine)
- terminal 1:
- nvm install
- nvm use
- npm install
- npm run dev
- terminal 2:
- python -m venv venv
- source venv/bin/activate
- pip install -e .
- python manage.py createsuperuser --username admin (set pw too)
- python manage.py runserver
- browser:
- go to http://127.0.0.1:8000/explorer
- login with admin/admin
- create connection, alias:TestSQLite2, name: TestSQLite2, type: django db. Click create.
- create query:
```
CREATE TABLE table_name (
column_1 int PRIMARY KEY,
column_2 int NOT NULL,
column_3 int DEFAULT 0
);
```
- save and run
- modify query to: `INSERT INTO table_name values (1,1,1,1),(2,2,2,2),(3,3,3,3);`
- save and run
- modify query to `select * from table_name;`
- save and run
- go to connections page, delete default connection
- go back to /explorer/
- the default query /explorer/1/ doesn't load (because the connection is gone)
- It would be nice if the page loaded but it raised an error saying this connection is invalid, please select another one.
- the new query /explorer/2/ loads, but you can't hit save and run, and you can't select because the dropdown for connections does not function correctly.
- it would be nice if the dropdown populated with all currently existing connections.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.