Documentation
¶
Overview ¶
Package postgresql provides a database provider for PostgreSQL.
Index ¶
- type Provider
- func (p *Provider) ConvertFieldType(field *types.Field) string
- func (p *Provider) ConvertFieldTypeWithSchema(schema *types.Schema, field *types.Field) string
- func (p *Provider) GenerateAddColumn(tableName string, field *types.Field) string
- func (p *Provider) GenerateAlterColumn(tableName string, oldField, newField *types.Field) (string, error)
- func (p *Provider) GenerateCreateIndex(index *types.Index, tableName string) string
- func (p *Provider) GenerateCreateTable(schema *types.Schema, table *types.Table) (string, error)
- func (p *Provider) GenerateDropColumn(tableName, columnName string) string
- func (p *Provider) GenerateDropForeignKeyConstraint(tableName, constraintName string) string
- func (p *Provider) GenerateDropIndex(indexName, tableName string) string
- func (p *Provider) GenerateDropTable(tableName string) string
- func (p *Provider) GenerateDropTableCascade(tableName string) string
- func (p *Provider) GenerateForeignKeyConstraint(...) string
- func (p *Provider) GenerateForeignKeyConstraints(schema *types.Schema, junctionTables []types.Table) string
- func (p *Provider) GenerateIndexes(schema *types.Schema) string
- func (p *Provider) GenerateJunctionTable(table1, table2 string, schema *types.Schema) (string, error)
- func (p *Provider) GenerateRenameColumn(tableName, oldName, newName string) string
- func (p *Provider) GenerateRenameTable(oldName, newName string) string
- func (p *Provider) GenerateUpsert(table string, conflictKeys []string, columns []string, ...) string
- func (p *Provider) GetDatabaseSchema(connectionString string) (*types.Schema, error)
- func (p *Provider) GetDefaultValue(defaultRef string, defaults map[string]string) (string, error)
- func (p *Provider) HistoryTableDDL() string
- func (p *Provider) InferForeignKeyType(referencedTable string, schema *types.Schema) string
- func (p *Provider) IsAlreadyExistsError(err error) bool
- func (p *Provider) IsNotFoundError(err error) bool
- func (p *Provider) Placeholder(n int) string
- func (p *Provider) QuoteName(name string) string
- func (p *Provider) SetTypeMappings(mappings map[string]string)
- func (p *Provider) SupportsOperation(operation string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements the Provider interface for PostgreSQL
func (*Provider) ConvertFieldType ¶
ConvertFieldType converts YAML field type to PostgreSQL-specific SQL type
func (*Provider) ConvertFieldTypeWithSchema ¶
ConvertFieldTypeWithSchema converts YAML field type to PostgreSQL-specific SQL type with schema context for foreign keys
func (*Provider) GenerateAddColumn ¶
GenerateAddColumn generates ALTER TABLE ADD COLUMN statement. The DEFAULT clause is emitted when field.Default is non-empty (already resolved from symbolic keys by resolveFieldDefault before this is called).
func (*Provider) GenerateAlterColumn ¶
func (p *Provider) GenerateAlterColumn(tableName string, oldField, newField *types.Field) (string, error)
GenerateAlterColumn generates one or more ALTER TABLE … ALTER COLUMN statements to transition a column from oldField to newField. Each distinct change (type, nullability, default) becomes its own statement, separated by newlines. Returns an empty string when no attributes differ.
func (*Provider) GenerateCreateIndex ¶
GenerateCreateIndex generates CREATE INDEX statement for PostgreSQL
func (*Provider) GenerateCreateTable ¶
GenerateCreateTable generates the CREATE TABLE SQL statement for the given table.
func (*Provider) GenerateDropColumn ¶
GenerateDropColumn generates ALTER TABLE DROP COLUMN statement
func (*Provider) GenerateDropForeignKeyConstraint ¶
GenerateDropForeignKeyConstraint generates an ALTER TABLE statement to drop a foreign key constraint.
func (*Provider) GenerateDropIndex ¶
GenerateDropIndex generates DROP INDEX statement for PostgreSQL
func (*Provider) GenerateDropTable ¶
GenerateDropTable generates DROP TABLE statement
func (*Provider) GenerateDropTableCascade ¶
GenerateDropTableCascade generates DROP TABLE IF EXISTS ... CASCADE statement for PostgreSQL. The CASCADE clause automatically drops any dependent objects (such as foreign key constraints from other tables referencing this one), preventing ordering failures during rollback.
func (*Provider) GenerateForeignKeyConstraint ¶
func (p *Provider) GenerateForeignKeyConstraint(tableName, fieldName, referencedTable, constraintName, onDelete, onUpdate string) string
GenerateForeignKeyConstraint generates an ALTER TABLE statement to add a foreign key constraint.
func (*Provider) GenerateForeignKeyConstraints ¶
func (p *Provider) GenerateForeignKeyConstraints(schema *types.Schema, junctionTables []types.Table) string
GenerateForeignKeyConstraints generates all foreign key constraint SQL statements for a schema.
func (*Provider) GenerateIndexes ¶
GenerateIndexes generates CREATE INDEX statements for all tables in the schema.
func (*Provider) GenerateJunctionTable ¶
func (p *Provider) GenerateJunctionTable(table1, table2 string, schema *types.Schema) (string, error)
GenerateJunctionTable generates the CREATE TABLE SQL for a many-to-many junction table.
func (*Provider) GenerateRenameColumn ¶
GenerateRenameColumn generates ALTER TABLE RENAME COLUMN statement
func (*Provider) GenerateRenameTable ¶
GenerateRenameTable generates ALTER TABLE RENAME statement
func (*Provider) GenerateUpsert ¶
func (p *Provider) GenerateUpsert(table string, conflictKeys []string, columns []string, valueLiterals [][]string) string
GenerateUpsert generates a multi-row INSERT ... ON CONFLICT DO UPDATE SET statement for PostgreSQL. It accepts pre-formatted SQL value literals that are inserted as-is. If all columns are conflict keys, DO NOTHING is used instead of DO UPDATE SET. Returns an empty string if valueLiterals is empty.
func (*Provider) GetDatabaseSchema ¶
GetDatabaseSchema extracts schema information from a PostgreSQL database
func (*Provider) GetDefaultValue ¶
GetDefaultValue converts default value references to PostgreSQL-specific values
func (*Provider) HistoryTableDDL ¶
HistoryTableDDL returns the CREATE TABLE IF NOT EXISTS statement for the morphic_history migration-tracking table, using this provider's SQL dialect.
func (*Provider) InferForeignKeyType ¶
InferForeignKeyType returns the SQL type to use for a foreign key column referencing the given table.
func (*Provider) IsAlreadyExistsError ¶
IsAlreadyExistsError returns true when err indicates an object already exists in the database.
func (*Provider) IsNotFoundError ¶
IsNotFoundError returns true when err is a PostgreSQL "does not exist" error.
func (*Provider) Placeholder ¶
Placeholder returns the bind-parameter placeholder for the nth argument (1-indexed).
func (*Provider) SetTypeMappings ¶
SetTypeMappings sets user-defined type mappings for this provider.
func (*Provider) SupportsOperation ¶
SupportsOperation checks if PostgreSQL supports a specific operation