Skip to content

Commit 91606db

Browse files
kyleconroylisitsky
authored andcommitted
docs: Update the managed db and verify documentation (sqlc-dev#3426)
1 parent b9547a9 commit 91606db

File tree

6 files changed

+55
-122
lines changed

6 files changed

+55
-122
lines changed

docs/howto/ci-cd.md

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,54 +80,20 @@ on: [push]
8080
jobs:
8181
vet:
8282
runs-on: ubuntu-latest
83-
services:
84-
postgres:
85-
image: "postgres:15"
86-
env:
87-
POSTGRES_DB: postgres
88-
POSTGRES_PASSWORD: postgres
89-
POSTGRES_USER: postgres
90-
ports:
91-
- 5432:5432
92-
# needed because the postgres container does not provide a healthcheck
93-
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
94-
env:
95-
PG_PORT: ${{ job.services.postgres.ports['5432'] }}
96-
9783
steps:
9884
- uses: actions/checkout@v3
9985
- uses: sqlc-dev/setup-sqlc@v3
10086
with:
10187
sqlc-version: '1.26.0'
102-
# Connect and migrate your database here. This is an example which runs
103-
# commands from a `schema.sql` file.
104-
- run: psql -h localhost -U postgres -p $PG_PORT -d postgres -f schema.sql
105-
env:
106-
PGPASSWORD: postgres
107-
- run: sqlc vet
108-
```
109-
110-
#### Managed databases
111-
112-
```{note}
113-
Managed databases are powered by [sqlc Cloud](https://dashboard.sqlc.dev). Sign up for [free](https://dashboard.sqlc.dev) today.
114-
```
115-
116-
If you're using [managed databases](managed-databases.md), the `services` block
117-
in the previous workflow isn't required.
118-
119-
```yaml
120-
name: sqlc
121-
on: [push]
122-
jobs:
123-
vet:
124-
runs-on: ubuntu-latest
125-
steps:
126-
- uses: actions/checkout@v3
127-
- uses: sqlc-dev/setup-sqlc@v3
88+
# Start a PostgreSQL server
89+
- uses: sqlc-dev/action-setup-postgres@master
12890
with:
129-
sqlc-version: '1.26.0'
91+
postgres-version: "16"
92+
id: postgres
13093
- run: sqlc vet
94+
env:
95+
POSTGRESQL_SERVER_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable
96+
13197
```
13298

13399
### push
@@ -174,8 +140,13 @@ jobs:
174140
- uses: sqlc-dev/setup-sqlc@v3
175141
with:
176142
sqlc-version: '1.26.0'
143+
- uses: sqlc-dev/action-setup-postgres@master
144+
with:
145+
postgres-version: "16"
146+
id: postgres
177147
- run: sqlc verify
178148
env:
149+
POSTGRESQL_SERVER_URI: ${{ steps.postgres.outputs.connection-uri }}?sslmode=disable
179150
SQLC_AUTH_TOKEN: ${{ secrets.SQLC_AUTH_TOKEN }}
180151
push:
181152
runs-on: ubuntu-latest

docs/howto/generate.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,16 @@ support planned in the future.
2727
2828
## Enhanced analysis with managed databases
2929
30-
```{note}
31-
Managed databases are powered by [sqlc Cloud](https://dashboard.sqlc.dev). Sign up for [free](https://dashboard.sqlc.dev) today.
32-
```
33-
3430
With [managed databases](managed-databases.md) configured, `generate` will automatically create a hosted ephemeral database with your
3531
schema and use that database to improve its query analysis. And sqlc will cache its analysis locally
3632
on a per-query basis to speed up future `generate` runs. This saves you the trouble of running and maintaining a database with
3733
an up-to-date schema. Here's a minimal working configuration:
3834

3935
```yaml
4036
version: "2"
41-
cloud:
42-
project: "<PROJECT_ID>"
37+
servers:
38+
- engine: postgresql
39+
uri: "postgres://locahost:5432/postgres?sslmode=disable"
4340
sql:
4441
- engine: "postgresql"
4542
queries: "query.sql"

docs/howto/managed-databases.md

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
# Managed databases
22

3-
```{note}
4-
Managed databases are powered by [sqlc Cloud](https://dashboard.sqlc.dev). Sign up for [free](https://dashboard.sqlc.dev) today.
5-
```
6-
73
*Added in v1.22.0*
84

9-
`sqlc` can create and maintain short-lived hosted databases for your project.
10-
These ephemeral databases are immediately useful for powering sqlc's
11-
database-connected query analyzer, an opt-in feature that improves upon sqlc's
12-
built-in query analysis engine. PostgreSQL support is available today, with
13-
MySQL on the way.
5+
`sqlc` can automatically create read-only databases to power query analysis,
6+
linting and verification. These databases are immediately useful for powering
7+
sqlc's database-connected query analyzer, an opt-in feature that improves upon
8+
sqlc's built-in query analysis engine. PostgreSQL support is available today,
9+
with MySQL on the way.
1410

1511
Once configured, `sqlc` will also use managed databases when linting queries
1612
with [`sqlc vet`](vet.md) in cases where your lint rules require a connection
1713
to a running database.
1814

1915
Managed databases are under active development, and we're interested in
20-
supporting other use-cases. Outside of sqlc itself, you can use our managed
21-
databases in your tests to quickly stand up a database per test suite or even per test,
22-
providing a real, isolated database for a test run. No cleanup required.
16+
supporting other use-cases.
2317

2418
## Configuring managed databases
2519

2620
To configure `sqlc` to use managed databases, remove the `uri` key from your
2721
`database` configuration and replace it with the `managed` key set to `true`.
28-
Set the `project` key in your `cloud` configuration to the value of your
29-
project ID, obtained via the [dashboard](https://dashboard.sqlc.dev).
22+
Access to a running database server is required. Add a connection string to the `servers` mapping.
3023

3124
```yaml
3225
version: '2'
33-
cloud:
34-
project: '<PROJECT_ID>'
26+
servers:
27+
- engine: postgresql
28+
uri: "postgres://locahost:5432/postgres?sslmode=disable"
3529
sql:
3630
- schema: schema.sql
3731
queries: query.sql
@@ -40,13 +34,19 @@ sql:
4034
managed: true
4135
```
4236
43-
### Authentication
37+
An environment variable can also be used via the `${}` syntax.
4438

45-
`sqlc` expects to find a valid auth token in the value of the `SQLC_AUTH_TOKEN`
46-
environment variable. You can create an auth token via the [dashboard](https://dashboard.sqlc.dev).
47-
48-
```shell
49-
export SQLC_AUTH_TOKEN=sqlc_xxxxxxxx
39+
```yaml
40+
version: '2'
41+
servers:
42+
- engine: postgresql
43+
uri: ${DATABASE_URI}
44+
sql:
45+
- schema: schema.sql
46+
queries: query.sql
47+
engine: postgresql
48+
database:
49+
managed: true
5050
```
5151

5252
## Improving codegen
@@ -61,8 +61,9 @@ on a per-query basis to speed up future codegen runs. Here's a minimal working c
6161

6262
```yaml
6363
version: '2'
64-
cloud:
65-
project: '<PROJECT_ID>'
64+
servers:
65+
- engine: postgresql
66+
uri: "postgres://locahost:5432/postgres?sslmode=disable"
6667
sql:
6768
- schema: schema.sql
6869
queries: query.sql
@@ -86,8 +87,9 @@ to ensure the query is valid. Here's a minimal working configuration:
8687

8788
```yaml
8889
version: '2'
89-
cloud:
90-
project: '<PROJECT_ID>'
90+
servers:
91+
- engine: postgresql
92+
uri: "postgres://locahost:5432/postgres?sslmode=disable"
9193
sql:
9294
- schema: schema.sql
9395
queries: query.sql
@@ -97,35 +99,3 @@ sql:
9799
rules:
98100
- sqlc/db-prepare
99101
```
100-
101-
## With other tools
102-
103-
With managed databases configured, `sqlc createdb` will create a hosted ephemeral database with your
104-
schema and write the database's connection URI as a string to standard output (stdout). This allows you to use
105-
ephemeral databases with other tools that understand database connection strings.
106-
107-
In the simplest case, you can use psql to poke around:
108-
109-
```shell
110-
psql $(sqlc createdb)
111-
```
112-
113-
Or if you're tired of waiting for us to resolve https://github.com/sqlc-dev/sqlc/issues/296,
114-
you can create databases ad hoc to use with pgtyped:
115-
116-
```shell
117-
DATABASE_URL=$(sqlc createdb) npx pgtyped -c config.json
118-
```
119-
120-
Here's a minimal working configuration if all you need to use is `sqlc createdb`:
121-
122-
```yaml
123-
version: '2'
124-
cloud:
125-
project: '<PROJECT_ID>'
126-
sql:
127-
- schema: schema.sql
128-
engine: postgresql
129-
database:
130-
managed: true
131-
```

docs/howto/verify.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# `verify` - Verifying schema changes
22

3-
```{note}
4-
`verify` is powered by [sqlc Cloud](https://dashboard.sqlc.dev). Sign up for [free](https://dashboard.sqlc.dev) today.
5-
```
6-
73
*Added in v1.24.0*
84

95
Schema updates and poorly-written queries often bring down production databases. That’s bad.

docs/tutorials/getting-started-mysql.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ database must have the `authors` table as defined in `schema.sql`.
184184
You should now have a working program using sqlc's generated Go source code,
185185
and hopefully can see how you'd use sqlc in your own real-world applications.
186186

187-
## Query analysis and managed databases
187+
## Query verification
188188

189-
[sqlc Cloud](https://dashboard.sqlc.dev) provides additional insights into your
190-
queries, catching subtle bugs and performance issues. To get started, create a
189+
[sqlc Cloud](https://dashboard.sqlc.dev) provides additional verification, catching subtle bugs. To get started, create a
191190
[dashboard account](https://dashboard.sqlc.dev). Once you've signed in, create a
192191
project and generate an auth token. Add your project's ID to the `cloud` block
193192
to your sqlc.yaml.
194193

194+
195195
```yaml
196196
version: "2"
197197
cloud:
@@ -219,7 +219,3 @@ export SQLC_AUTH_TOKEN="<your sqlc auth token>"
219219
```shell
220220
$ sqlc push --tag tutorial
221221
```
222-
223-
In the sidebar, go to the "Insights" section to run checks against your queries.
224-
If you need access to a pre-configured MySQL database, check out [managed
225-
databases](../howto/managed-databases.md).

docs/tutorials/getting-started-postgresql.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,9 @@ database must have the `authors` table as defined in `schema.sql`.
203203
You should now have a working program using sqlc's generated Go source code,
204204
and hopefully can see how you'd use sqlc in your own real-world applications.
205205

206-
## Query analysis and managed databases
206+
## Query verification
207207

208-
[sqlc Cloud](https://dashboard.sqlc.dev) provides additional insights into your
209-
queries, catching subtle bugs and performance issues. To get started, create a
208+
[sqlc Cloud](https://dashboard.sqlc.dev) provides additional verification, catching subtle bugs. To get started, create a
210209
[dashboard account](https://dashboard.sqlc.dev). Once you've signed in, create a
211210
project and generate an auth token. Add your project's ID to the `cloud` block
212211
to your sqlc.yaml.
@@ -240,6 +239,10 @@ export SQLC_AUTH_TOKEN="<your sqlc auth token>"
240239
$ sqlc push --tag tutorial
241240
```
242241

243-
In the sidebar, go to the "Insights" section to run checks against your queries.
244-
If you need access to a pre-configured PostgreSQL database, check out [managed
245-
databases](../howto/managed-databases.md).
242+
In the sidebar, go to the "Queries" section to see your published queries. Run
243+
`verify` to ensure that previously published queries continue to work against
244+
updated database schema.
245+
246+
```shell
247+
$ sqlc verify --against tutorial
248+
```

0 commit comments

Comments
 (0)