sql

package
v0.0.0-...-fcef4a4 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatValidationResult

func FormatValidationResult(result *SchemaValidationResult) string

FormatValidationResult formats the validation result as a human-readable string

Types

type Analyzer

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

Analyzer performs drift analysis on GCP Cloud SQL instances

func NewAnalyzer

func NewAnalyzer(ctx context.Context) (*Analyzer, error)

NewAnalyzer creates a new Analyzer instance with GCP API client

func (*Analyzer) Analyze

func (a *Analyzer) Analyze(ctx context.Context, projects []string) error

Analyze performs drift analysis implementing analyzer.ResourceAnalyzer interface

func (*Analyzer) AnalyzeDrift

func (a *Analyzer) AnalyzeDrift(instances []*DatabaseInstance, baseline *DatabaseConfig) *DriftReport

AnalyzeDrift compares discovered instances against a baseline and generates a drift report

func (*Analyzer) AnalyzeInstance

func (a *Analyzer) AnalyzeInstance(inst *DatabaseInstance, baseline *DatabaseConfig) *InstanceDrift

AnalyzeInstance compares a single instance against the baseline configuration (public method)

func (*Analyzer) Close

func (a *Analyzer) Close() error

Close releases resources held by the Analyzer

func (*Analyzer) DiscoverInstances

func (a *Analyzer) DiscoverInstances(ctx context.Context, projects []string) ([]*DatabaseInstance, error)

DiscoverInstances finds all PostgreSQL instances across the specified GCP projects

func (*Analyzer) GenerateReport

func (a *Analyzer) GenerateReport() (string, error)

GenerateReport generates a formatted report implementing analyzer.ResourceAnalyzer interface

func (*Analyzer) GetDriftCount

func (a *Analyzer) GetDriftCount() int

GetDriftCount returns the number of drifts detected implementing analyzer.ResourceAnalyzer interface

func (*Analyzer) GetTimestamp

func (a *Analyzer) GetTimestamp() time.Time

GetTimestamp returns the current timestamp for report generation

type CachedSchema

type CachedSchema struct {
	ConnectionName string          `json:"connection_name" yaml:"connection_name"`
	Database       string          `json:"database" yaml:"database"`
	Timestamp      time.Time       `json:"timestamp" yaml:"timestamp"`
	Schema         *DatabaseSchema `json:"schema" yaml:"schema"`
}

CachedSchema represents a cached database schema with metadata

type ColumnInfo

type ColumnInfo struct {
	Name         string
	DataType     string
	IsNullable   bool
	DefaultValue *string
	IsIdentity   bool
}

ColumnInfo contains column metadata

type Command

type Command struct {
	Projects       string
	ProjectList    []string
	Baselines      []SQLBaseline
	OutputFile     string
	Format         string
	FilterRole     string
	GenerateConfig bool
}

Command handles Cloud SQL drift analysis operations

func (*Command) Execute

func (c *Command) Execute(ctx context.Context) error

Execute runs the SQL drift analysis command

type Config

type Config struct {
	Projects            []string             `yaml:"projects"`
	Baselines           []SQLBaseline        `yaml:"baselines,omitempty"`
	DatabaseConnections []DatabaseConnection `yaml:"database_connections,omitempty"`

	// Legacy single baseline support
	Baseline     *DatabaseConfig   `yaml:"baseline,omitempty"`
	FilterLabels map[string]string `yaml:"filter_labels,omitempty"`
}

Config represents the YAML configuration file structure for SQL

type ConnectionConfig

type ConnectionConfig struct {
	InstanceConnectionName string `yaml:"instance_connection_name,omitempty"` // format: project:region:instance
	Database               string `yaml:"database,omitempty"`
	Username               string `yaml:"username,omitempty"`
	Password               string `yaml:"password,omitempty"`
	UsePrivateIP           bool   `yaml:"use_private_ip,omitempty"`
	Project                string `yaml:"project,omitempty"`

	// For instances without connection name format
	InstanceName string `yaml:"instance_name,omitempty"`
	Region       string `yaml:"region,omitempty"`
}

