-
Notifications
You must be signed in to change notification settings - Fork 804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(vet): Run rules against a managed database #2751
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0d8d73d
feat(vet): Support managed databases
kyleconroy 8dfde57
feat(vet): Run rules against a managed database
kyleconroy c20dc5a
remove skip
kyleconroy e27afd3
fix read file error
kyleconroy e8812d8
Add managed to JSON schema
kyleconroy a3aa231
Use different hostname for region discovery
kyleconroy d12a8a6
Add first pass at docs
kyleconroy ffaf99e
docs: second pass at managed-databases.md
andrewmbenton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Managed databases | ||
|
||
*Added in v1.22.0* | ||
|
||
`sqlc` can create and maintain hosted databases for your project. These | ||
databases are immediately useful for linting queries with [`sqlc vet`](vet.md) | ||
if your lint rules require a connection to a running database. PostgreSQL | ||
support is available today, with MySQL on the way. | ||
|
||
This feature is under active development, and we're interested in supporting | ||
other use-cases. Beyond linting queries, you can use sqlc managed databases | ||
in your tests to quickly stand up a database per test suite or even per test, | ||
providing a real, isolated database for a test run. No cleanup required. | ||
|
||
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 | ||
at <mailto:[email protected]>. | ||
|
||
## Configuring managed databases | ||
|
||
To configure `sqlc` to use a managed database, remove the `uri` key from your | ||
`database` configuration and replace it with the `managed` key set to `true`. | ||
Set the `project` key in your `cloud` configuration to the value of your | ||
project ID, obtained via the sqlc.dev Dashboard. | ||
|
||
```yaml | ||
version: '2' | ||
cloud: | ||
project: '<PROJECT_ID>' | ||
sql: | ||
- schema: schema.sql | ||
queries: query.sql | ||
engine: postgresql | ||
database: | ||
managed: true | ||
``` | ||
|
||
## Authentication | ||
|
||
`sqlc` expects to find a valid auth token in the value of the `SQLC_AUTH_TOKEN` | ||
environment variable. You can create an auth token via the sqlc.dev Dashboard. | ||
|
||
```shell | ||
export SQLC_AUTH_TOKEN=sqlc_xxxxxxxx | ||
``` | ||
|
||
## Linting queries | ||
|
||
With managed databases configured, `sqlc vet` will create a database with your | ||
package's schema and use that database when running lint rules that require a | ||
database connection, e.g. any [rule relying on `EXPLAIN ...` output](vet.md#rules-using-explain-output). | ||
|
||
If you don't yet have any vet rules, the [built-in sqlc/db-prepare rule](vet.md#sqlc-db-prepare) | ||
is a good place to start. It prepares each of your queries against the database | ||
to ensure the query is valid. Here's a minimal working configuration: | ||
|
||
```yaml | ||
version: '2' | ||
cloud: | ||
project: '<PROJECT_ID>' | ||
sql: | ||
- schema: schema.sql | ||
queries: query.sql | ||
engine: postgresql | ||
database: | ||
managed: true | ||
rules: | ||
- sqlc/db-prepare | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,9 @@ | |
"properties": { | ||
"uri": { | ||
"type": "string" | ||
}, | ||
"managed": { | ||
"type": "boolean" | ||
} | ||
} | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,9 @@ | |
"properties": { | ||
"uri": { | ||
"type": "string" | ||
}, | ||
"managed": { | ||
"type": "boolean" | ||
} | ||
} | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that
vet
is also using the project configuration, we can't default to remote generation. Instead, allow users to opt in with the--remote
flag.