Running SQL queries via Marvin
Once in a while people ask me to run some sort of SQL query on the production or staging database. In other instances one might ask for direct DB access.
Instead I propose that Marvin can run SQL queries on either the production or staging database, with staging being the default. Using PostgreSQL permissions and what not we can restrict access pretty decently. For example:
- We set the statement timeout to 5 seconds
- The user used for running queries only has the
SELECT
permission, preventing it from accidentally removing data - If I'm not mistaken we can even deny access to specific columns, preventing one from being able to access e.g. salted user passwords or OTP tokens
On top of that we should start with a restricted number of users that can do this.
Example use case that I'm thinking of:
@yorickpeterse: @marvin query production SELECT COUNT(*) FROM users;
@marvin:
count
--------
257538
(1 row)
Time: 30,517 ms
So the command syntax would be:
query [production | staging] [SQL query until a semicolon or EOF]