dbinspect

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaskPassword

func MaskPassword(connStr string) string

MaskPassword masks the password in a connection string for display.

Types

type DatabaseInfo

type DatabaseInfo struct {
	Name             string
	Owner            string
	Encoding         string
	Collation        string
	CType            string
	IsTemplate       bool
	Size             string
	HasTables        bool
	TableCount       int
	HasMigrations    bool
	MigrationVersion *int
	IsDirty          bool
}

DatabaseInfo represents information about a PostgreSQL database.

type Inspector

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

Inspector provides methods to inspect PostgreSQL databases.

func NewInspector

func NewInspector(connStr string) *Inspector

NewInspector creates a new database inspector.

func (*Inspector) CheckConnection

func (i *Inspector) CheckConnection(ctx context.Context) error

CheckConnection tests if a connection can be established.

func (*Inspector) CheckPermissions

func (i *Inspector) CheckPermissions(ctx context.Context, name string) error

CheckPermissions checks if the user has necessary permissions.

func (*Inspector) DatabaseExists

func (i *Inspector) DatabaseExists(ctx context.Context, name string) (bool, error)

DatabaseExists checks if a database exists.

func (*Inspector) GetDatabaseURL

func (i *Inspector) GetDatabaseURL(name string) string

GetDatabaseURL returns a connection string for a specific database.

func (*Inspector) InspectDatabase

func (i *Inspector) InspectDatabase(ctx context.Context, name string) (*DatabaseInfo, error)

InspectDatabase performs a detailed inspection of a specific database.

func (*Inspector) ListDatabases

func (i *Inspector) ListDatabases(ctx context.Context) ([]DatabaseInfo, error)

ListDatabases returns all databases accessible with the connection string.

type MigrationChecker

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

MigrationChecker checks migration state against database.

func NewMigrationChecker

func NewMigrationChecker(inspector *Inspector, migrationsDir string) *MigrationChecker

NewMigrationChecker creates a new migration checker.

func (*MigrationChecker) CanApplyMigrations

func (m *MigrationChecker) CanApplyMigrations(state *MigrationState, dbHasTables bool) (bool, string)

CanApplyMigrations returns whether migrations can be safely applied.

func (*MigrationChecker) CheckDestructive

func (m *MigrationChecker) CheckDestructive(sql string) bool

CheckDestructive checks if a migration contains potentially destructive operations.

func (*MigrationChecker) CheckState

func (m *MigrationChecker) CheckState(ctx context.Context, dbName string) (*MigrationState, error)

CheckState checks the migration state against the database.

func (*MigrationChecker) LoadMigrations

func (m *MigrationChecker) LoadMigrations() ([]MigrationFile, error)

LoadMigrations loads all migration files from the migrations directory.

type MigrationFile

type MigrationFile struct {
	Version int
	Name    string
	Path    string
	UpSQL   string
	DownSQL string
}

MigrationFile represents a migration file.

type MigrationState

type MigrationState struct {
	CurrentVersion *int
	IsDirty        bool
	Available      []MigrationFile
	Applied        []int
	Pending        []MigrationFile
	HasDestructive bool
}

MigrationState represents the state of migrations.

Jump to

Keyboard shortcuts

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