{"modulePath":"github.com/stripe/pg-schema-diff","version":"v1.0.9","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package diff\n\n## Variables\n\n```go\nvar (\n\t// ErrColumnOrderingChanged is returned when the ordering of columns changes and column ordering is not ignored.\n\t// It is recommended to ignore column ordering changes to column order\n\tErrColumnOrderingChanged = fmt.Errorf(\"column ordering changed: %w\", ErrNotImplemented)\n)\n```\n\n```go\nvar ErrNotImplemented = fmt.Errorf(\"not implemented\")\n```\n\n## Types\n\n```go\ntype MigrationHazard struct {\n\tType    MigrationHazardType `json:\"type\"`\n\tMessage string              `json:\"message\"`\n}\n```\nMigrationHazard represents a hazard that a statement poses to a database\n\n```go\nfunc (p MigrationHazard) String() string\n```\n\n```go\ntype MigrationHazardType = string\n```\n\n```go\nconst (\n\tMigrationHazardTypeAcquiresAccessExclusiveLock   MigrationHazardType = \"ACQUIRES_ACCESS_EXCLUSIVE_LOCK\"\n\tMigrationHazardTypeAcquiresShareLock             MigrationHazardType = \"ACQUIRES_SHARE_LOCK\"\n\tMigrationHazardTypeAcquiresShareRowExclusiveLock MigrationHazardType = \"ACQUIRES_SHARE_ROW_EXCLUSIVE_LOCK\"\n\tMigrationHazardTypeCorrectness                   MigrationHazardType = \"CORRECTNESS\"\n\tMigrationHazardTypeDeletesData                   MigrationHazardType = \"DELETES_DATA\"\n\tMigrationHazardTypeHasUntrackableDependencies    MigrationHazardType = \"HAS_UNTRACKABLE_DEPENDENCIES\"\n\tMigrationHazardTypeIndexBuild                    MigrationHazardType = \"INDEX_BUILD\"\n\tMigrationHazardTypeIndexDropped                  MigrationHazardType = \"INDEX_DROPPED\"\n\tMigrationHazardTypeImpactsDatabasePerformance    MigrationHazardType = \"IMPACTS_DATABASE_PERFORMANCE\"\n\tMigrationHazardTypeIsUserGenerated               MigrationHazardType = \"IS_USER_GENERATED\"\n\tMigrationHazardTypeExtensionVersionUpgrade       MigrationHazardType = \"UPGRADING_EXTENSION_VERSION\"\n\tMigrationHazardTypeAuthzUpdate                   MigrationHazardType = \"AUTHZ_UPDATE\"\n)\n```\n\n```go\ntype Plan struct {\n\t// Statements is the set of statements to be executed in order to migrate a database from schema A to schema B\n\tStatements []Statement `json:\"statements\"`\n\t// CurrentSchemaHash is the hash of the current schema, schema A. If you serialize this plans somewhere and\n\t// plan on running them later, you should verify that the current schema hash matches the current schema hash.\n\t// To get the current schema hash, you can use schema.GetPublicSchemaHash(ctx, conn)\n\tCurrentSchemaHash string `json:\"current_schema_hash\"`\n}\n```\nPlan represents a set of statements to be executed in order to migrate a database from schema A to schema B\n\n```go\nfunc Generate(\n\tctx context.Context,\n\tfromSchema SchemaSource,\n\ttargetSchema SchemaSource,\n\topts ...PlanOpt,\n) (Plan, error)\n```\nGenerate generates a migration plan to migrate the database to the target schema\n\nParameters: fromSchema:\t\tThe target schema to generate the diff for. targetSchema:\tThe (source of the) schema you want to migrate the database to. Use DDLSchemaSource if the new schema is encoded in DDL. opts: \t\t\tAdditional options to configure the plan generation\n\n```go\nfunc (p Plan) ApplyLockTimeoutModifier(regex *regexp.Regexp, timeout time.Duration) Plan\n```\nApplyLockTimeoutModifier applies the given timeout to all statements that match the given regex\n\n```go\nfunc (p Plan) ApplyStatementTimeoutModifier(regex *regexp.Regexp, timeout time.Duration) Plan\n```\nApplyStatementTimeoutModifier applies the given timeout to all statements that match the given regex\n\n```go\nfunc (p Plan) InsertStatement(index int, statement Statement) (Plan, error)\n```\nInsertStatement inserts the given statement at the given index. If index is equal to the length of the statements, it will append the statement to the end of the statement in the plan\n\n```go\ntype PlanOpt func(opts *planOptions)\n```\n\n```go\nfunc WithDataPackNewTables() PlanOpt\n```\nWithDataPackNewTables configures the plan generation such that it packs the columns in the new tables to minimize padding. It will help minimize the storage used by the tables\n\n```go\nfunc WithDoNotValidatePlan() PlanOpt\n```\nWithDoNotValidatePlan disables plan validation, where the migration plan is tested against a temporary database instance.\n\n```go\nfunc WithExcludeSchemas(schemas ...string) PlanOpt\n```\n\n```go\nfunc WithGetSchemaOpts(getSchemaOpts ...externalschema.GetSchemaOpt) PlanOpt\n```\n\n```go\nfunc WithIncludeSchemas(schemas ...string) PlanOpt\n```\n\n```go\nfunc WithLogger(logger log.Logger) PlanOpt\n```\nWithLogger configures plan generation to use the provided logger instead of the default\n\n```go\nfunc WithNoConcurrentIndexOps() PlanOpt\n```\nWithNoConcurrentIndexOps disables the use of CONCURRENTLY in CREATE INDEX and DROP INDEX statements. This can be useful when you need simpler DDL statements or when working in environments that don't support concurrent index operations. Note that disabling concurrent operations may result in longer lock times and potential downtime during migrations.\n\n```go\nfunc WithRandReader(randReader io.Reader) PlanOpt\n```\nWithRandReader seeds the random used to generate random SQL identifiers, e.g., temporary not-null check constraints.\n\n```go\nfunc WithRespectColumnOrder() PlanOpt\n```\nWithRespectColumnOrder configures the plan generation to respect any changes to the ordering of columns in existing tables. You will most likely want this disabled, since column ordering changes are common\n\n```go\nfunc WithTempDbFactory(factory tempdb.Factory) PlanOpt\n```\n\n```go\ntype SchemaSource interface {\n\tGetSchema(ctx context.Context, deps schemaSourcePlanDeps) (schema.Schema, error)\n}\n```\n\n```go\nfunc DBSchemaSource(queryable sqldb.Queryable) SchemaSource\n```\nDBSchemaSource returns a SchemaSource that returns a schema based on the provided queryable. It is recommended that the sqldb.Queryable is a \\*sql.DB with a max # of connections set.\n\n```go\nfunc DDLSchemaSource(stmts []string) SchemaSource\n```\nDDLSchemaSource returns a SchemaSource that returns a schema based on the provided DDL. You must provide a tempDBFactory via the WithTempDbFactory option.\n\n```go\nfunc DirSchemaSource(dirs []string) (SchemaSource, error)\n```\nDirSchemaSource returns a SchemaSource that returns a schema based on the provided directories. You must provide a tempDBFactory via the WithTempDbFactory option.\n\n```go\ntype Statement struct {\n\tDDL string\n\t// Timeout is the statement_timeout to apply to this statement. If implementing your own plan executor, be sure to set\n\t// the session-level statement_timeout to this value before executing the statement. A transaction-level statement_timeout\n\t// will not work since building indexes concurrently cannot be done in a transaction\n\tTimeout time.Duration\n\t// LockTimeout is the lock_timeout to apply to this statement. If implementing your own plan executor, be sure to set\n\t// the session-level lock_timeout to this value before executing the statement. A transaction-level lock_timeout\n\t// will not work since building indexes concurrently cannot be done in a transaction\n\tLockTimeout time.Duration\n\t// The hazards this statement poses\n\tHazards []MigrationHazard\n\t// SkipValidation indicates that this statement should be skipped during plan validation against a temporary\n\t// database instance. This is useful for statements that depend on entities (like roles) that won't exist\n\t// in the temp DB.\n\tSkipValidation bool\n}\n```\n\n```go\nfunc (s Statement) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (s Statement) ToSQL() string\n```\n\n","path":"github.com/stripe/pg-schema-diff/pkg/diff","name":"diff","synopsis":"","isRedistributable":true}
