Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
covrom committed Aug 31, 2021
1 parent 96cb891 commit 9550192
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`
5 changes: 5 additions & 0 deletions goerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@ 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)
err := driver.Analyze(s)
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 {
Expand Down

0 comments on commit 9550192

Please sign in to comment.