ddl

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyDDL

func ApplyDDL(
	catalog *catalog.Catalog,
	sql string,
	migrationFile string,
	databaseType string,
) error

ApplyDDL applies d d l.

func ParseDataType added in v0.38.9

func ParseDataType(typeStr string) (dataType string, length *int32, precision *int32, scale *int32)

ParseDataType parses SQL data type strings into components

func StripComments added in v1.0.0

func StripComments(sql string) string

StripComments removes SQL comments from the input string. It handles both single-line comments (-- ...) and block comments (/* ... */). It preserves comment-like patterns inside quoted strings.

Types

type AlterTableParser

type AlterTableParser struct {
	// contains filtered or unexported fields
}

AlterTableParser handles ALTER TABLE statements

func NewAlterTableParser

func NewAlterTableParser() *AlterTableParser

NewAlterTableParser creates a new alter table parser.

func (*AlterTableParser) Parse

func (p *AlterTableParser) Parse(
	sql, migrationFile string,
	databaseType string,
) (*AlterTableStatement, error)

Parse performs the parse operation.

type AlterTableStatement

type AlterTableStatement struct {
	Raw            string
	SchemaName     string
	TableName      string
	AlterOperation string
	ColumnName     string
	NewColumnName  string
	NewTableName   string
	ColumnDef      *catalog.Column
	ColumnChanges  map[string]any
	Operations     []string
}

AlterTableStatement represents alter table statement.

func (*AlterTableStatement) Accept

func (s *AlterTableStatement) Accept(visitor DDLVisitor) error

Accept performs the accept operation.

func (*AlterTableStatement) GetRaw

func (s *AlterTableStatement) GetRaw() string

GetRaw returns raw.

func (*AlterTableStatement) GetType

func (s *AlterTableStatement) GetType() StatementType

GetType returns type.

type CatalogVisitor added in v0.38.9

type CatalogVisitor struct {
	// contains filtered or unexported fields
}

CatalogVisitor visits catalog data.

func NewCatalogVisitor added in v0.38.9

func NewCatalogVisitor(cat *catalog.Catalog, migrationFile, databaseType string) *CatalogVisitor

NewCatalogVisitor creates a new catalog visitor.

func (*CatalogVisitor) VisitAlterTable added in v0.38.9

func (v *CatalogVisitor) VisitAlterTable(stmt *AlterTableStatement) error

VisitAlterTable performs the visit alter table operation.

func (*CatalogVisitor) VisitCreateEnum added in v0.38.9

func (v *CatalogVisitor) VisitCreateEnum(stmt *CreateEnumStatement) error

VisitCreateEnum performs the visit create enum operation.

func (*CatalogVisitor) VisitCreateIndex added in v0.38.9

func (v *CatalogVisitor) VisitCreateIndex(stmt *CreateIndexStatement) error

Stub implementations for operations we don't process

func (*CatalogVisitor) VisitCreateSchema added in v0.38.9

func (v *CatalogVisitor) VisitCreateSchema(stmt *CreateSchemaStatement) error

VisitCreateSchema performs the visit create schema operation.

func (*CatalogVisitor) VisitCreateTable added in v0.38.9

func (v *CatalogVisitor) VisitCreateTable(stmt *CreateTableStatement) error

VisitCreateTable performs the visit create table operation.

func (*CatalogVisitor) VisitDropEnum added in v0.38.9

func (v *CatalogVisitor) VisitDropEnum(stmt *DropEnumStatement) error

VisitDropEnum performs the visit drop enum operation.

func (*CatalogVisitor) VisitDropIndex added in v0.38.9

func (v *CatalogVisitor) VisitDropIndex(stmt *DropIndexStatement) error

VisitDropIndex performs the visit drop index operation.

func (*CatalogVisitor) VisitDropSchema added in v0.38.9

func (v *CatalogVisitor) VisitDropSchema(stmt *DropSchemaStatement) error

VisitDropSchema performs the visit drop schema operation.

func (*CatalogVisitor) VisitDropTable added in v0.38.9

func (v *CatalogVisitor) VisitDropTable(stmt *DropTableStatement) error

VisitDropTable performs the visit drop table operation.

type CreateEnumParser

type CreateEnumParser struct{}

CreateEnumParser handles CREATE TYPE (enum) statements

func NewCreateEnumParser

func NewCreateEnumParser() *CreateEnumParser

NewCreateEnumParser creates a new create enum parser.

func (*CreateEnumParser) Parse

Parse performs the parse operation.

type CreateEnumStatement

type CreateEnumStatement struct {
	Raw        string
	SchemaName string
	EnumName   string
	EnumDef    *catalog.Enum
}

CreateEnumStatement represents create enum statement.

func (*CreateEnumStatement) Accept

func (s *CreateEnumStatement) Accept(visitor DDLVisitor) error

Accept performs the accept operation.

func (*CreateEnumStatement) GetRaw

func (s *CreateEnumStatement) GetRaw() string

GetRaw returns raw.

