Skip to content

Commit

Permalink
package functions
Browse files Browse the repository at this point in the history
  • Loading branch information
covrom committed Aug 31, 2021
1 parent b1d194a commit c1d3d29
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions goerd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package goerd

import (
"database/sql"
"io"

"github.com/covrom/goerd/drivers/postgres"
"github.com/covrom/goerd/schema"
)

func SchemaFromPostgresDB(db *sql.DB) (*schema.Schema, error) {
s := &schema.Schema{}
driver := postgres.New(db)
err := driver.Analyze(s)
return s, err
}

func GenerateMigrationSQL(sfrom, sto *schema.Schema) []string {
ptch := &schema.PatchSchema{CurrentSchema: sfrom.CurrentSchema}
ptch.Build(sfrom, sto)
return ptch.GenerateSQL()
}

func SchemaToYAML(s *schema.Schema, w io.Writer) error {
return s.SaveYaml(w)
}

func SchemaFromYAML(r io.Reader) (*schema.Schema, error) {
s := &schema.Schema{}
if err := s.LoadYaml(r); err != nil {
return nil, err
}
return s, nil
}

0 comments on commit c1d3d29

Please sign in to comment.