You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(vet): Run rules against a managed database (#2751)
* feat(vet): Support managed databases * feat(vet): Run rules against a managed database * Add managed to JSON schema * Use different hostname for region discovery * docs: second pass at managed-databases.md --------- Co-authored-by: Andrew Benton <andrew@sqlc.dev>
`sqlc` can create and maintain hosted databases for your project. These
6
+
databases are immediately useful for linting queries with [`sqlc vet`](vet.md)
7
+
if your lint rules require a connection to a running database. PostgreSQL
8
+
support is available today, with MySQL on the way.
9
+
10
+
This feature is under active development, and we're interested in supporting
11
+
other use-cases. Beyond linting queries, you can use sqlc managed databases
12
+
in your tests to quickly stand up a database per test suite or even per test,
13
+
providing a real, isolated database for a test run. No cleanup required.
14
+
15
+
Interested in trying out managed databases? Sign up [here](https://docs.google.com/forms/d/e/1FAIpQLSdxoMzJ7rKkBpuez-KyBcPNyckYV-5iMR--FRB7WnhvAmEvKg/viewform) or send us an email
16
+
at <mailto:hello@sqlc.dev>.
17
+
18
+
## Configuring managed databases
19
+
20
+
To configure `sqlc` to use a managed database, remove the `uri` key from your
21
+
`database` configuration and replace it with the `managed` key set to `true`.
22
+
Set the `project` key in your `cloud` configuration to the value of your
23
+
project ID, obtained via the sqlc.dev Dashboard.
24
+
25
+
```yaml
26
+
version: '2'
27
+
cloud:
28
+
project: '<PROJECT_ID>'
29
+
sql:
30
+
- schema: schema.sql
31
+
queries: query.sql
32
+
engine: postgresql
33
+
database:
34
+
managed: true
35
+
```
36
+
37
+
## Authentication
38
+
39
+
`sqlc` expects to find a valid auth token in the value of the `SQLC_AUTH_TOKEN`
40
+
environment variable. You can create an auth token via the sqlc.dev Dashboard.
41
+
42
+
```shell
43
+
export SQLC_AUTH_TOKEN=sqlc_xxxxxxxx
44
+
```
45
+
46
+
## Linting queries
47
+
48
+
With managed databases configured, `sqlc vet` will create a database with your
49
+
package's schema and use that database when running lint rules that require a
50
+
database connection, e.g. any [rule relying on `EXPLAIN ...` output](vet.md#rules-using-explain-output).
51
+
52
+
If you don't yet have any vet rules, the [built-in sqlc/db-prepare rule](vet.md#sqlc-db-prepare)
53
+
is a good place to start. It prepares each of your queries against the database
54
+
to ensure the query is valid. Here's a minimal working configuration:
0 commit comments