Documentation
¶
Overview ¶
Package sqlddl reads SQL migrations without running them: a lexer splits statements, and a replay applies the DDL that shapes tables and columns to an in-memory schema. PostgreSQL first; MySQL quoting is tolerated. Statements it does not know are skipped, never guessed. See https://cernly.dev/how/plugins/.
Index ¶
Constants ¶
const ( MySQL = "mysql" PostgreSQL = "postgresql" SQLServer = "sqlserver" // a Set only: the EF Core reader's migrationBuilder.Sql )
Variables ¶
This section is empty.
Functions ¶
func Replay ¶
Replay applies a migration set's files in order and returns the tables they leave, sorted by name. hint is the dialect when the SQL itself has no signal (a Prisma migration_lock.toml); the SQL's own signal wins. Only a PostgreSQL set puts unqualified tables in public and says whether row-level security is on.
Types ¶
type Dialect ¶
type Dialect struct {
Name string // "mysql", "postgresql" or ""
Signal string // what was seen, e.g. "CREATE EXTENSION"
File string
Line int
}
Dialect is what a migration set was read as, and the first statement that says so: MySQL, PostgreSQL, or neither ("": table names stay as written, no row-level security).
func Detect ¶
Detect reads a set's dialect from the SQL itself. MySQL: backticks, a CREATE TABLE … ENGINE= option, or lexed as MySQL by SplitSet. PostgreSQL: a schema-qualified table, CREATE EXTENSION, row-level security, a $$ body, a SERIAL type or a :: cast. The first statement with a signal decides within each kind; MySQL wins over PostgreSQL.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a replay that a caller drives statement by statement and whose tables it changes in between: the EF Core reader replays migrationBuilder.Sql literals into the tables its own operations built.
func NewSet ¶
NewSet starts an empty set read as dialect (MySQL, PostgreSQL, SQLServer or ""). defaultSchema qualifies unqualified names outside PostgreSQL (dbo for SQL Server); a MySQL set has no schemas. A SQLServer set finds tables and columns without regard to case, as SQL Server's default collation does, when exactly one matches so.
func (*Set) Exec ¶
Exec applies stmts from file with every statement placed at line: SQL held in a string of another language has no lines of its own. unread is true when a statement that shapes tables could not be read, or names a table or column the set does not hold, so it changed nothing.
type Stmt ¶
type Stmt struct {
Line, End int
// contains filtered or unexported fields
}
Stmt is one statement: its tokens, without comments, and its first and last line.
type SyntaxError ¶
SyntaxError is a lexing failure at a line.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string