ConnectionConfig holds database connection information (kept for backward compatibility)

func (*ConnectionConfig) GetConnectionName

func (c *ConnectionConfig) GetConnectionName() string

GetConnectionName returns the full instance connection name Either from the explicit field or constructed from project:region:instance

func (*ConnectionConfig) Validate

func (c *ConnectionConfig) Validate() error

Validate checks if the connection config has required fields

type ConstraintInfo

type ConstraintInfo struct {
	Name       string
	Type       string // PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK
	Definition string
}

ConstraintInfo contains constraint metadata

type CountMismatch

type CountMismatch struct {
	ObjectType string
	Expected   int
	Actual     int
}

CountMismatch represents a mismatch in expected vs actual counts

type DatabaseConfig

type DatabaseConfig struct {
	DatabaseVersion   string            `yaml:"database_version" json:"database_version"`
	Tier              string            `yaml:"tier" json:"tier"`
	DatabaseFlags     map[string]string `yaml:"database_flags,omitempty" json:"database_flags,omitempty"`
	Settings          *Settings         `yaml:"settings,omitempty" json:"settings,omitempty"`
	DiskSize          int64             `yaml:"disk_size_gb" json:"disk_size_gb"`
	DiskType          string            `yaml:"disk_type" json:"disk_type"`
	DiskAutoresize    bool              `yaml:"disk_autoresize" json:"disk_autoresize"`
	MaintenanceDenied []string          `yaml:"maintenance_denied_periods,omitempty" json:"maintenance_denied_periods,omitempty"`
	RequiredDatabases []string          `yaml:"required_databases,omitempty" json:"required_databases,omitempty"`
}

DatabaseConfig holds the configuration parameters for a PostgreSQL instance

type DatabaseConnection

type DatabaseConnection struct {
	Name                   string `yaml:"name"`                     // Friendly name
	InstanceConnectionName string `yaml:"instance_connection_name"` // project:region:instance
	Database               string `yaml:"database"`                 // Database name
	Username               string `yaml:"username"`                 // DB user
	Password               string `yaml:"password,omitempty"`       // Password (or use IAM)
	UsePrivateIP           bool   `yaml:"use_private_ip,omitempty"` // Private IP connection

	// Optional: construct connection name from parts
	Project      string `yaml:"project,omitempty"`
	Region       string `yaml:"region,omitempty"`
	InstanceName string `yaml:"instance_name,omitempty"`

	// SSH Tunnel configuration (for bastion/jump host access)
	SSHTunnel *SSHTunnelConfig `yaml:"ssh_tunnel,omitempty"`

	// Schema baseline expectations for drift detection
	SchemaBaseline *SchemaBaseline `yaml:"schema_baseline,omitempty"`
}

DatabaseConnection represents connection info for database schema inspection This is separate from infrastructure - focuses on inspecting database content: tables, views, functions, procedures, owners, roles, etc.

func (*DatabaseConnection) GetConnectionName

func (dc *DatabaseConnection) GetConnectionName() string

GetConnectionName returns the full instance connection name

func (*DatabaseConnection) ToConnectionConfig

func (dc *DatabaseConnection) ToConnectionConfig() *ConnectionConfig

ToConnectionConfig converts to ConnectionConfig for backward compatibility

func (*DatabaseConnection) Validate

func (dc *DatabaseConnection) Validate() error

Validate checks if the database connection config is valid

type DatabaseInspector

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

DatabaseInspector connects to PostgreSQL instances and extracts detailed information

func NewCloudSQLInspector

func NewCloudSQLInspector(instanceConnectionName, user, password, database string) *DatabaseInspector

NewCloudSQLInspector creates a new database inspector using Cloud SQL connector

func NewDatabaseInspector

func NewDatabaseInspector(host, user, password, database string, port int) *DatabaseInspector

NewDatabaseInspector creates a new database inspector with direct connection

func NewInspectorFromConnectionConfig

func NewInspectorFromConnectionConfig(config *ConnectionConfig) (*DatabaseInspector, error)