func (*CreateEnumStatement) GetType

func (s *CreateEnumStatement) GetType() StatementType

GetType returns type.

type CreateIndexParser

type CreateIndexParser struct{}

CreateIndexParser handles CREATE INDEX statements

func NewCreateIndexParser

func NewCreateIndexParser() *CreateIndexParser

NewCreateIndexParser creates a new create index parser.

func (*CreateIndexParser) Parse

Parse performs the parse operation.

type CreateIndexStatement

type CreateIndexStatement struct {
	Raw string
}

CreateIndexStatement represents create index statement.

func (*CreateIndexStatement) Accept

func (s *CreateIndexStatement) Accept(visitor DDLVisitor) error

Accept performs the accept operation.

func (*CreateIndexStatement) GetRaw

func (s *CreateIndexStatement) GetRaw() string

GetRaw returns raw.

func (*CreateIndexStatement) GetType

func (s *CreateIndexStatement) GetType() StatementType

GetType returns type.

type CreateSchemaParser

type CreateSchemaParser struct{}

CreateSchemaParser handles CREATE SCHEMA statements

func NewCreateSchemaParser

func NewCreateSchemaParser() *CreateSchemaParser

NewCreateSchemaParser creates a new create schema parser.

func (*CreateSchemaParser) Parse

Parse performs the parse operation.

type CreateSchemaStatement

type CreateSchemaStatement struct {
	Raw        string
	SchemaName string
}

CreateSchemaStatement represents create schema statement.

func (*CreateSchemaStatement) Accept

func (s *CreateSchemaStatement) Accept(visitor DDLVisitor) error

Accept performs the accept operation.

func (*CreateSchemaStatement) GetRaw

func (s *CreateSchemaStatement) GetRaw() string

GetRaw returns raw.

func (*CreateSchemaStatement) GetType

func (s *CreateSchemaStatement) GetType() StatementType

GetType returns type.

type CreateTableParser

type CreateTableParser struct{}

CreateTableParser handles CREATE TABLE statements

func NewCreateTableParser

func NewCreateTableParser() *CreateTableParser

NewCreateTableParser creates a new create table parser.

func (*CreateTableParser) Parse

func (p *CreateTableParser) Parse(
	sql, migrationFile string,
	databaseType string,
) (*CreateTableStatement, error)

Parse performs the parse operation.

type CreateTableStatement

type CreateTableStatement struct {
	Raw         string
	SchemaName  string
	TableName   string
	IfNotExists bool
	Columns     []*catalog.Column
}

Statement implementations

func (*CreateTableStatement) Accept

func (s *CreateTableStatement) Accept(visitor DDLVisitor) error

Accept performs the accept operation.

func (*CreateTableStatement) GetRaw

func (s *CreateTableStatement) GetRaw() string

GetRaw returns raw.

func (*CreateTableStatement) GetType

func (s *CreateTableStatement) GetType() StatementType

GetType returns type.

type DDLParser

type DDLParser struct {
	// contains filtered or unexported fields
}

NewDDLParser creates a parser using the visitor pattern

func NewDDLParser

func NewDDLParser() *DDLParser

NewDDLParser creates a new d d l parser.

func (*DDLParser) Parse

func (p *DDLParser) Parse(sql, migrationFile string, databaseType string) (Statement, error)

Parse performs the parse operation.

type DDLVisitor

type DDLVisitor interface {
	TableVisitor
	IndexVisitor
	SchemaVisitor
	EnumVisitor
}

DDLVisitor combines all DDL visitor interfaces

type DropEnumParser

type DropEnumParser struct{}

DropEnumParser handles DROP TYPE (enum) statements

func NewDropEnumParser

func NewDropEnumParser() *DropEnumParser

NewDropEnumParser creates a new drop enum parser.

func (*DropEnumParser) Parse

func (p *DropEnumParser) Parse(sql string) (*DropEnumStatement, error)

Parse performs the parse operation.

type DropEnumStatement

type DropEnumStatement struct {
	Raw        string
	SchemaName string
	EnumName   string
}

DropEnumStatement represents drop enum statement.

func (*DropEnumStatement) Accept

func (s *DropEnumStatement) Accept(visitor DDLVisitor) error

Accept performs the accept operation.

func (*DropEnumStatement) GetRaw

func (s *DropEnumStatement) GetRaw() string

GetRaw returns raw.

func (*DropEnumStatement) GetType

func (s *DropEnumStatement) GetType() StatementType

GetType returns type.

type DropIndexParser

type DropIndexParser struct{}

DropIndexParser handles DROP INDEX statements

func NewDropIndexParser

func NewDropIndexParser() *DropIndexParser

NewDropIndexParser creates a new drop index parser.

func (*DropIndexParser) Parse

func (p *DropIndexParser) Parse(sql string) (*DropIndexStatement, error)

Parse performs the parse operation.

type DropIndexStatement

type DropIndexStatement struct {
	Raw string
}

DropIndexStatement represents drop index statement.

