From 9550192b33e2a0403d31855506fa0436843fd396 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 31 Aug 2021 18:43:08 +0300 Subject: [PATCH] docs --- README.md | 16 ++++++++-------- goerd.go | 5 +++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 29027b6..d43de7b 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,21 @@ -# goerd [WIP] +# goerd -This tool allows you to turn schemas into instructions for the database, including migrations between schemas. Create easy-to-read data models as contracts for agreement between architects, development teams, and team leaders. This tool provides agility to change the huge data model. +This tool allows you to turn schemas into instructions for the database, including migrations between schemas. Create easy-to-read data models as contracts for agreement between architects, development teams, and team leaders. This tool provides agility to change the huge data-layered models. ![Conceptual view](concept.png) -Features (in progress): +Features: -- Generating posgresql migrations as a set of SQL queries that apply changes between two schemas, a schema and a database, or two databases using a yaml schema definition +- Create posgresql migrations as a set of SQL queries that apply changes between two schemas, a schema and a database, or two databases using a schema definition that is stored in a yaml or plantuml file. - Using https://github.com/jackc/pgx -- Run as grpc-microservice -- Use as library -- [Check rules for schema](https://wiki.postgresql.org/wiki/Don't_Do_This) -- [Generate CRUDs like postgrest](https://github.com/PostgREST/postgrest) Example of generated plantuml: ![Plantuml view](plantuml-example.png) +### API + +See [docs](https://pkg.go.dev/github.com/covrom/goerd). + ### testing and examples ```docker-compose up``` and see `./output/schema.yaml` \ No newline at end of file diff --git a/goerd.go b/goerd.go index 696d95a..4eccab8 100644 --- a/goerd.go +++ b/goerd.go @@ -8,6 +8,7 @@ import ( "github.com/covrom/goerd/schema" ) +// SchemaFromPostgresDB reads database schema from postgres *sql.DB func SchemaFromPostgresDB(db *sql.DB) (*schema.Schema, error) { s := &schema.Schema{} driver := postgres.New(db) @@ -15,16 +16,20 @@ func SchemaFromPostgresDB(db *sql.DB) (*schema.Schema, error) { return s, err } +// GenerateMigrationSQL generates an array of SQL DDL queries +// for postgres that modify database tables, columns, indexes, etc. func GenerateMigrationSQL(sfrom, sto *schema.Schema) []string { ptch := &schema.PatchSchema{CurrentSchema: sfrom.CurrentSchema} ptch.Build(sfrom, sto) return ptch.GenerateSQL() } +// SchemaToYAML saves the schema to a yaml file func SchemaToYAML(s *schema.Schema, w io.Writer) error { return s.SaveYaml(w) } +// SchemaFromYAML loads the schema from the yaml file func SchemaFromYAML(r io.Reader) (*schema.Schema, error) { s := &schema.Schema{} if err := s.LoadYaml(r); err != nil {