NewInspectorFromConnectionConfig creates a new database inspector from ConnectionConfig

func NewInspectorFromDatabaseConnection

func NewInspectorFromDatabaseConnection(conn *DatabaseConnection) (*DatabaseInspector, error)

NewInspectorFromDatabaseConnection creates a new database inspector from DatabaseConnection

func NewInspectorWithProxy

func NewInspectorWithProxy(instanceConnectionName, user, password, database string, usePrivateIP bool) (*DatabaseInspector, error)

NewInspectorWithProxy creates a new inspector that manages a proxy process

func NewInspectorWithSSHTunnel

func NewInspectorWithSSHTunnel(conn *DatabaseConnection) (*DatabaseInspector, error)

NewInspectorWithSSHTunnel creates a new inspector that uses SSH tunnel through bastion

func (*DatabaseInspector) InspectDatabase

func (di *DatabaseInspector) InspectDatabase(ctx context.Context) (*DatabaseSchema, error)

InspectDatabase connects and extracts detailed schema information

type DatabaseInstance

type DatabaseInstance struct {
	Project           string
	Name              string
	State             string
	Region            string
	Config            *DatabaseConfig
	MaintenanceWindow *MaintenanceWindow
	Labels            map[string]string
	Databases         []string
}

DatabaseInstance represents a GCP Cloud SQL PostgreSQL instance with its configuration

type DatabaseSchema

type DatabaseSchema struct {
	DatabaseName string
	Owner        string
	Encoding     string
	Collation    string
	Roles        []Role
	Tables       []TableInfo
	Views        []ViewInfo
	Sequences    []SequenceInfo
	Functions    []FunctionInfo
	Procedures   []ProcedureInfo
	Extensions   []Extension
}

DatabaseSchema contains detailed schema information

func (*DatabaseSchema) FormatSchemaReport

func (schema *DatabaseSchema) FormatSchemaReport() string

FormatSchemaReport generates a human-readable report

func (*DatabaseSchema) GenerateDDL

func (schema *DatabaseSchema) GenerateDDL() string

GenerateDDL generates DDL statements from the schema

type Drift

type Drift = report.Drift

Drift represents a single configuration difference from the baseline

type DriftReport

type DriftReport struct {
	Timestamp        time.Time        `json:"timestamp" yaml:"timestamp"`
	TotalInstances   int              `json:"total_instances" yaml:"total_instances"`
	DriftedInstances int              `json:"drifted_instances" yaml:"drifted_instances"`
	Instances        []*InstanceDrift `json:"instances" yaml:"instances"`
}

DriftReport contains the complete analysis results for all instances

func (*DriftReport) FormatJSON

func (r *DriftReport) FormatJSON() (string, error)

FormatJSON generates JSON output of the drift report

func (*DriftReport) FormatText

func (r *DriftReport) FormatText() string

FormatText generates a human-readable text report with summary and detailed drift information

func (*DriftReport) FormatYAML

func (r *DriftReport) FormatYAML() (string, error)

FormatYAML generates YAML output of the drift report

type Extension

type Extension struct {
	Name    string
	Version string
	Schema  string
}

Extension represents a PostgreSQL extension

type ForbiddenObject

type ForbiddenObject struct {
	ObjectType string
	Name       string
}

ForbiddenObject represents an object that shouldn't exist but does

type FunctionInfo

type FunctionInfo struct {
	Schema     string
	Name       string
	Owner      string
	Language   string
	ReturnType string
	Arguments  string
	Definition string
}

FunctionInfo contains function metadata

type IPConfiguration

type IPConfiguration struct {
	IPv4Enabled        bool     `yaml:"ipv4_enabled" json:"ipv4_enabled"`
	PrivateNetworkID   string   `yaml:"private_network,omitempty" json:"private_network,omitempty"`
	RequireSSL         bool     `yaml:"require_ssl" json:"require_ssl"`
	AuthorizedNetworks []string `yaml:"authorized_networks,omitempty" json:"authorized_networks,omitempty"`
}

IPConfiguration defines network and security settings for database access

type IndexInfo

