Documentation
¶
Index ¶
- func NeedsQuoting(identifier string) bool
- func QualifyEntityNameWithQuotes(entitySchema, entityName, targetSchema string) string
- func QuoteIdentifier(identifier string) string
- type Aggregate
- type Column
- type Constraint
- type ConstraintColumn
- type ConstraintType
- type DependencyType
- type DomainConstraint
- type Function
- type IR
- type Identity
- type IgnoreConfig
- func (c *IgnoreConfig) ShouldIgnoreFunction(functionName string) bool
- func (c *IgnoreConfig) ShouldIgnoreProcedure(procedureName string) bool
- func (c *IgnoreConfig) ShouldIgnoreSequence(sequenceName string) bool
- func (c *IgnoreConfig) ShouldIgnoreTable(tableName string) bool
- func (c *IgnoreConfig) ShouldIgnoreType(typeName string) bool
- func (c *IgnoreConfig) ShouldIgnoreView(viewName string) bool
- type Index
- type IndexColumn
- type IndexType
- type Inspector
- type LikeClause
- type Metadata
- type Parameter
- type PolicyCommand
- type Procedure
- type RLSPolicy
- type Schema
- func (s *Schema) GetAggregate(name string) (*Aggregate, bool)
- func (s *Schema) GetFunction(name string) (*Function, bool)
- func (s *Schema) GetProcedure(name string) (*Procedure, bool)
- func (s *Schema) GetSequence(name string) (*Sequence, bool)
- func (s *Schema) GetTable(name string) (*Table, bool)
- func (s *Schema) GetType(name string) (*Type, bool)
- func (s *Schema) GetView(name string) (*View, bool)
- func (s *Schema) SetAggregate(name string, aggregate *Aggregate)
- func (s *Schema) SetFunction(name string, function *Function)
- func (s *Schema) SetProcedure(name string, procedure *Procedure)
- func (s *Schema) SetSequence(name string, sequence *Sequence)
- func (s *Schema) SetTable(name string, table *Table)
- func (s *Schema) SetType(name string, typ *Type)
- func (s *Schema) SetView(name string, view *View)
- type Sequence
- type Table
- type TableDependency
- type TableType
- type Trigger
- type TriggerEvent
- type TriggerLevel
- type TriggerTiming
- type Type
- type TypeColumn
- type TypeKind
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NeedsQuoting ¶
NeedsQuoting checks if an identifier needs to be quoted
func QualifyEntityNameWithQuotes ¶
QualifyEntityNameWithQuotes returns the properly qualified and quoted entity name
func QuoteIdentifier ¶
QuoteIdentifier adds quotes to an identifier if needed
Types ¶
type Aggregate ¶
type Aggregate struct {
Schema string `json:"schema"`
Name string `json:"name"`
ReturnType string `json:"return_type"`
TransitionFunction string `json:"transition_function"`
TransitionFunctionSchema string `json:"transition_function_schema,omitempty"`
StateType string `json:"state_type"`
InitialCondition string `json:"initial_condition,omitempty"`
FinalFunction string `json:"final_function,omitempty"`
FinalFunctionSchema string `json:"final_function_schema,omitempty"`
Comment string `json:"comment,omitempty"`
}
Aggregate represents a database aggregate function
type Column ¶
type Column struct {
Name string `json:"name"`
Position int `json:"position"` // ordinal_position
DataType string `json:"data_type"`
IsNullable bool `json:"is_nullable"`
DefaultValue *string `json:"default_value,omitempty"`
MaxLength *int `json:"max_length,omitempty"`
Precision *int `json:"precision,omitempty"`
Scale *int `json:"scale,omitempty"`
Comment string `json:"comment,omitempty"`
Identity *Identity `json:"identity,omitempty"`
GeneratedExpr *string `json:"generated_expr,omitempty"` // Expression for generated columns
IsGenerated bool `json:"is_generated,omitempty"` // True if this is a generated column
}
Column represents a table column
func (*Column) IsDiffSource ¶
func (c *Column) IsDiffSource()
type Constraint ¶
type Constraint struct {
Schema string `json:"schema"`
Table string `json:"table"`
Name string `json:"name"`
Type ConstraintType `json:"type"`
Columns []*ConstraintColumn `json:"columns"`
ReferencedSchema string `json:"referenced_schema,omitempty"`
ReferencedTable string `json:"referenced_table,omitempty"`
ReferencedColumns []*ConstraintColumn `json:"referenced_columns,omitempty"`
CheckClause string `json:"check_clause,omitempty"`
DeleteRule string `json:"delete_rule,omitempty"`
UpdateRule string `json:"update_rule,omitempty"`
Deferrable bool `json:"deferrable,omitempty"`
InitiallyDeferred bool `json:"initially_deferred,omitempty"`
IsValid bool `json:"is_valid,omitempty"`
Comment string `json:"comment,omitempty"`
}
Constraint represents a table constraint
func (*Constraint) IsDiffSource ¶
func (c *Constraint) IsDiffSource()
type ConstraintColumn ¶
type ConstraintColumn struct {
Name string `json:"name"`
Position int `json:"position"` // ordinal_position within the constraint
}
ConstraintColumn represents a column within a constraint with its position
type ConstraintType ¶
type ConstraintType string
ConstraintType represents different types of database constraints
const ( ConstraintTypePrimaryKey ConstraintType = "PRIMARY_KEY" ConstraintTypeUnique ConstraintType = "UNIQUE" ConstraintTypeForeignKey ConstraintType = "FOREIGN_KEY" ConstraintTypeCheck ConstraintType = "CHECK" ConstraintTypeExclusion ConstraintType = "EXCLUSION" )
type DependencyType ¶
type DependencyType string
DependencyType represents different types of database object dependencies
const ( DependencyTypeTable DependencyType = "TABLE" DependencyTypeView DependencyType = "VIEW" DependencyTypeFunction DependencyType = "FUNCTION" DependencyTypeSequence DependencyType = "SEQUENCE" )
type DomainConstraint ¶
DomainConstraint represents a constraint on a domain
type Function ¶
type Function struct {
Schema string `json:"schema"`
Name string `json:"name"`
Definition string `json:"definition"`
ReturnType string `json:"return_type"`
Language string `json:"language"`
Parameters []*Parameter `json:"parameters,omitempty"`
Comment string `json:"comment,omitempty"`
Volatility string `json:"volatility,omitempty"` // IMMUTABLE, STABLE, VOLATILE
IsStrict bool `json:"is_strict,omitempty"` // STRICT or null behavior
IsSecurityDefiner bool `json:"is_security_definer,omitempty"` // SECURITY DEFINER
}
Function represents a database function
func (*Function) GetArguments ¶
GetArguments returns the function arguments string (types only) for function identification. This is built dynamically from the Parameters array to ensure it uses normalized types. Per PostgreSQL DROP FUNCTION syntax, only input parameters are included (IN, INOUT, VARIADIC).
func (*Function) IsDiffSource ¶
func (f *Function) IsDiffSource()
type IR ¶
type IR struct {
Metadata Metadata `json:"metadata"`
Schemas map[string]*Schema `json:"schemas"` // schema_name -> Schema
// contains filtered or unexported fields
}
IR represents the complete database schema intermediate representation
func (*IR) CreateSchema ¶
CreateSchema creates a new schema with the given name. If the schema already exists, it returns the existing schema.
func (*IR) GetOrCreateSchema ¶
GetOrCreateSchema gets or creates a database schema by name with thread safety. This is an exported version of the internal getOrCreateSchema method.
type Identity ¶
type Identity struct {
Generation string `json:"generation,omitempty"` // "ALWAYS" or "BY DEFAULT"
Start *int64 `json:"start,omitempty"`
Increment *int64 `json:"increment,omitempty"`
Maximum *int64 `json:"maximum,omitempty"`
Minimum *int64 `json:"minimum,omitempty"`
Cycle bool `json:"cycle,omitempty"`
}
Identity represents PostgreSQL identity column configuration
type IgnoreConfig ¶
type IgnoreConfig struct {
Tables []string `toml:"tables,omitempty"`
Views []string `toml:"views,omitempty"`
Functions []string `toml:"functions,omitempty"`
Procedures []string `toml:"procedures,omitempty"`
Types []string `toml:"types,omitempty"`
Sequences []string `toml:"sequences,omitempty"`
}
IgnoreConfig represents the configuration for ignoring database objects
func (*IgnoreConfig) ShouldIgnoreFunction ¶
func (c *IgnoreConfig) ShouldIgnoreFunction(functionName string) bool
ShouldIgnoreFunction checks if a function should be ignored based on the patterns
func (*IgnoreConfig) ShouldIgnoreProcedure ¶
func (c *IgnoreConfig) ShouldIgnoreProcedure(procedureName string) bool
ShouldIgnoreProcedure checks if a procedure should be ignored based on the patterns
func (*IgnoreConfig) ShouldIgnoreSequence ¶
func (c *IgnoreConfig) ShouldIgnoreSequence(sequenceName string) bool
ShouldIgnoreSequence checks if a sequence should be ignored based on the patterns
func (*IgnoreConfig) ShouldIgnoreTable ¶
func (c *IgnoreConfig) ShouldIgnoreTable(tableName string) bool
ShouldIgnoreTable checks if a table should be ignored based on the patterns
func (*IgnoreConfig) ShouldIgnoreType ¶
func (c *IgnoreConfig) ShouldIgnoreType(typeName string) bool
ShouldIgnoreType checks if a type should be ignored based on the patterns
func (*IgnoreConfig) ShouldIgnoreView ¶
func (c *IgnoreConfig) ShouldIgnoreView(viewName string) bool
ShouldIgnoreView checks if a view should be ignored based on the patterns
type Index ¶
type Index struct {
Schema string `json:"schema"`
Table string `json:"table"`
Name string `json:"name"`
Type IndexType `json:"type"`
Method string `json:"method"` // btree, hash, gin, gist, etc.
Columns []*IndexColumn `json:"columns"`
IsPartial bool `json:"is_partial"` // has a WHERE clause
IsExpression bool `json:"is_expression"` // functional/expression index
Where string `json:"where,omitempty"` // partial index condition
Comment string `json:"comment,omitempty"`
}
Index represents a database index
func (*Index) IsDiffSource ¶
func (i *Index) IsDiffSource()
type IndexColumn ¶
type IndexColumn struct {
Name string `json:"name"`
Position int `json:"position"`
Direction string `json:"direction,omitempty"` // ASC, DESC
Operator string `json:"operator,omitempty"` // operator class
}
IndexColumn represents a column within an index
type Inspector ¶
type Inspector struct {
// contains filtered or unexported fields
}
Inspector builds IR from database queries
func NewInspector ¶
func NewInspector(db *sql.DB, ignoreConfig *IgnoreConfig) *Inspector
NewInspector creates a new schema inspector with optional ignore configuration
type LikeClause ¶
type LikeClause struct {
SourceSchema string `json:"source_schema"`
SourceTable string `json:"source_table"`
Options string `json:"options"` // e.g., "INCLUDING ALL" or "INCLUDING DEFAULTS EXCLUDING INDEXES"
}
LikeClause represents a LIKE clause in CREATE TABLE statement
type Metadata ¶
type Metadata struct {
DatabaseVersion string `json:"database_version"`
}
Metadata contains information about the schema dump
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
DataType string `json:"data_type"`
Mode string `json:"mode"` // IN, OUT, INOUT
Position int `json:"position"`
DefaultValue *string `json:"default_value,omitempty"`
}
Parameter represents a function parameter
type PolicyCommand ¶
type PolicyCommand string
PolicyCommand represents the command for which the policy applies
const ( PolicyCommandAll PolicyCommand = "ALL" PolicyCommandSelect PolicyCommand = "SELECT" PolicyCommandInsert PolicyCommand = "INSERT" PolicyCommandUpdate PolicyCommand = "UPDATE" PolicyCommandDelete PolicyCommand = "DELETE" )
type Procedure ¶
type Procedure struct {
Schema string `json:"schema"`
Name string `json:"name"`
Definition string `json:"definition"`
Language string `json:"language"`
Parameters []*Parameter `json:"parameters,omitempty"`
Comment string `json:"comment,omitempty"`
}
Procedure represents a database procedure
func (*Procedure) IsDiffSource ¶
func (p *Procedure) IsDiffSource()
type RLSPolicy ¶
type RLSPolicy struct {
Schema string `json:"schema"`
Table string `json:"table"`
Name string `json:"name"`
Command PolicyCommand `json:"command"` // SELECT, INSERT, UPDATE, DELETE, ALL
Permissive bool `json:"permissive"`
Roles []string `json:"roles,omitempty"`
Using string `json:"using,omitempty"` // USING expression
WithCheck string `json:"with_check,omitempty"` // WITH CHECK expression
Comment string `json:"comment,omitempty"`
}
RLSPolicy represents a Row Level Security policy
func (*RLSPolicy) IsDiffSource ¶
func (p *RLSPolicy) IsDiffSource()
type Schema ¶
type Schema struct {
Name string `json:"name"`
Owner string `json:"owner"` // Schema owner
// Note: Indexes, Triggers, and RLS Policies are stored at table level (Table.Indexes, Table.Triggers, Table.Policies)
Tables map[string]*Table `json:"tables"` // table_name -> Table
Views map[string]*View `json:"views"` // view_name -> View
Functions map[string]*Function `json:"functions"` // function_name -> Function
Procedures map[string]*Procedure `json:"procedures"` // procedure_name -> Procedure
Aggregates map[string]*Aggregate `json:"aggregates"` // aggregate_name -> Aggregate
Sequences map[string]*Sequence `json:"sequences"` // sequence_name -> Sequence
Types map[string]*Type `json:"types"` // type_name -> Type
// contains filtered or unexported fields
}
Schema represents a single database schema (namespace)
func (*Schema) GetAggregate ¶
GetAggregate retrieves an aggregate from the schema with thread safety
func (*Schema) GetFunction ¶
GetFunction retrieves a function from the schema with thread safety
func (*Schema) GetProcedure ¶
GetProcedure retrieves a procedure from the schema with thread safety
func (*Schema) GetSequence ¶
GetSequence retrieves a sequence from the schema with thread safety
func (*Schema) SetAggregate ¶
SetAggregate sets an aggregate in the schema with thread safety
func (*Schema) SetFunction ¶
SetFunction sets a function in the schema with thread safety
func (*Schema) SetProcedure ¶
SetProcedure sets a procedure in the schema with thread safety
func (*Schema) SetSequence ¶
SetSequence sets a sequence in the schema with thread safety
type Sequence ¶
type Sequence struct {
Schema string `json:"schema"`
Name string `json:"name"`
DataType string `json:"data_type"`
StartValue int64 `json:"start_value"`
MinValue *int64 `json:"min_value,omitempty"`
MaxValue *int64 `json:"max_value,omitempty"`
Increment int64 `json:"increment"`
CycleOption bool `json:"cycle_option"`
Cache *int64 `json:"cache,omitempty"`
OwnedByTable string `json:"owned_by_table,omitempty"`
OwnedByColumn string `json:"owned_by_column,omitempty"`
Comment string `json:"comment,omitempty"`
}
Sequence represents a database sequence
func (*Sequence) IsDiffSource ¶
func (s *Sequence) IsDiffSource()
type Table ¶
type Table struct {
Schema string `json:"schema"`
Name string `json:"name"`
Type TableType `json:"type"` // BASE_TABLE, VIEW, etc.
IsExternal bool `json:"is_external,omitempty"` // True if table is externally managed (e.g., in ignored schemas)
Columns []*Column `json:"columns"`
Constraints map[string]*Constraint `json:"constraints"` // constraint_name -> Constraint
Indexes map[string]*Index `json:"indexes"` // index_name -> Index
Triggers map[string]*Trigger `json:"triggers"` // trigger_name -> Trigger
RLSEnabled bool `json:"rls_enabled"`
Policies map[string]*RLSPolicy `json:"policies"` // policy_name -> RLSPolicy
Dependencies []TableDependency `json:"dependencies"`
Comment string `json:"comment,omitempty"`
IsPartitioned bool `json:"is_partitioned"`
PartitionStrategy string `json:"partition_strategy,omitempty"` // RANGE, LIST, HASH
PartitionKey string `json:"partition_key,omitempty"` // Column(s) used for partitioning
LikeClauses []LikeClause `json:"like_clauses,omitempty"` // LIKE clauses in CREATE TABLE
}
Table represents a database table
func (*Table) IsDiffSource ¶
func (t *Table) IsDiffSource()
DiffSource interface implementations for IR types
type TableDependency ¶
type TableDependency struct {
Schema string `json:"schema"`
Name string `json:"name"`
Type DependencyType `json:"type"`
}
TableDependency represents a dependency between database objects
type Trigger ¶
type Trigger struct {
Schema string `json:"schema"`
Table string `json:"table"`
Name string `json:"name"`
Timing TriggerTiming `json:"timing"` // BEFORE, AFTER, INSTEAD OF
Events []TriggerEvent `json:"events"` // INSERT, UPDATE, DELETE
Level TriggerLevel `json:"level"` // ROW, STATEMENT
Function string `json:"function"`
Condition string `json:"condition,omitempty"` // WHEN condition
Comment string `json:"comment,omitempty"`
IsConstraint bool `json:"is_constraint,omitempty"` // Whether this is a constraint trigger
Deferrable bool `json:"deferrable,omitempty"` // Can be deferred until end of transaction
InitiallyDeferred bool `json:"initially_deferred,omitempty"` // Whether deferred by default
OldTable string `json:"old_table,omitempty"` // REFERENCING OLD TABLE AS name
NewTable string `json:"new_table,omitempty"` // REFERENCING NEW TABLE AS name
}
Trigger represents a database trigger
func (*Trigger) IsDiffSource ¶
func (t *Trigger) IsDiffSource()
type TriggerEvent ¶
type TriggerEvent string
TriggerEvent represents the event that triggers the trigger
const ( TriggerEventInsert TriggerEvent = "INSERT" TriggerEventUpdate TriggerEvent = "UPDATE" TriggerEventDelete TriggerEvent = "DELETE" TriggerEventTruncate TriggerEvent = "TRUNCATE" )
type TriggerLevel ¶
type TriggerLevel string
TriggerLevel represents the level at which the trigger fires
const ( TriggerLevelRow TriggerLevel = "ROW" TriggerLevelStatement TriggerLevel = "STATEMENT" )
type TriggerTiming ¶
type TriggerTiming string
TriggerTiming represents the timing of trigger execution
const ( TriggerTimingBefore TriggerTiming = "BEFORE" TriggerTimingAfter TriggerTiming = "AFTER" TriggerTimingInsteadOf TriggerTiming = "INSTEAD_OF" )
type Type ¶
type Type struct {
Schema string `json:"schema"`
Name string `json:"name"`
Kind TypeKind `json:"kind"`
Comment string `json:"comment,omitempty"`
EnumValues []string `json:"enum_values,omitempty"` // For ENUM types
Columns []*TypeColumn `json:"columns,omitempty"` // For composite types
BaseType string `json:"base_type,omitempty"` // For DOMAIN types
NotNull bool `json:"not_null,omitempty"` // For DOMAIN types
Default string `json:"default,omitempty"` // For DOMAIN types
Constraints []*DomainConstraint `json:"constraints,omitempty"` // For DOMAIN types
}
Type represents a PostgreSQL user-defined type
func (*Type) IsDiffSource ¶
func (t *Type) IsDiffSource()
type TypeColumn ¶
type TypeColumn struct {
Name string `json:"name"`
DataType string `json:"data_type"`
Position int `json:"position"`
}
TypeColumn represents a column in a composite type
type View ¶
type View struct {
Schema string `json:"schema"`
Name string `json:"name"`
Definition string `json:"definition"`
Comment string `json:"comment,omitempty"`
Materialized bool `json:"materialized,omitempty"`
Indexes map[string]*Index `json:"indexes,omitempty"` // For materialized views only
}
View represents a database view
func (*View) IsDiffSource ¶
func (v *View) IsDiffSource()