func (*DropIndexStatement) Accept

func (s *DropIndexStatement) Accept(visitor DDLVisitor) error

Accept performs the accept operation.

func (*DropIndexStatement) GetRaw

func (s *DropIndexStatement) GetRaw() string

GetRaw returns raw.

func (*DropIndexStatement) GetType

func (s *DropIndexStatement) GetType() StatementType

GetType returns type.

type DropSchemaParser

type DropSchemaParser struct{}

DropSchemaParser handles DROP SCHEMA statements

func NewDropSchemaParser

func NewDropSchemaParser() *DropSchemaParser

NewDropSchemaParser creates a new drop schema parser.

func (*DropSchemaParser) Parse

Parse performs the parse operation.

type DropSchemaStatement

type DropSchemaStatement struct {
	Raw        string
	SchemaName string
}

DropSchemaStatement represents drop schema statement.

func (*DropSchemaStatement) Accept

func (s *DropSchemaStatement) Accept(visitor DDLVisitor) error

Accept performs the accept operation.

func (*DropSchemaStatement) GetRaw

func (s *DropSchemaStatement) GetRaw() string

GetRaw returns raw.

func (*DropSchemaStatement) GetType

func (s *DropSchemaStatement) GetType() StatementType

GetType returns type.

type DropTableParser

type DropTableParser struct{}

DropTableParser handles DROP TABLE statements

func NewDropTableParser

func NewDropTableParser() *DropTableParser

NewDropTableParser creates a new drop table parser.

func (*DropTableParser) Parse

func (p *DropTableParser) Parse(sql string) (*DropTableStatement, error)

Parse performs the parse operation.

type DropTableStatement

type DropTableStatement struct {
	Raw        string
	SchemaName string
	TableName  string
	IfExists   bool
}

DropTableStatement represents drop table statement.

func (*DropTableStatement) Accept

func (s *DropTableStatement) Accept(visitor DDLVisitor) error

Accept performs the accept operation.

func (*DropTableStatement) GetRaw

func (s *DropTableStatement) GetRaw() string

GetRaw returns raw.

func (*DropTableStatement) GetType

func (s *DropTableStatement) GetType() StatementType

GetType returns type.

type EnumVisitor

type EnumVisitor interface {
	VisitCreateEnum(stmt *CreateEnumStatement) error
	VisitDropEnum(stmt *DropEnumStatement) error
}

EnumVisitor handles enum-related DDL operations

type IndexVisitor

type IndexVisitor interface {
	VisitCreateIndex(stmt *CreateIndexStatement) error
	VisitDropIndex(stmt *DropIndexStatement) error
}

IndexVisitor handles index-related DDL operations

type SchemaVisitor

type SchemaVisitor interface {
	VisitCreateSchema(stmt *CreateSchemaStatement) error
	VisitDropSchema(stmt *DropSchemaStatement) error
}

SchemaVisitor handles schema-related DDL operations

type Statement

type Statement interface {
	Accept(visitor DDLVisitor) error
	GetRaw() string
	GetType() StatementType
}

Base statement interfaces

type StatementType

type StatementType int

StatementType represents the type of DDL statement

const (
	// CreateTable is a constant value for create table.
	CreateTable StatementType = iota
	// AlterTable is a constant value for alter table.
	AlterTable
	// DropTable is a constant value for drop table.
	DropTable
	// CreateIndex is a constant value for create index.
	CreateIndex
	// DropIndex is a constant value for drop index.
	DropIndex
	// CreateSchema is a constant value for create schema.
	CreateSchema
	// DropSchema is a constant value for drop schema.
	DropSchema
	// CreateEnum is a constant value for create enum.
	CreateEnum
	// DropEnum is a constant value for drop enum.
	DropEnum
	// Unknown is a constant value for unknown.
	Unknown
)

type TableVisitor

type TableVisitor interface {
	VisitCreateTable(stmt *CreateTableStatement) error
	VisitAlterTable(stmt *AlterTableStatement) error
	VisitDropTable(stmt *DropTableStatement) error
}

TableVisitor handles table-related DDL operations

type UnknownStatement

type UnknownStatement struct {
	Raw string
}

UnknownStatement represents unknown statement.

func (*UnknownStatement) Accept

func (s *UnknownStatement) Accept(visitor DDLVisitor) error

Accept performs the accept operation.

func (*UnknownStatement) GetRaw

func (s *UnknownStatement) GetRaw() string

GetRaw returns raw.

func (*UnknownStatement) GetType

func (s *UnknownStatement) GetType() StatementType

GetType returns type.

type UnsupportedStatementError added in v1.0.0

type UnsupportedStatementError struct {
	Statement string
	Reason    string
}

UnsupportedStatementError identifies DDL that may change generated models but cannot be represented safely by the catalog parser.

func (*UnsupportedStatementError) Error added in v1.0.0

func (e *UnsupportedStatementError) Error() string

Error returns an actionable parser diagnostic.

Jump to

Keyboard shortcuts

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