Documentation
¶
Overview ¶
Package schema provisions tables and extracts/applies explicit native schema artifacts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = errors.New("schema feature unsupported")
ErrUnsupported identifies a dialect or requested schema feature without a faithful native extractor. AllowPartial returns its omissions in the artifact.
Functions ¶
func SplitSQL ¶ added in v0.26.1
SplitSQL reads SQL, including quoted identifiers/strings, comments, PostgreSQL dollar quotes, and SQLite trigger BEGIN/END bodies. It rejects client commands (DELIMITER, GO, backslash commands), COPY FROM STDIN and unquoted procedural blocks outside SQLite triggers. PostgreSQL strings assume standard_conforming_strings is on; use E'...' for backslash escapes. MySQL strings use its default escape rules. Script settings that change lexical rules require explicit statements.
Types ¶
type ApplyOptions ¶ added in v0.26.1
ApplyOptions controls DDL execution. A supplied Tx remains caller-owned and is never committed or rolled back. Atomic requests an owned DDL transaction and cannot be combined with Tx. SQLite and PostgreSQL support this option; MySQL and BigQuery DDL do not. Without either option all statements share one pinned connection and successful statements remain applied on a later failure. PostgreSQL sequence state and side effects of authored functions retain the server's nontransactional behavior even inside a transaction.
type ApplyResult ¶ added in v0.26.1
ApplyResult accounts for successful Exec calls, including calls subsequently rolled back. Executed does not claim that a caller-owned transaction committed. Atomic is true when statements ran inside an owned or caller transaction.
func Apply ¶ added in v0.26.1
func Apply(ctx context.Context, db *sql.DB, artifact *Artifact, opts ApplyOptions) (*ApplyResult, error)
Apply executes an artifact as authored, failing on existing objects or other SQL errors. It does not infer migrations, disable constraints, or reset tables.
func ApplySQL ¶ added in v0.26.1
func ApplySQL(ctx context.Context, db *sql.DB, script string, opts ApplyOptions) (*ApplyResult, error)
ApplySQL parses the entire script before executing its ordered statements.
type Artifact ¶ added in v0.26.1
type Artifact struct {
Dialect string
Driver string
Schema string
Tables []string
Statements []string
Objects []Object
Complete bool
Omissions []Omission
Checksum string
}
Artifact is a same-dialect schema, not a migration or a database backup. Statements are complete native SQL statements in execution order. Checksum is SHA-256 of SQL(), including its final newline. Counters are opt-in and separate from identity definitions. Schema remapping is deliberately unsupported.
type ExtractOptions ¶ added in v0.26.1
type ExtractOptions struct {
Dialect *info.Dialect
Schema string
Tables []string
IncludeDependencies bool
IncludeViews bool
IncludeTriggers bool
IncludeSequenceState bool
AllowPartial bool
}
ExtractOptions selects decoded, literal table names in one schema. A dot in a table name is part of that name. Constraints and indexes are always included. Dependencies are rejected unless IncludeDependencies is set. Views and triggers are opt-in. SQLite includes all views when requested; view/trigger dependencies conservatively require all user tables in the selected schema. Routines, grants, extensions and data are outside scope. Extraction requires a quiescent source; it does not lock concurrent DDL.
type Field ¶ added in v0.26.1
Field can describe nested native fields without flattening RECORD/STRUCTs. Native statements remain authoritative; extractors need not populate Fields.
type Object ¶ added in v0.26.1
type Object struct {
Kind string
Name string
Table string `json:",omitempty"`
Fields []Field `json:",omitempty"`
}
Object records one extracted object in execution order.
type Omission ¶ added in v0.26.1
Omission describes an explicitly incomplete portion of the requested scope.
type Service ¶
Service provisions on the caller's native database. It does not own its lifetime, cache schema results, or begin a transaction (DDL may auto-commit).
func (*Service) EnsureTable ¶
EnsureTable preserves an accessible existing table. Failed probes are followed by CREATE IF NOT EXISTS and another probe, never ALTER or DROP. A concurrent creator may win even when the vendor reports a catalog conflict on CREATE.