From 4aa4f20dcb88640a3b1d62da73042638a08450cc Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Fri, 6 Nov 2026 16:27:09 +0100 Subject: [PATCH 1/3] docs(typegen): document --workdir and --remote= for gen types --- MIGRATION.md | 5 +++- packages/supabase_typegen/README.md | 15 +++++++++++ .../skills/supabase-typegen-generate/SKILL.md | 27 +++++++++++++------ skills_src/generate/SKILL.md.tmpl | 27 +++++++++++++------ 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 684e844f3..61cc25153 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -90,7 +90,10 @@ dart pub add dev:supabase_typegen supabase gen types --lang dart > lib/supabase_schema.g.dart ``` -`--remote` generates from the linked project and `--remote=` from any hosted project; see the +`--remote` generates from the linked project, `--remote=` from any hosted project and +`--remote=` from any Postgres database. The CLI finds the `supabase/` directory in the +current directory or its parents; pass `--workdir` with the directory that contains it when it is +elsewhere. See the [`supabase_typegen` README](https://github.com/supabase/supabase-flutter/blob/main/packages/supabase_typegen/README.md) for details. diff --git a/packages/supabase_typegen/README.md b/packages/supabase_typegen/README.md index 288c9d8e7..18eab191f 100644 --- a/packages/supabase_typegen/README.md +++ b/packages/supabase_typegen/README.md @@ -94,8 +94,23 @@ supabase gen types --lang dart > lib/supabase_schema.g.dart # The project linked with `supabase link`, or any project by ref. supabase gen types --lang dart --remote > lib/supabase_schema.g.dart supabase gen types --lang dart --remote=abcdefghijklmnopqrst > lib/supabase_schema.g.dart + +# Any Postgres database, by connection string. +supabase gen types --lang dart --remote=postgresql://postgres:postgres@127.0.0.1:54322/postgres > lib/supabase_schema.g.dart +``` + +The CLI looks for the `supabase/` directory in the current directory and its +parents only. When it is elsewhere, such as in a sibling directory of the +app, keep running the command from the app and pass the directory that +contains `supabase/` with `--workdir`: + +```sh +supabase gen types --lang dart --workdir ../backend > lib/supabase_schema.g.dart ``` +The `--local` and `--db-url` flags of older CLI versions are deprecated: the +local stack is the default, and `--remote=` replaces `--db-url`. + The CLI introspects the database into the `GeneratorMetadata` document of [`@supabase/postgrest-typegen`](https://github.com/supabase/sdk/tree/main/packages/postgrest-typegen), the intermediate representation its TypeScript, Go, Swift and Python diff --git a/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md b/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md index a2571f307..073997ac0 100644 --- a/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md +++ b/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md @@ -43,9 +43,11 @@ schema on stdin, and the generated code arrives on stdout. - Regenerate after upgrading `supabase_typegen` or the Supabase CLI, since the generated code can change between versions. - Commit the generated file, so the app builds without a database. -- Run the command from the directory of the app's `pubspec.yaml`. The CLI - finds the `supabase/` folder in that directory or any parent, and runs the - generator where it was started. +- Run the command from the directory of the app's `pubspec.yaml`, since the + CLI runs the generator where it was started. The CLI looks for the + `supabase/` folder in that directory and its parents only. When the folder + is elsewhere, such as in a sibling directory of the app, pass the directory + that contains it with `--workdir`. ## Setup @@ -61,16 +63,25 @@ of the package the file is written into, since the CLI runs it with Pick the database to read from: -| Source | Command | -| -------------------------------------------------------------------- | ---------------------------------------------------------------------------- | -| Local stack from the `supabase/` migrations (after `supabase start`) | `supabase gen types --lang dart > lib/supabase_schema.g.dart` | -| The project linked with `supabase link` | `supabase gen types --lang dart --remote > lib/supabase_schema.g.dart` | -| Any hosted project | `supabase gen types --lang dart --remote= > lib/supabase_schema.g.dart` | +| Source | Command | +| -------------------------------------------------------------------- | ------------------------------------------------------------------------------- | +| Local stack from the `supabase/` migrations (after `supabase start`) | `supabase gen types --lang dart > lib/supabase_schema.g.dart` | +| Local stack whose `supabase/` folder is not in a parent directory | `supabase gen types --lang dart --workdir > lib/supabase_schema.g.dart` | +| The project linked with `supabase link` | `supabase gen types --lang dart --remote > lib/supabase_schema.g.dart` | +| Any hosted project | `supabase gen types --lang dart --remote= > lib/supabase_schema.g.dart` | +| Any Postgres database, by connection string | `supabase gen types --lang dart --remote= > lib/supabase_schema.g.dart` | Prefer the local stack when the project keeps its schema as migrations, so the SQL in `supabase/migrations` stays the source of truth. It needs Docker and a running stack. +`` is the directory that contains `supabase/`, not the `supabase/` folder +itself. `` is a `postgresql://` URL with the password in it, such as +`postgresql://postgres:postgres@127.0.0.1:54322/postgres` for a local stack on +the default ports. The `--local` and `--db-url` flags of older CLI versions are +deprecated: the local stack is the default, and `--remote=` replaces +`--db-url`. + Without `--schema`, the CLI generates `public` plus the schemas listed in `api.schemas` of `supabase/config.toml`. Pass `--schema` once per schema to choose them yourself: diff --git a/skills_src/generate/SKILL.md.tmpl b/skills_src/generate/SKILL.md.tmpl index 24d74a110..5116b5b61 100644 --- a/skills_src/generate/SKILL.md.tmpl +++ b/skills_src/generate/SKILL.md.tmpl @@ -43,9 +43,11 @@ schema on stdin, and the generated code arrives on stdout. - Regenerate after upgrading `supabase_typegen` or the Supabase CLI, since the generated code can change between versions. - Commit the generated file, so the app builds without a database. -- Run the command from the directory of the app's `pubspec.yaml`. The CLI - finds the `supabase/` folder in that directory or any parent, and runs the - generator where it was started. +- Run the command from the directory of the app's `pubspec.yaml`, since the + CLI runs the generator where it was started. The CLI looks for the + `supabase/` folder in that directory and its parents only. When the folder + is elsewhere, such as in a sibling directory of the app, pass the directory + that contains it with `--workdir`. ## Setup @@ -61,16 +63,25 @@ of the package the file is written into, since the CLI runs it with Pick the database to read from: -| Source | Command | -| -------------------------------------------------------------------- | ---------------------------------------------------------------------------- | -| Local stack from the `supabase/` migrations (after `supabase start`) | `supabase gen types --lang dart > lib/supabase_schema.g.dart` | -| The project linked with `supabase link` | `supabase gen types --lang dart --remote > lib/supabase_schema.g.dart` | -| Any hosted project | `supabase gen types --lang dart --remote= > lib/supabase_schema.g.dart` | +| Source | Command | +| -------------------------------------------------------------------- | ------------------------------------------------------------------------------- | +| Local stack from the `supabase/` migrations (after `supabase start`) | `supabase gen types --lang dart > lib/supabase_schema.g.dart` | +| Local stack whose `supabase/` folder is not in a parent directory | `supabase gen types --lang dart --workdir > lib/supabase_schema.g.dart` | +| The project linked with `supabase link` | `supabase gen types --lang dart --remote > lib/supabase_schema.g.dart` | +| Any hosted project | `supabase gen types --lang dart --remote= > lib/supabase_schema.g.dart` | +| Any Postgres database, by connection string | `supabase gen types --lang dart --remote= > lib/supabase_schema.g.dart` | Prefer the local stack when the project keeps its schema as migrations, so the SQL in `supabase/migrations` stays the source of truth. It needs Docker and a running stack. +`` is the directory that contains `supabase/`, not the `supabase/` folder +itself. `` is a `postgresql://` URL with the password in it, such as +`postgresql://postgres:postgres@127.0.0.1:54322/postgres` for a local stack on +the default ports. The `--local` and `--db-url` flags of older CLI versions are +deprecated: the local stack is the default, and `--remote=` replaces +`--db-url`. + Without `--schema`, the CLI generates `public` plus the schemas listed in `api.schemas` of `supabase/config.toml`. Pass `--schema` once per schema to choose them yourself: From d836b9d7d66d92a0a3aa98ece111d96296c18214 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Fri, 6 Nov 2026 16:34:59 +0100 Subject: [PATCH 2/3] docs(typegen): address review feedback on database URLs and --workdir --- packages/supabase_typegen/README.md | 8 +++++--- .../skills/supabase-typegen-generate/SKILL.md | 11 ++++++++--- skills_src/generate/SKILL.md.tmpl | 11 ++++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/supabase_typegen/README.md b/packages/supabase_typegen/README.md index 18eab191f..43fd090d1 100644 --- a/packages/supabase_typegen/README.md +++ b/packages/supabase_typegen/README.md @@ -95,16 +95,18 @@ supabase gen types --lang dart > lib/supabase_schema.g.dart supabase gen types --lang dart --remote > lib/supabase_schema.g.dart supabase gen types --lang dart --remote=abcdefghijklmnopqrst > lib/supabase_schema.g.dart -# Any Postgres database, by connection string. -supabase gen types --lang dart --remote=postgresql://postgres:postgres@127.0.0.1:54322/postgres > lib/supabase_schema.g.dart +# Any Postgres database, by its postgresql:// URL with the password in it. +supabase gen types --lang dart --remote="$DATABASE_URL" > lib/supabase_schema.g.dart ``` The CLI looks for the `supabase/` directory in the current directory and its parents only. When it is elsewhere, such as in a sibling directory of the app, keep running the command from the app and pass the directory that -contains `supabase/` with `--workdir`: +contains `supabase/` with `--workdir`, also to the commands that change the +local stack: ```sh +supabase migration up --workdir ../backend supabase gen types --lang dart --workdir ../backend > lib/supabase_schema.g.dart ``` diff --git a/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md b/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md index 073997ac0..296ec5267 100644 --- a/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md +++ b/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md @@ -76,9 +76,14 @@ SQL in `supabase/migrations` stays the source of truth. It needs Docker and a running stack. `` is the directory that contains `supabase/`, not the `supabase/` folder -itself. `` is a `postgresql://` URL with the password in it, such as -`postgresql://postgres:postgres@127.0.0.1:54322/postgres` for a local stack on -the default ports. The `--local` and `--db-url` flags of older CLI versions are +itself. Pass the same `--workdir` to `supabase migration up` and +`supabase db reset`, or they act on a different stack than the one the types +are generated from. `` is a `postgresql://` URL with the password in +it, such as `postgresql://postgres:postgres@127.0.0.1:54322/postgres` for a +local stack on the default ports. Quote it, since an `&` in its query string +splits the command. For any other database, ask the user to put the URL in an +environment variable and pass `--remote="$DATABASE_URL"`, so the password +never appears in a command or its output. The `--local` and `--db-url` flags of older CLI versions are deprecated: the local stack is the default, and `--remote=` replaces `--db-url`. diff --git a/skills_src/generate/SKILL.md.tmpl b/skills_src/generate/SKILL.md.tmpl index 5116b5b61..a765a58b2 100644 --- a/skills_src/generate/SKILL.md.tmpl +++ b/skills_src/generate/SKILL.md.tmpl @@ -76,9 +76,14 @@ SQL in `supabase/migrations` stays the source of truth. It needs Docker and a running stack. `` is the directory that contains `supabase/`, not the `supabase/` folder -itself. `` is a `postgresql://` URL with the password in it, such as -`postgresql://postgres:postgres@127.0.0.1:54322/postgres` for a local stack on -the default ports. The `--local` and `--db-url` flags of older CLI versions are +itself. Pass the same `--workdir` to `supabase migration up` and +`supabase db reset`, or they act on a different stack than the one the types +are generated from. `` is a `postgresql://` URL with the password in +it, such as `postgresql://postgres:postgres@127.0.0.1:54322/postgres` for a +local stack on the default ports. Quote it, since an `&` in its query string +splits the command. For any other database, ask the user to put the URL in an +environment variable and pass `--remote="$DATABASE_URL"`, so the password +never appears in a command or its output. The `--local` and `--db-url` flags of older CLI versions are deprecated: the local stack is the default, and `--remote=` replaces `--db-url`. From 070d404af084b877ec5946135f484d5ec9c7b7b6 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Fri, 6 Nov 2026 16:53:17 +0100 Subject: [PATCH 3/3] docs(typegen): pass --workdir to supabase start and qualify the password note --- .../skills/supabase-typegen-generate/SKILL.md | 35 ++++++++++--------- skills_src/generate/SKILL.md.tmpl | 35 ++++++++++--------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md b/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md index 296ec5267..3b47c8bbf 100644 --- a/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md +++ b/packages/supabase_typegen/skills/supabase-typegen-generate/SKILL.md @@ -76,16 +76,17 @@ SQL in `supabase/migrations` stays the source of truth. It needs Docker and a running stack. `` is the directory that contains `supabase/`, not the `supabase/` folder -itself. Pass the same `--workdir` to `supabase migration up` and -`supabase db reset`, or they act on a different stack than the one the types -are generated from. `` is a `postgresql://` URL with the password in +itself. Pass the same `--workdir` to `supabase start`, `supabase migration up` +and `supabase db reset`, or they act on a different stack than the one the +types are generated from. `` is a `postgresql://` URL with the password in it, such as `postgresql://postgres:postgres@127.0.0.1:54322/postgres` for a local stack on the default ports. Quote it, since an `&` in its query string splits the command. For any other database, ask the user to put the URL in an -environment variable and pass `--remote="$DATABASE_URL"`, so the password -never appears in a command or its output. The `--local` and `--db-url` flags of older CLI versions are -deprecated: the local stack is the default, and `--remote=` replaces -`--db-url`. +environment variable and pass `--remote="$DATABASE_URL"`, so the password is +not written into the command you run or printed in its output. The shell +still expands it into the arguments of the `supabase` process. The `--local` +and `--db-url` flags of older CLI versions are deprecated: the local stack is +the default, and `--remote=` replaces `--db-url`. Without `--schema`, the CLI generates `public` plus the schemas listed in `api.schemas` of `supabase/config.toml`. Pass `--schema` once per schema to @@ -161,13 +162,13 @@ The CLI reports a generator failure as `failed to generate dart types: dart run supabase_typegen exited with code N: …`, followed by the generator's own message. -| Symptom | Fix | -| ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | -| `dart run` cannot find `supabase_typegen` | Add the dev dependency and run `pub get` in the directory the command runs in. | -| `The project is on Dart X, but the generated code needs Dart Y or newer` | Raise the lower bound of `environment.sdk` in `pubspec.yaml`. | -| `The database has no schema "x"` | Check the schema name, or that the stack has run the migration that creates it. | -| `The project resolves supabase_flutter 2.x, but the generated code needs version 3 of supabase_flutter` | Upgrade the package to version 3 following `MIGRATION.md`, then run `pub get`. | -| `The document describes no tables, views, enums or functions` | Check the schema names, or that the stack has run the migrations. | -| `The document has no "rpcFunctions" collection, so no RPC methods are generated` | Upgrade the Supabase CLI to the latest release and regenerate. | -| `--lang dart` is rejected | Upgrade the Supabase CLI to 3.0.0 or newer. | -| The CLI cannot reach the local database | Run `supabase start` first. | +| Symptom | Fix | +| ------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | +| `dart run` cannot find `supabase_typegen` | Add the dev dependency and run `pub get` in the directory the command runs in. | +| `The project is on Dart X, but the generated code needs Dart Y or newer` | Raise the lower bound of `environment.sdk` in `pubspec.yaml`. | +| `The database has no schema "x"` | Check the schema name, or that the stack has run the migration that creates it. | +| `The project resolves supabase_flutter 2.x, but the generated code needs version 3 of supabase_flutter` | Upgrade the package to version 3 following `MIGRATION.md`, then run `pub get`. | +| `The document describes no tables, views, enums or functions` | Check the schema names, or that the stack has run the migrations. | +| `The document has no "rpcFunctions" collection, so no RPC methods are generated` | Upgrade the Supabase CLI to the latest release and regenerate. | +| `--lang dart` is rejected | Upgrade the Supabase CLI to 3.0.0 or newer. | +| The CLI cannot reach the local database | Run `supabase start` first, with the same `--workdir` as the generation command. | diff --git a/skills_src/generate/SKILL.md.tmpl b/skills_src/generate/SKILL.md.tmpl index a765a58b2..1df2d42b5 100644 --- a/skills_src/generate/SKILL.md.tmpl +++ b/skills_src/generate/SKILL.md.tmpl @@ -76,16 +76,17 @@ SQL in `supabase/migrations` stays the source of truth. It needs Docker and a running stack. `` is the directory that contains `supabase/`, not the `supabase/` folder -itself. Pass the same `--workdir` to `supabase migration up` and -`supabase db reset`, or they act on a different stack than the one the types -are generated from. `` is a `postgresql://` URL with the password in +itself. Pass the same `--workdir` to `supabase start`, `supabase migration up` +and `supabase db reset`, or they act on a different stack than the one the +types are generated from. `` is a `postgresql://` URL with the password in it, such as `postgresql://postgres:postgres@127.0.0.1:54322/postgres` for a local stack on the default ports. Quote it, since an `&` in its query string splits the command. For any other database, ask the user to put the URL in an -environment variable and pass `--remote="$DATABASE_URL"`, so the password -never appears in a command or its output. The `--local` and `--db-url` flags of older CLI versions are -deprecated: the local stack is the default, and `--remote=` replaces -`--db-url`. +environment variable and pass `--remote="$DATABASE_URL"`, so the password is +not written into the command you run or printed in its output. The shell +still expands it into the arguments of the `supabase` process. The `--local` +and `--db-url` flags of older CLI versions are deprecated: the local stack is +the default, and `--remote=` replaces `--db-url`. Without `--schema`, the CLI generates `public` plus the schemas listed in `api.schemas` of `supabase/config.toml`. Pass `--schema` once per schema to @@ -161,13 +162,13 @@ The CLI reports a generator failure as `failed to generate dart types: dart run supabase_typegen exited with code N: …`, followed by the generator's own message. -| Symptom | Fix | -| ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | -| `dart run` cannot find `supabase_typegen` | Add the dev dependency and run `pub get` in the directory the command runs in. | -| `The project is on Dart X, but the generated code needs Dart Y or newer` | Raise the lower bound of `environment.sdk` in `pubspec.yaml`. | -| `The database has no schema "x"` | Check the schema name, or that the stack has run the migration that creates it. | -| `The project resolves supabase_flutter 2.x, but the generated code needs version 3 of supabase_flutter` | Upgrade the package to version 3 following `MIGRATION.md`, then run `pub get`. | -| `The document describes no tables, views, enums or functions` | Check the schema names, or that the stack has run the migrations. | -| `The document has no "rpcFunctions" collection, so no RPC methods are generated` | Upgrade the Supabase CLI to the latest release and regenerate. | -| `--lang dart` is rejected | Upgrade the Supabase CLI to 3.0.0 or newer. | -| The CLI cannot reach the local database | Run `supabase start` first. | +| Symptom | Fix | +| ------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | +| `dart run` cannot find `supabase_typegen` | Add the dev dependency and run `pub get` in the directory the command runs in. | +| `The project is on Dart X, but the generated code needs Dart Y or newer` | Raise the lower bound of `environment.sdk` in `pubspec.yaml`. | +| `The database has no schema "x"` | Check the schema name, or that the stack has run the migration that creates it. | +| `The project resolves supabase_flutter 2.x, but the generated code needs version 3 of supabase_flutter` | Upgrade the package to version 3 following `MIGRATION.md`, then run `pub get`. | +| `The document describes no tables, views, enums or functions` | Check the schema names, or that the stack has run the migrations. | +| `The document has no "rpcFunctions" collection, so no RPC methods are generated` | Upgrade the Supabase CLI to the latest release and regenerate. | +| `--lang dart` is rejected | Upgrade the Supabase CLI to 3.0.0 or newer. | +| The CLI cannot reach the local database | Run `supabase start` first, with the same `--workdir` as the generation command. |