type IndexInfo struct {
	Name       string
	Columns    []string
	IsUnique   bool
	IsPrimary  bool
	Definition string
}

IndexInfo contains index metadata

type InsightsConfig

type InsightsConfig struct {
	QueryInsightsEnabled  bool  `yaml:"query_insights_enabled" json:"query_insights_enabled"`
	QueryPlansPerMinute   int64 `yaml:"query_plans_per_minute" json:"query_plans_per_minute"`
	QueryStringLength     int64 `yaml:"query_string_length" json:"query_string_length"`
	RecordApplicationTags bool  `yaml:"record_application_tags" json:"record_application_tags"`
}

InsightsConfig configures Query Insights for performance monitoring

type InspectorConfig

type InspectorConfig struct {
	// Cloud SQL connection (recommended)
	UseCloudSQL            bool
	InstanceConnectionName string // format: project:region:instance
	UsePrivateIP           bool
	UseProxy               bool // if true, starts Cloud SQL Proxy in background
	UseGcloudProxy         bool // if true, uses gcloud instead of cloud-sql-proxy binary
	ProxyPort              int  // local port for proxy (default: 5432)

	// Direct connection (alternative)
	Host string
	Port int

	// Common fields
	User     string
	Password string
	Database string
}

InspectorConfig holds configuration for creating an inspector

type InstanceDrift

type InstanceDrift struct {
	Project           string             `json:"project" yaml:"project"`
	Name              string             `json:"name" yaml:"name"`
	Region            string             `json:"region" yaml:"region"`
	State             string             `json:"state" yaml:"state"`
	Labels            map[string]string  `json:"labels,omitempty" yaml:"labels,omitempty"`
	Databases         []string           `json:"databases,omitempty" yaml:"databases,omitempty"`
	MaintenanceWindow *MaintenanceWindow `json:"maintenance_window,omitempty" yaml:"maintenance_window,omitempty"`
	Drifts            []Drift            `json:"drifts" yaml:"drifts"`
	Recommendations   []string           `json:"recommendations" yaml:"recommendations"`
}

InstanceDrift represents drift analysis results for a single database instance

func (*InstanceDrift) FormatText

func (id *InstanceDrift) FormatText() string

FormatText generates a formatted text representation of instance drift details

type MaintenanceWindow

type MaintenanceWindow struct {
	Day         int    `yaml:"day" json:"day"`
	Hour        int    `yaml:"hour" json:"hour"`
	UpdateTrack string `yaml:"update_track" json:"update_track"`
}

MaintenanceWindow defines when database maintenance can occur

type MissingObject

type MissingObject struct {
	ObjectType string
	Name       string
}

MissingObject represents a required object that doesn't exist

type OwnershipViolation

type OwnershipViolation struct {
	ObjectType    string
	ObjectName    string
	ActualOwner   string
	ExpectedOwner string
	ViolationType string // "wrong_owner", "forbidden_owner", "database_owner"
}

OwnershipViolation represents an object with incorrect ownership

type ProcedureInfo

type ProcedureInfo struct {
	Schema     string
	Name       string
	Owner      string
	Language   string
	Arguments  string
	Definition string
}

ProcedureInfo contains procedure metadata

type ProxyConfig

type ProxyConfig struct {
	InstanceConnectionName string
	LocalPort              int // Local port to bind (default: 5432)
	UsePrivateIP           bool
	UseGcloud              bool // Use gcloud command instead of cloud-sql-proxy binary
}

ProxyConfig configures the proxy manager

type ProxyManager

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

ProxyManager manages Cloud SQL Proxy or gcloud proxy processes

func NewProxyManager

func NewProxyManager(config ProxyConfig) *ProxyManager

NewProxyManager creates a new proxy manager

func (*ProxyManager) GetLocalPort

func (pm *ProxyManager) GetLocalPort() int

GetLocalPort returns the local port the proxy is listening on

func (*ProxyManager) IsRunning

func (pm *ProxyManager) IsRunning() bool

IsRunning checks if the proxy is running

func (*ProxyManager) Start

func (pm *ProxyManager) Start(ctx context.Context) error

Start launches the proxy process in the background

func (*ProxyManager) Stop

func (pm *ProxyManager) Stop() error

Stop terminates the proxy process

type Role

type Role struct {
	Name          string
	IsSuperuser   bool
	CanLogin      bool
	CanCreateDB   bool
	CanCreateRole bool
	MemberOf      []string
}

Role represents a PostgreSQL role/user

type SQLBaseline

type SQLBaseline struct {
	Name         string            `yaml:"name,omitempty"`
	FilterLabels map[string]string `yaml:"filter_labels,omitempty"`
	Config       *DatabaseConfig   `yaml:"config"`
}

SQLBaseline represents a Cloud SQL INSTANCE configuration baseline This is for infrastructure drift: instance settings, flags, disk, etc.

func (SQLBaseline) GetName

func (b SQLBaseline) GetName() string

GetName returns the baseline name implementing analyzer.Baseline interface

func (SQLBaseline) Validate

func (b SQLBaseline) Validate() error

Validate checks if the baseline is valid implementing analyzer.Baseline interface

type SSHTunnelConfig

type SSHTunnelConfig struct {
	Enabled      bool   `yaml:"enabled"`                  // Enable SSH tunnel
	BastionHost  string `yaml:"bastion_host"`             // Bastion host name (e.g., "bastion")
	BastionZone  string `yaml:"bastion_zone"`             // GCE zone (e.g., "us-west1-a")
	Project      string `yaml:"project"`                  // GCP project
	LocalPort    int    `yaml:"local_port,omitempty"`     // Local port (default: 5432)
	PrivateIP    string `yaml:"private_ip"`               // Cloud SQL private IP
	RemotePort   int    `yaml:"remote_port,omitempty"`    // Remote port (default: 5432)
	UseIAP       bool   `yaml:"use_iap"`                  // Use Identity-Aware Proxy
	SSHKeyExpiry string `yaml:"ssh_key_expiry,omitempty"` // SSH key expiry (default: 1h)
}

SSHTunnelConfig defines SSH tunnel configuration for accessing private databases

type SSHTunnelManager

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

SSHTunnelManager manages SSH tunnel connections through bastion hosts

func NewSSHTunnelManager

func NewSSHTunnelManager(config *SSHTunnelConfig) (*SSHTunnelManager, error)

NewSSHTunnelManager creates a new SSH tunnel manager

func (*SSHTunnelManager) GetConnectionString

func (stm *SSHTunnelManager) GetConnectionString(user, password, database string) string

GetConnectionString returns a connection string that uses the SSH tunnel

func (*SSHTunnelManager) GetLocalPort

func (stm *SSHTunnelManager) GetLocalPort() int

GetLocalPort returns the local port the tunnel is listening on

func (*SSHTunnelManager) IsConnected

func (stm *SSHTunnelManager) IsConnected() bool

IsConnected returns whether the tunnel is currently active

func (*SSHTunnelManager) Start

func (stm *SSHTunnelManager) Start(ctx context.Context) error

Start establishes the SSH tunnel through the bastion host

func (*SSHTunnelManager) Stop

func (stm *SSHTunnelManager) Stop() error

Stop closes the SSH tunnel

type SchemaBaseline

