Serverpod

Generate Serverpod database models from your Supabase schema.

The supabase_codegen_serverpod package generates Serverpod database models (.spy.yaml files) from your Supabase schema.

Installation

Add the package to your Serverpod server project (e.g., my_server_server):

dart pub add supabase_codegen_serverpod

Setup

    Json Class Configuration

    The generator requires a helper class to handle jsonb columns. Run:

    dart run supabase_codegen_serverpod:init
    

    Generator Config

    The init command automatically adds the following to your config/generator.yaml:

    extraClasses:
      - package:supabase_codegen_serverpod/json_class.dart:JsonClass
    

    Environment File

    Place your Supabase credentials in a .env file:

    SUPABASE_URL=https://your-project.supabase.co
    SUPABASE_ANON_KEY=your-anon-key
    

CLI Usage

Generate Serverpod models:

dart run supabase_codegen_serverpod:generate_types

By default, files are generated in lib/src/models. You can change this using the -o or --output flag.

Working with Models

Once the .spy.yaml files are generated, run the Serverpod generator to create the Dart classes:

serverpod generate

Type Mapping

Supabase types are automatically mapped to Serverpod types:

PostgresServerpod
text, uuidString
int4, int8int
boolbool
jsonbJsonClass
timestampDateTime

Exclusions

By default, the generator excludes any tables starting with serverpod to avoid conflicts with Serverpod's internal database structure.