Documentation
¶
Overview ¶
Package pglint reads an application database migration before it saves (#2405, #2449, #2539): the statements that lock, rewrite or remove data a live table holds, the statements that leave the database open to a role that should not reach it or need a privilege an application's role must not hold, the features the server's major lacks, and the roles a migration names outside its schema. It reads SQL lexically and touches no database; the postgres toolkit's review and an application import run it.
Index ¶
Constants ¶
const ( // SeverityWarning is a statement that locks or rewrites a live table; it // is reported and recorded, and the migration saves. SeverityWarning = "warning" // SeverityDestructive is a statement that removes data; the migration // saves only with an agreed summary of what it removes. SeverityDestructive = "destructive" )
The severities a finding has.
const ( RuleIndexLocks = "create_index_locks" RuleNotNullNoDefault = "not_null_without_default" RuleVolatileDefault = "volatile_default_rewrites" RuleTypeChangeRewrites = "type_change_rewrites" RuleConstraintValidates = "constraint_validates" RuleDropTable = "drop_table" RuleDropColumn = "drop_column" RuleTruncate = "truncate" RuleUnboundedDelete = "unbounded_delete" RuleUnboundedUpdate = "unbounded_update" RuleRenameReferenced = "rename_referenced" RuleLockTimeoutRaised = "lock_timeout_raised" RuleFromZeroUnchecked = "from_zero_unchecked" )
The lint's rules.
const ( RuleIndexVirtualColumn = "index_on_virtual_column" RuleNeedsNewerServer = "feature_needs_newer_server" RuleTargetUnread = "target_unread" )
The rules.
const MigrationLockTimeout = 10 * time.Second
MigrationLockTimeout is how long one migration's statement waits for a lock a running query holds, so a migration never queues behind a long read while every later query queues behind it: what the postgres toolkit sets, and the bound the lock_timeout rule holds a migration to.
const SeverityRefused = "refused"
SeverityRefused is a statement that needs a privilege an application's role must not hold or reaches outside the database; the migration does not save.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Finding ¶
type Finding struct {
Rule string `json:"rule"`
Severity string `json:"severity"`
// Statement is the statement's place in the up SQL, from 1.
Statement int `json:"statement,omitempty"`
// Object is the table, column or setting the statement acts on.
Object string `json:"object,omitempty"`
// Effect is what the statement does to a live table.
Effect string `json:"effect"`
// Safe is the form that does not.
Safe string `json:"safe_form,omitempty"`
// Scripts names the saved scripts that name a renamed object.
Scripts []string `json:"scripts,omitempty"`
}
Finding is one thing the lint found in a migration.
func Destructive ¶
Destructive is the findings that need an agreed summary.
type Rename ¶
type Rename struct {
Statement int
// Table is the table renamed, or the table whose column is renamed.
Table string
// Column is the column renamed; empty for a table.
Column string
}
Rename is a table or column a migration renames.
type Target ¶
type Target struct {
// Major is the server's major, 0 when it could not be read.
Major int
// RowSecurity is the schema's tables with row-level security enabled.
RowSecurity map[string]bool
// Virtual is the schema's virtual generated columns, by table.
Virtual map[string]map[string]bool
// Schema is the schema the migration is for, whose name every role the
// migration names starts with (#2539); empty checks no role.
Schema string
}
Target is what the review knows of the server and schema a migration is for. A zero Target leaves the version rules silent.