type SchemaBaseline struct {
	// Expected counts
	ExpectedTables     *int `yaml:"expected_tables,omitempty"`
	ExpectedViews      *int `yaml:"expected_views,omitempty"`
	ExpectedSequences  *int `yaml:"expected_sequences,omitempty"`
	ExpectedFunctions  *int `yaml:"expected_functions,omitempty"`
	ExpectedProcedures *int `yaml:"expected_procedures,omitempty"`
	ExpectedRoles      *int `yaml:"expected_roles,omitempty"`
	ExpectedExtensions *int `yaml:"expected_extensions,omitempty"`

	// Required objects (must exist)
	RequiredTables     []string `yaml:"required_tables,omitempty"`
	RequiredViews      []string `yaml:"required_views,omitempty"`
	RequiredFunctions  []string `yaml:"required_functions,omitempty"`
	RequiredProcedures []string `yaml:"required_procedures,omitempty"`
	RequiredExtensions []string `yaml:"required_extensions,omitempty"`

	// Forbidden objects (must not exist)
	ForbiddenTables []string `yaml:"forbidden_tables,omitempty"`

	// Ownership validation
	ExpectedDatabaseOwner  string   `yaml:"expected_database_owner,omitempty"`  // e.g., "cloudsqlsuperuser"
	ExpectedTableOwner     string   `yaml:"expected_table_owner,omitempty"`     // Default owner for all tables
	ExpectedViewOwner      string   `yaml:"expected_view_owner,omitempty"`      // Default owner for all views
	ExpectedSequenceOwner  string   `yaml:"expected_sequence_owner,omitempty"`  // Default owner for all sequences
	ExpectedFunctionOwner  string   `yaml:"expected_function_owner,omitempty"`  // Default owner for all functions
	ExpectedProcedureOwner string   `yaml:"expected_procedure_owner,omitempty"` // Default owner for all procedures
	AllowedOwners          []string `yaml:"allowed_owners,omitempty"`           // List of allowed owners
	ForbiddenOwners        []string `yaml:"forbidden_owners,omitempty"`         // Owners that should not exist

	// Specific ownership exceptions
	TableOwnerExceptions     map[string]string `yaml:"table_owner_exceptions,omitempty"`     // table -> expected owner
	ViewOwnerExceptions      map[string]string `yaml:"view_owner_exceptions,omitempty"`      // view -> expected owner
	SequenceOwnerExceptions  map[string]string `yaml:"sequence_owner_exceptions,omitempty"`  // sequence -> expected owner
	FunctionOwnerExceptions  map[string]string `yaml:"function_owner_exceptions,omitempty"`  // function -> expected owner
	ProcedureOwnerExceptions map[string]string `yaml:"procedure_owner_exceptions,omitempty"` // procedure -> expected owner
}

SchemaBaseline defines expected schema counts and specific objects

type SchemaCache

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

SchemaCache manages local caching of inspected database schemas

func NewSchemaCache

func NewSchemaCache(cacheDir string) (*SchemaCache, error)

NewSchemaCache creates a new schema cache manager

func (*SchemaCache) Clear

func (sc *SchemaCache) Clear() error

Clear removes all cached schemas

func (*SchemaCache) Delete

func (sc *SchemaCache) Delete(connectionName string, database string) error

Delete removes a cached schema

func (*SchemaCache) Exists

func (sc *SchemaCache) Exists(connectionName string, database string) bool

Exists checks if a cache file exists for the given connection

func (*SchemaCache) ExportYAML

func (sc *SchemaCache) ExportYAML(connectionName string, database string, outputPath string) error

ExportYAML exports a cached schema to YAML format

func (*SchemaCache) GetAge

func (sc *SchemaCache) GetAge(connectionName string, database string) (time.Duration, error)

GetAge returns how old the cached schema is

func (*SchemaCache) GetCacheDir

func (sc *SchemaCache) GetCacheDir() string

GetCacheDir returns the cache directory path

func (*SchemaCache) List

func (sc *SchemaCache) List() ([]CachedSchema, error)

List returns all cached schemas

func (*SchemaCache) Load

func (sc *SchemaCache) Load(connectionName string, database string) (*CachedSchema, error)

Load retrieves a cached database schema

func (*SchemaCache) Save

func (sc *SchemaCache) Save(connectionName string, database string, schema *DatabaseSchema) error

Save stores a database schema to local cache

type SchemaDiff

type SchemaDiff struct {
	OldTimestamp string `json:"old_timestamp" yaml:"old_timestamp"`
	NewTimestamp string `json:"new_timestamp" yaml:"new_timestamp"`

	AddedTables    []TableInfo `json:"added_tables,omitempty" yaml:"added_tables,omitempty"`
	DeletedTables  []TableInfo `json:"deleted_tables,omitempty" yaml:"deleted_tables,omitempty"`
	ModifiedTables []TableInfo `json:"modified_tables,omitempty" yaml:"modified_tables,omitempty"`

	AddedViews   []ViewInfo `json:"added_views,omitempty" yaml:"added_views,omitempty"`
	DeletedViews []ViewInfo `json:"deleted_views,omitempty" yaml:"deleted_views,omitempty"`

	AddedRoles   []string `json:"added_roles,omitempty" yaml:"added_roles,omitempty"`
	DeletedRoles []string `json:"deleted_roles,omitempty" yaml:"deleted_roles,omitempty"`

	AddedExtensions   []Extension `json:"added_extensions,omitempty" yaml:"added_extensions,omitempty"`
	DeletedExtensions []Extension `json:"deleted_extensions,omitempty" yaml:"deleted_extensions,omitempty"`
}

SchemaDiff represents differences between two database schemas

func CompareSchemas

func CompareSchemas(old *DatabaseSchema, new *DatabaseSchema) *SchemaDiff

CompareSchemas compares two schemas and returns differences

func (*SchemaDiff) HasChanges

func (sd *SchemaDiff) HasChanges() bool

HasChanges returns true if there are any differences

type SchemaValidationResult

type SchemaValidationResult struct {
	HasDrift            bool
	CountMismatches     []CountMismatch
	MissingObjects      []MissingObject
	ForbiddenObjects    []ForbiddenObject
	OwnershipViolations []OwnershipViolation
}

SchemaValidationResult contains the results of schema baseline validation

func ValidateSchemaAgainstBaseline

func ValidateSchemaAgainstBaseline(schema *DatabaseSchema, baseline *SchemaBaseline) *SchemaValidationResult

ValidateSchemaAgainstBaseline validates a database schema against baseline expectations

type SequenceInfo

type SequenceInfo struct {
	Schema     string
	Name       string
	Owner      string
	DataType   string
	StartValue int64
	MinValue   *int64
	MaxValue   *int64
	Increment  int64
}

SequenceInfo contains sequence metadata

type Settings

type Settings struct {
	AvailabilityType            string           `yaml:"availability_type" json:"availability_type"`
	BackupEnabled               bool             `yaml:"backup_enabled" json:"backup_enabled"`
	BackupStartTime             string           `yaml:"backup_start_time,omitempty" json:"backup_start_time,omitempty"`
	BackupRetentionDays         int64            `yaml:"backup_retention_days,omitempty" json:"backup_retention_days,omitempty"`
	PointInTimeRecovery         bool             `yaml:"point_in_time_recovery" json:"point_in_time_recovery"`
	TransactionLogRetentionDays int64            `yaml:"transaction_log_retention_days,omitempty" json:"transaction_log_retention_days,omitempty"`
	IPConfiguration             *IPConfiguration `yaml:"ip_configuration,omitempty" json:"ip_configuration,omitempty"`
	LocationPreference          string           `yaml:"location_preference,omitempty" json:"location_preference,omitempty"`
	DataDiskSizeGb              int64            `yaml:"data_disk_size_gb" json:"data_disk_size_gb"`
	PricingPlan                 string           `yaml:"pricing_plan" json:"pricing_plan"`
	ReplicationType             string           `yaml:"replication_type" json:"replication_type"`
	InsightsConfig              *InsightsConfig  `yaml:"insights_config,omitempty" json:"insights_config,omitempty"`
}

Settings contains the runtime and operational settings for a database instance

type StringArray

type StringArray []string

StringArray is a helper type for scanning PostgreSQL arrays

func (*StringArray) Scan

func (a *StringArray) Scan(src interface{}) error

type TableInfo

type TableInfo struct {
	Schema      string
	Name        string
	Owner       string
	RowCount    int64
	SizeBytes   int64
	Columns     []ColumnInfo
	Constraints []ConstraintInfo
	Indexes     []IndexInfo
}

TableInfo contains table metadata

type ViewInfo

type ViewInfo struct {
	Schema     string
	Name       string
	Owner      string
	Definition string
}

ViewInfo contains view metadata

Jump to

Keyboard shortcuts

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