https://github.com/artarts36/db-exporter
Console application for export db schema and data to formats
https://github.com/artarts36/db-exporter
code-generation code-generator csv db dbml docs documentation markdown mysql postgresql
Last synced: 2 months ago
JSON representation
Console application for export db schema and data to formats
- Host: GitHub
- URL: https://github.com/artarts36/db-exporter
- Owner: ArtARTs36
- License: mit
- Created: 2024-03-06T21:09:38.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-10-26T10:52:00.000Z (8 months ago)
- Last Synced: 2025-10-26T12:28:04.331Z (8 months ago)
- Topics: code-generation, code-generator, csv, db, dbml, docs, documentation, markdown, mysql, postgresql
- Language: Go
- Homepage:
- Size: 1.02 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# db-exporter


**db-exporter** - application for export db schema and data to formats
[🚀 Use with GitHub Actions](./docs/usage_examples.md#use-with-github-actions)
[🚀 Use with Gitlab CI](./docs/usage_examples.md#use-with-gitlab-ci)
**Exporters**
| Exporter | Description | Usage example |
|--------------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
| `grpc-crud` | Exports CRUD in .proto from database schema | |
| `ddl` | Exports DDL from database schema | |
| `csv` | Exports data from tables | |
| `md` | Exports database schema to Markdown | [Schema ➡️ Markdown](./docs/usage_examples.md#export-schema-from-postgresql-to-markdown) |
| `diagram` | Exports database schema as image of Class Diagram | |
| `go-entities` | Go structures with db tags | [Schema ➡️ Go entities, repositories](./docs/usage_examples.md#export-schema-to-go-entities-and-repositories) |
| `go-entity-repository` | Go structures with db tags and repositories | |
| `goose` | Goose migrations | |
| `goose-fixtures` | Exports data from tables as inserts to Goose migrations | |
| `go-sql-migrate` | Migrations for [sql-migrate](https://github.com/rubenv/sql-migrate) | |
| `laravel-migrations-raw` | Raw SQL Laravel migrations | |
| `laravel-models` | Exports database schema as Laravel models | |
| `json-schema` | Exports database schema to [JSON Schema](https://json-schema.org) | |
| `graphql` | Exports database schema to [GraphQL](https://graphql.org/learn/schema) types | |
| `dbml` | Exports database schema to DBML (table, ref, enum) | |
| `custom` | Exports DB schema by your template with [Twig](https://twig.symfony.com) syntax | [Generating .txt files from a template built into the configuration](./docs/usage_custom.md) |
| `mermaid` | Exports DB schema to Mermaid ER Diagram | |
Supported database schemas:
-  PostgreSQL
-  DBML: only export db schema, without fixtures and import
-  MySQL
usage:
```text
Usage
db-exporter[--config] [--tasks]
Options
config Path to config file (yaml), default: ./.db-exporter.yaml
tasks task names of config file
Usage examples
db-exporter --config db.yaml Run db-exporter with custom config path
```

## Configuration
The exporter operates on tasks that have activities.

For example, to describe the export of a database schema to a GraphQL, the following configuration is required.
```yaml
databases:
default:
driver: postgres
dsn: ${PG_DSN}
tasks:
gen_graphql:
activities:
- format: graphql
out:
dir: ./out/graphql
```
Config file declared in [JSON Schema](db-exporter-json-schema.json)
### Environment variables
You can inject environment variables to config:
- **DSN** to database in `databases`:
```yaml
databases:
default:
driver: postgres
dsn: $PG_DSN
```
- **Commit Author** in `tasks`:
```yaml
tasks:
gen_docs:
commit:
author: ${COMMIT_AUTHOR}
activities:
...
```
- **Tables List** in `activities`
```yaml
tasks:
gen_csv:
activities:
- format: csv
tables:
list: ${MY_TABLES}
```
## Articles
На русском:
- [Генерируем CRUD для gRPC по схеме БД следуя Google AIP](https://tproger.ru/articles/generiruem-crud-dlya-grpc-po-sheme-bd)
- [Генерируем документацию к БД и не мучаем разработчиков](https://dzen.ru/a/aOlhYHhHszJpeGgW)