Skip to content

Snippet and tests syncing #3925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft

Snippet and tests syncing #3925

wants to merge 4 commits into from

Conversation

SaxonF
Copy link

@SaxonF SaxonF commented Jul 28, 2025

This adds commands for downloading and pushing "snippets" to remote (dashboard). As part of database testing work, a snippet can either by "sql" (e.g. in sql editor) or "tests". A test is an sql file that makes use of pgTap. https://supabase.com/docs/guides/database/testing

tests download downloads project snippets of type test to the tests/database folder.

snippets download downloads project snippets of type sql to the snippets folder.

Infrastructure PR https://github.com/supabase/infrastructure/pull/24519

Studio PR supabase/supabase#37499

)

var (
testsCmd = &cobra.Command{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a test root command that we can enrich https://github.com/supabase/cli/blob/develop/cmd/test.go

"favorite": false,
"schema_version": schemaVersion,
"sql": sql,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix the openapi type so this can be a properly generated struct.

I'd also use multipart/form upload for sql snippets to avoid string escape issues when converting sql function to json.


const (
ContentTypeTest ContentType = "test"
ContentTypeSnippet ContentType = "snippet"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can reuse the generated enums for api.UpsertContentBodyType to simplify type conversion

Visibility: api.UpsertContentBodyVisibilityProject,
Content: &content,
}
resp, err := utils.GetSupabase().V1ProjectUpsertSnippetWithResponse(ctx, flags.ProjectRef, id, body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upsert really means update or insert. The operation id for this openapi spec should be v1-project-update-snippet for clarity

if !isCorrectType(s.Type, contentType) || s.Visibility != api.SnippetListDataVisibilityProject {
continue
}
id, err := uuid.Parse(s.Id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update openapi response type to uuid to avoid this client side conversion loop

return nil
}

func DownloadAll(ctx context.Context, fsys afero.Fs, contentType ContentType) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest breaking this up

  • ListSnippets(ctx context.Context, contentType ContentType)
  • DownloadSnippets(ctx context.Context, snippetIds []uuid.UUID, fsys afero.Fs)

There's no need to have a separate DownloadOne since we can use a single element array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants