supabase

package
v1.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package supabase implements the Supabase → nSelf migration pipeline.

It connects to a Supabase project via PostgREST + the service_role key, pulls schema, data, auth users, and storage buckets, then generates nSelf-compatible Drizzle migration SQL files, Hasura metadata YAML, an auth user import script, and a human-readable next-steps summary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthUser

type AuthUser struct {
	ID             string `json:"id"`
	Email          string `json:"email"`
	Phone          string `json:"phone"`
	EmailConfirmed bool   `json:"email_confirmed_at"`
	CreatedAt      string `json:"created_at"`
}

AuthUser represents a minimal view of a Supabase auth.users row.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the Supabase REST APIs.

func NewClient

func NewClient(cfg Config) *Client

NewClient creates a Client for the given Supabase project.

func (*Client) PullAuthUsers

func (c *Client) PullAuthUsers(ctx context.Context) ([]AuthUser, error)

PullAuthUsers fetches up to 1 000 users from the Supabase Admin auth API.

func (*Client) PullRLSPolicies

func (c *Client) PullRLSPolicies(ctx context.Context) ([]RLSPolicy, error)

PullRLSPolicies fetches RLS policies from the Supabase project by executing a query against pg_policies via the Supabase Management API SQL endpoint.

The Management API endpoint is:

POST https://api.supabase.com/v1/projects/{ref}/database/query
Authorization: Bearer <service_role_key>
Content-Type: application/json
{"query": "<SQL>"}

If the Management API is unreachable or returns an auth error, an empty slice is returned along with an informational error so the caller can include a manual-review note in the generated migration SQL.

func (*Client) PullSchema

func (c *Client) PullSchema(ctx context.Context) ([]Table, error)

PullSchema fetches tables and columns from the Supabase project. It uses the PostgREST OpenAPI endpoint which returns schema information.

func (*Client) PullStorageBuckets

func (c *Client) PullStorageBuckets(ctx context.Context) ([]StorageBucket, error)

PullStorageBuckets fetches all storage buckets from the Supabase Storage API.

type Column

type Column struct {
	Name       string
	DataType   string
	IsNullable bool
	Default    string
}

Column describes a single column returned by the Supabase REST schema API.

type Config

type Config struct {
	ProjectRef string // e.g. "abcdefghijklmnopqrst"
	ServiceKey string // service_role JWT
}

Config holds the credentials for one Supabase project.

type GeneratedArtifacts

type GeneratedArtifacts struct {
	// MigrationSQL is the Drizzle-compatible SQL migration file content.
	MigrationSQL string
	// HasuraMetadata is the Hasura metadata YAML for the pulled schema.
	HasuraMetadata string
	// AuthImportScript is a shell script that imports users into nSelf.
	AuthImportScript string
	// Summary is a human-readable text summary with next steps.
	Summary string
}

GeneratedArtifacts contains the files the generator produced in memory (keyed by relative output path).

func Generate

func Generate(projectRef string, r *PullResult) *GeneratedArtifacts

Generate converts a PullResult into nSelf-compatible artifacts.

type PullResult

type PullResult struct {
	Tables   []Table
	Policies []RLSPolicy
	Users    []AuthUser
	Buckets  []StorageBucket
}

PullResult contains everything pulled from a Supabase project.

func Pull

func Pull(ctx context.Context, cfg Config) (*PullResult, error)

Pull runs all four pull operations and returns the aggregate result.

type RLSPolicy

type RLSPolicy struct {
	TableSchema string
	TableName   string
	PolicyName  string
	Command     string // SELECT | INSERT | UPDATE | DELETE | ALL
	Permissive  bool
	Roles       []string
	Using       string
	WithCheck   string
}

RLSPolicy is a PostgreSQL row-level security policy captured from the information_schema via PostgREST.

type StorageBucket

type StorageBucket struct {
	ID            string `json:"id"`
	Name          string `json:"name"`
	Public        bool   `json:"public"`
	FileSizeLimit int    `json:"file_size_limit"`
}

StorageBucket is a Supabase Storage bucket.

type Table

type Table struct {
	Schema  string
	Name    string
	Columns []Column
}

Table is a simplified representation of a Supabase table.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL