Files
upstream-sqlc/docs/guides/migrating-off-hosted-managed-databases.md
upstream-mirror 0f4df23290
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
2026-09-16 02:17:34 +05:00

1.7 KiB

Migrating off hosted managed databases

Starting in sqlc 1.27.0, managed databases 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, as it can support both MySQL and PostgreSQL.

If you're using macOS and PostgreSQL, Postgres.app is also a good option.

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

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:

version: "3.8"
services:
  postgresql:
    image: "postgres:16"
    ports:
      - "5432:5432"
    restart: always
    environment:
      POSTGRES_DB: postgres
      POSTGRES_PASSWORD: mysecretpassword
      POSTGRES_USER: postgres
docker compose up -d

Upgrade sqlc

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

Add servers to configuration

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.