Documentation
¶
Index ¶
- Constants
- func GenerateAsync(projectDir string, opts *GenerateOptions, callbacks *GenerateCallbacks) error
- func GetEnvVarName(projectDir string) (string, error)
- func GetProvider(projectDir string) (string, error)
- func GetWorkspaceType(dir string) string
- func IsWorkspace(dir string) bool
- func MaskPassword(dbURL string) string
- type DBMigration
- type Datasource
- type GenerateCallbacks
- type GenerateOptions
- type GenerateResult
- type Migration
- type MigrationCategory
- type ValidateResult
- type VersionInfo
Constants ¶
const ( // v7.0+ config file ConfigFileName = "prisma.config.ts" // Schema file prior to v7.0 SchemaFileName = "schema.prisma" SchemaDirName = "prisma" )
const (
MigrationsDirName = "migrations"
)
Variables ¶
This section is empty.
Functions ¶
func GenerateAsync ¶
func GenerateAsync(projectDir string, opts *GenerateOptions, callbacks *GenerateCallbacks) error
GenerateAsync runs `npx prisma generate` asynchronously with real-time output
func GetEnvVarName ¶
GetEnvVarName extracts the environment variable name used for database URL Returns the env var name even if the variable is not set
func GetProvider ¶
GetProvider extracts only the provider from schema files This is useful when URL resolution fails but we still want to show the provider
func GetWorkspaceType ¶
GetWorkspaceType returns the type of Prisma workspace Returns "v7+" for prisma.config.ts, "v7-" for prisma/schema.prisma, "" if not a workspace
func IsWorkspace ¶
IsWorkspace checks if the given directory is a Prisma workspace For v7.0+: checks for prisma.config.ts in the current directory For v7.0-: checks for prisma/schema.prisma in the current directory
func MaskPassword ¶
MaskPassword masks the password in a database URL with asterisks
Types ¶
type DBMigration ¶
type DBMigration struct {
Name string
Checksum string
StartedAt *time.Time // Migration start time
FinishedAt *time.Time // nil if migration failed
RolledBackAt *time.Time // nil if not rolled back
Logs *string // Migration logs (especially for failed migrations)
}
DBMigration represents a migration from the database
func GetDBMigrations ¶
func GetDBMigrations(db *sql.DB) ([]DBMigration, error)
GetDBMigrations returns migrations from the _prisma_migrations table
type Datasource ¶
type Datasource struct {
Provider string // Database provider (postgresql, mysql, sqlite, etc.)
URL string // Database connection URL
EnvVarName string // Environment variable name (e.g., "DATABASE_URL")
IsHardcoded bool // True if URL is hardcoded in schema/config
}
Datasource represents a Prisma datasource configuration
func GetDatasource ¶
func GetDatasource(projectDir string) (*Datasource, error)
GetDatasource extracts datasource information from schema.prisma or prisma.config.ts
type GenerateCallbacks ¶
type GenerateCallbacks struct {
OnStdout func(string) // Called for each stdout line
OnStderr func(string) // Called for each stderr line
OnComplete func(bool) // Called when complete (success bool)
OnError func(error) // Called on error
}
GenerateAsync runs prisma generate asynchronously with callbacks
type GenerateOptions ¶
type GenerateOptions struct {
Schema string // Optional path to schema file
Watch bool // Enable watch mode
NoEngine bool // Skip engine download
DataProxy bool // Generate for Data Proxy
Accelerate bool // Generate for Accelerate
}
GenerateOptions holds options for prisma generate command
type GenerateResult ¶
type GenerateResult struct {
Success bool // True if generation succeeded
Output string // Full output from generate command
Error string // Error message if failed
}
GenerateResult holds the result of prisma generate
func Generate ¶
func Generate(projectDir string, opts *GenerateOptions) (*GenerateResult, error)
Generate runs `npx prisma generate` to generate Prisma Client
type Migration ¶
type Migration struct {
Name string
Path string
AppliedAt *time.Time // nil if not applied to DB
IsEmpty bool // true if migration folder is empty or has no migration.sql
HasDownSQL bool // true if migration folder has down.sql
Checksum string // SHA-256 checksum of local migration.sql
DBChecksum string // SHA-256 checksum from DB (if exists)
IsFailed bool // true if migration failed (finished_at IS NULL AND rolled_back_at IS NULL)
ChecksumMismatch bool // true if local checksum != DB checksum
Logs *string // Migration logs from DB (if failed)
StartedAt *time.Time // Migration start time from DB (for in-transaction migrations)
}
Migration represents a migration
func GetLocalMigrations ¶
GetLocalMigrations returns a list of local migrations from the prisma/migrations directory
type MigrationCategory ¶
type MigrationCategory struct {
Local []Migration // All local migrations
Pending []Migration // Local but not in DB
DBOnly []Migration // In DB but not local
}
MigrationCategory represents different migration types
func CompareMigrations ¶
func CompareMigrations(localMigrations []Migration, dbMigrations []DBMigration) MigrationCategory
CompareMigrations classifies migrations into categories
type ValidateResult ¶
type ValidateResult struct {
Valid bool // True if schema is valid
Errors []string // List of validation errors
Output string // Full output from validate command
}
ValidateResult holds the result of schema validation
func Validate ¶
func Validate(projectDir string) (*ValidateResult, error)
Validate runs `npx prisma validate` to check schema validity
type VersionInfo ¶
VersionInfo holds Prisma version information
func GetVersion ¶
func GetVersion(projectDir string) (*VersionInfo, error)
GetVersion returns the Prisma version It checks local installation first, then falls back to global