Skip to content

Commit

Permalink
docs: Add migration guide for hosted managed databases (sqlc-dev#3417)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy authored and lisitsky committed Jun 21, 2024
1 parent b284315 commit a3d3b4f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
3 changes: 0 additions & 3 deletions docs/_templates/breadcrumbs.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

{% block breadcrumbs %}
{% if show_banner %}
<header id="banner">
<div>Join the wait list for <a href="https://bm2gstcnhch.typeform.com/to/fV96Dsyf">BigQuery</a>, <a href="https://bm2gstcnhch.typeform.com/to/fV96Dsyf">ClickHouse</a>, <a href="https://bm2gstcnhch.typeform.com/to/fV96Dsyf">MSSQL</a>, or <a href="https://bm2gstcnhch.typeform.com/to/fV96Dsyf">Spanner</a> today.</div>
</header>
{% endif %}
{{ super() }}
{% endblock %}
71 changes: 71 additions & 0 deletions docs/guides/migrating-off-hosted-managed-databases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Migrating off hosted managed databases

Starting in sqlc 1.27.0, [managed databases](../docs/managed-databases.md) will require a database server URI in the configuration file.

This guide walks you through migrating to a locally running database server.

## Run a database server locally

There are many options for running a database server locally, but this guide
will use [Docker Compose](https://docs.docker.com/compose/), as it can support
both MySQL and PostgreSQL.

If you're using macOS and PostgreSQL, [Postgres.app](https://postgresapp.com/) is also a good option.

For MySQL, create a `docker-compose.yml` file with the following contents:

```yaml
version: "3.8"
services:
mysql:
image: "mysql/mysql-server:8.0"
ports:
- "3306:3306"
restart: always
environment:
MYSQL_DATABASE: dinotest
MYSQL_ROOT_PASSWORD: mysecretpassword
MYSQL_ROOT_HOST: '%'
```
For PostgreSQL, create a `docker-compose.yml` file with the following contents:

```yaml
version: "3.8"
services:
postgresql:
image: "postgres:16"
ports:
- "5432:5432"
restart: always
environment:
POSTGRES_DB: postgres
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_USER: postgres
```

```sh
docker compose up -d
```

## Upgrade sqlc

You must be running sqlc v1.27.0 or greater to have access to the `servers`
configuration.

## Add servers to configuration

```diff
version: '2'
cloud:
project: '<PROJECT_ID>'
+ servers:
+ - name: mysql
+ uri: mysql://localhost:3306
+ - name: postgres
+ uri: postgres://localhost:5432/postgres?sslmode=disable
```

## Re-generate the code

Run `sqlc generate`. A database with the `sqlc_managed_` prefix will be automatically created and used for query analysis.

0 comments on commit a3d3b4f

Please sign in to comment.