MCPcopy Index your code
hub / github.com/covrom/goerd

github.com/covrom/goerd @v1.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.1 ↗ · + Follow
179 symbols 430 edges 24 files 34 documented · 19% updated 2y agov1.1.1 · 2023-10-18★ 32
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

goerd

This is a New Era of migrations PostgreSQL databases with Golang.

We no longer want to ensure the database schema with incremental patches. Shema MUST match what the app wants. It doesn't matter what was in the database before that.

It could be empty, it could contain some data in any of its previous versions. It doesn't matter anymore. It is important that we carefully transform it into the target state. We will no longer be guessing about the target state of the database by patchset. This is a thing of the past.

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

API

Use as library: Productive usage example

Install schema tool

go install github.com/covrom/goerd/cmd/goerd@latest

Features

  • Generate yaml short schema description from database
  • Generate plantuml view of schema
  • 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.

Migration of the following objects is currently supported: - Tables - Columns - Indexes - Constraints and Foreign Keys - Views

This set covers 99% of PostgreSQL usecases in Golang services.

Example of generated plantuml:

Plantuml view

Tool usage

Save database schema to yaml schema or PlantUML:

goerd -from "postgres://username:password@url:port/dbName" -to ./schema1.yaml

goerd -from "postgres://username:password@url:port/dbName" -to ./schema1.puml

Print SQL queries migration between two schemas, dropping queries is commented out:

goerd -from schema1.yml -to schema2.yaml

goerd -from schema1.yml -to "postgres://username:password@url:port/dbName"

With dropping queries:

goerd -drop -from schema1.yml -to schema2.yml

goerd -drop -from schema1.yml -to "postgres://username:password@url:port/dbName"

Save PlantUML from schema:

goerd -from schema1.yml -to schema1.puml

goerd -from "postgres://username:password@url:port/dbName" -to schema1.puml

Apply schema from yaml to database:

goerd -c apply -from schema1.yml -to "postgres://username:password@url:port/dbName"

Apply schema from DB1 to DB2:

goerd -c apply -from "postgres://username:password@url:port/DB1" -to "postgres://username:password@url:port/DB2"

Docs

Docs.

Testing and Examples

docker-compose up and see ./output/schema.yaml

Productive usage example

Extension points exported contracts — how you extend this code

Driver (Interface)
Driver is the common interface for database drivers [1 implementers]
drivers/drivers.go
Columner (Interface)
(no doc) [2 implementers]
replace.go

Core symbols most depended-on inside this repo

FindColumnByName
called by 11
schema/schema.go
SqlxTxFromContext
called by 8
transaction.go
Scan
called by 8
drivers/postgres/nstr.go
FindTableByName
called by 8
schema/schema.go
GenerateSQL
called by 7
schema/diff.go
Build
called by 7
schema/diff.go
New
called by 5
objmodel.go
SchemaFromPostgresWithConnect
called by 5
goerd.go

Shape

Method 89
Function 53
Struct 32
Interface 4
TypeAlias 1

Languages

Go100%

Modules by API surface

schema/diff.go31 symbols
objmodel.go29 symbols
schema/schema.go23 symbols
transaction.go11 symbols
schema/yaml.go10 symbols
product_test.go10 symbols
category_test.go10 symbols
schema/plantuml.go8 symbols
drivers/postgres/nstr.go8 symbols
replace.go7 symbols
schema/diff_test.go6 symbols
goerd.go6 symbols

Datastores touched

dbNameDatabase · 1 repos
DB1Database · 1 repos
DB2Database · 1 repos
dbtest1Database · 1 repos
goerdDatabase · 1 repos

For agents

$ claude mcp add goerd \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact