schemacheck

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package schemacheck reads the canonical SQL of both roles and the bindings generated from it so tests can compare them against a real database. It exposes those inputs without interpreting them: deciding what has to agree is left to the tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppliedVersion

func AppliedVersion(ctx context.Context, db *sql.DB) (int64, error)

AppliedVersion reports the highest migration goose recorded as applied.

func CanonicalQueryNames

func CanonicalQueryNames(dir string) ([]string, error)

CanonicalQueryNames returns the names declared in the SQL below dir.

func Directives

func Directives(sequence fs.FS, name string) error

Directives reports whether a migration carries both goose annotations. A file without them applies as a single statement block or not at all.

func GeneratedQueries

func GeneratedQueries(dir string) (map[string]string, error)

GeneratedQueries returns the SQL embedded in the generated bindings below dir, keyed by the query name the generator recorded with it.

func GeneratedStructs

func GeneratedStructs(path string) (map[string][]string, error)

GeneratedStructs returns the field names of every generated model struct.

func OpenFresh

func OpenFresh(ctx context.Context, dir string, sequence fs.FS) (*sql.DB, error)

OpenFresh creates a new SQLite database below dir and applies the embedded sequence to it. The caller closes the returned handle.

func RepoRoot

func RepoRoot() (string, error)

RepoRoot locates the checkout that holds the running package.

func Signature

func Signature(names []string) string

Signature folds a set of column or field names onto an order-independent key. The generator derives Go field names from column names by removing the separators and changing case, so both sides fold onto the same value.

func TableColumns

func TableColumns(ctx context.Context, db *sql.DB) (map[string][]string, error)

TableColumns reports the tables and views the migrations produced and the columns of each, excluding SQLite's own tables and goose's bookkeeping.

Types

type GeneratorConfig

type GeneratorConfig struct {
	Queries []string
	Schema  []string
	Out     []string
}

GeneratorConfig holds the directories recorded in sqlc.yml.

func ReadGeneratorConfig

func ReadGeneratorConfig(path string) (GeneratorConfig, error)

ReadGeneratorConfig collects the directories the SQL generator reads and writes, so tests can confirm they address the sequences the roles embed.

type Migration

type Migration struct {
	Version int64
	File    string
}

Migration is one file of an embedded sequence.

func Migrations

func Migrations(sequence fs.FS) ([]Migration, error)

Migrations lists an embedded sequence in applied order. It rejects names outside NNNNN_lower_case.sql, repeated version numbers, and sequences that do not run from 1 without gaps.

type Role

type Role struct {
	Name          string
	Migrations    fs.FS
	MigrationsDir string
	QueriesDir    string
	GeneratedDir  string
}

Role is one embedded migration sequence together with the canonical queries and the generated bindings produced from it.

func Roles

func Roles() []Role

Roles returns both schemas the project ships, in a stable order. Each role keeps its sequence, its canonical queries and its bindings below one directory named after it, which is also what sqlc.yml addresses.

Jump to

Keyboard shortcuts

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