{"modulePath":"github.com/kr9ly/sqlshape","version":"v1.2.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package diff\n\nPackage diff compares two schemas object by object and lists what it takes to turn one into the other. It reads what the loader holds of the database state and nothing else: \\`-- sqlshape:\\` directives, problems and analysis results are not schema.\n\nExpressions compare by their deparsed text, so the two sides should be in the same form: both loaded from schema text, or both canonical (dump.Canonical / dump.Load). A rename is not recognized: it shows as a drop and an add, and an intent declaration is the place to say otherwise.\n\n## Functions\n\n```go\nfunc Props(s *schema.Schema, obj any) map[string]string\n```\nProps are the comparable properties of a relation, column, constraint, index, rule, function or trigger: two objects with equal Props are the same to Compare.\n\n```go\nfunc Signature(s *schema.Schema, f *schema.Function) string\n```\nSignature is how a function is named: schema.name(input types).\n\n```go\nfunc UserTypes(s *schema.Schema) map[string]UserType\n```\nUserTypes lists a schema's declared types by name (public omitted).\n\n## Types\n\n```go\ntype Change struct {\n\tOp   Op\n\tKind string // schema, extension, enum, domain, composite, range, table, view, matview, sequence, column, constraint, index, rule, policy, rows, function, trigger, comment\n\tName string // qualified as the loader prints it: public omitted; column / constraint / index / rule as \u003crelation\u003e.\u003cname\u003e; trigger as \u003crelation\u003e.\u003cname\u003e\n\t// Fields are the properties that differ, for Alter.\n\tFields []Field\n}\n```\nChange is one object added, dropped or altered.\n\n```go\nfunc Compare(a, b *schema.Schema) []Change\n```\nCompare lists the changes from a to b, sorted by kind order (dependencies first for additions: schemas, extensions, types, relations, their parts, functions, triggers, comments) then by name. Drops come in the same order; ordering for execution is the DDL generator's job.\n\n```go\nfunc (c Change) OrderOnly() bool\n```\nOrderOnly reports whether a change is nothing but a relation's columns in another order: the database cannot be brought to the declared order without rebuilding the table, so apply tolerates it and reports it as a note.\n\n```go\nfunc (c Change) String() string\n```\n\n```go\ntype Field struct {\n\tName     string\n\tFrom, To string\n}\n```\nField is one differing property.\n\n```go\nfunc RowChanges(from, to *schema.Relation) []Field\n```\nRowChanges compares the seeded content of a table: the rows the target declares against the rows the source holds, by key. Each field names the key and shows the row texts (From empty for a row to insert, To empty for one to delete). A column left out of the declaration does not count, rows an additive seed does not list are not a change, and a target without a seed declares nothing about the content.\n\n```go\ntype Op byte\n```\nOp is what happens to an object.\n\n```go\nconst (\n\tAdd   Op = '+'\n\tDrop  Op = '-'\n\tAlter Op = '~'\n)\n```\n\n```go\ntype UserType struct {\n\tOID   catalog.OID\n\tKind  string // enum, domain, composite, range\n\tProps map[string]string\n}\n```\nUserType is a declared type with its comparable properties.\n\n","path":"github.com/kr9ly/sqlshape/internal/diff","name":"diff","synopsis":"Package diff compares two schemas object by object and lists what it takes to turn one into the other.","isRedistributable":true}
