Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config options, formatting updates, update packages #17

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f977ddf
Add feature to filter to specific schema
Hankanman Sep 11, 2024
77a791d
Support running with npx
Hankanman Sep 11, 2024
b1ebbca
Repoint to new repo source
Hankanman Sep 11, 2024
da06315
Add ability to filter to include/exclude tables and types
Hankanman Sep 11, 2024
abac175
Added ability to export in pureMarkdown for LLM context minimising to…
Hankanman Sep 11, 2024
7038864
Promote to v2.0.1
Hankanman Sep 11, 2024
cef65dc
Bump to v2.0.1 add features: print table of contents, print RLS Policies
Hankanman Sep 12, 2024
9d21ebb
Update to version 2.0.3; enhance configuration options, add support f…
Hankanman Dec 30, 2024
6a5cc5d
Update to version 2.0.3; add dotenv support for environment variables…
Hankanman Jan 3, 2025
6f12434
Upgrade to version 3.0.0; introduce .env.template for database connec…
Hankanman Jan 3, 2025
d2fb9a0
Update repolint workflow to use new repository source for custom rules
Hankanman Jan 3, 2025
8e93723
Update Changelog
Hankanman Jan 3, 2025
79d6195
Enhance CI workflow by adding Docker Buildx and Docker Compose setup …
Hankanman Jan 3, 2025
c6499c8
Update Node.js version in CI workflow from 12 to 16 for improved comp…
Hankanman Jan 3, 2025
9996f6c
Refactor README.md for clarity and organization; update usage instruc…
Hankanman Jan 3, 2025
0baf1a0
Upgrade version to 3.0.1 in package.json and package-lock.json for @h…
Hankanman Jan 3, 2025
67e8e92
Refactor project to align with Klarna branding: update repository URL…
Hankanman Jan 3, 2025
d2d7c15
Update package name in README from @hankanman/postgres-to-docs to @kl…
Hankanman Jan 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DB_STRING=postgresql://[user]:[password]@[host]:[port]/[database]
8 changes: 7 additions & 1 deletion .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 16
- run: npm install
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Set up Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- run: npm test
- run: npm run build
- id: publish
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.DS_Store
node_modules
dist
dist
.env
.env.local
docs/schema.json
docs/schema.md
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - yyyy-mm-dd

### Added
- New output formats and options:
- LLM-optimized JSON format for AI consumption
- Separate `folder` and `fileName` configuration options
- Ability to generate both markdown and JSON outputs simultaneously
- Entity Relationship Diagrams using Mermaid.js
- Function documentation support:
- Full function signatures
- Function definitions
- Language and volatility information
- Row Level Security (RLS) policy documentation:
- Policy definitions
- USING expressions
- WITH CHECK expressions
- Role assignments
- Enhanced schema documentation:
- Table and column comments
- View definitions and comments
- Default values for columns
- Environment variable support:
- `.env` and `.env.local` file support
- Database connection string via `DB_STRING`
- Table of Contents generation
- Pure markdown mode (no HTML)

### Changed
- Replaced single `output` option with `folder` and `fileName` for more flexibility
- Improved configuration handling with better defaults
- Enhanced CLI argument support for all configuration options

## [0.1.1] - 2020-03-15

### Added

- Initial release

<!-- Markdown link dfn's -->
Expand Down
159 changes: 121 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,139 @@
# postgres-to-docs
# Postgres to Docs
[![Build Status][ci-image]][ci-url]
[![License][license-image]][license-url]
[![Developed at Klarna][klarna-image]][klarna-url]

Make your database documentation smoooth by generating markdown for your schema.
Make your database documentation smooth by generating markdown for your schema. You need to get a quick and easy overview of your database schema but don't want to...
* Open the source code and find the model definitions
* Start your database and service, install dependencies, have a proper configuration, and open an external tool like TablePlus or DBeaver
* Read through your migrations directory to find the latest version of your schema
* Look through external documentation that might be out of date

## Features
postgres-to-docs generates comprehensive documentation for your PostgreSQL database schema:

### Documentation Elements
- [x] Tables
- Primary Keys
- Foreign Keys
- Nullable fields
- Default values
- Column comments
- [x] Views
- Column definitions
- View comments
- [x] User-defined Types
- Composite types
- Enums
- [x] Functions
- Full signatures
- Arguments and return types
- Function definitions
- Language and volatility
- [x] Row Level Security (RLS) Policies
- Policy definitions
- USING expressions
- WITH CHECK expressions
- Applicable roles
- [x] Entity Relationship Diagrams
- Mermaid.js format
- Visual representation of relationships
- Table structure visualization

### Output Formats
- [x] Markdown
- Clean, readable documentation
- Table of Contents
- Hyperlinked references
- Optional pure markdown mode (no HTML)
- [x] LLM-optimized JSON
- Structured schema information
- Complete metadata
- Optimized for AI consumption
- Includes schema statistics

### Configuration Options
- **Output Control**
- `folder`: Output directory (default: "docs")
- `fileName`: Base name for output files (default: "schema")
- `pureMarkdown`: Generate clean markdown without HTML
- `llmFormat`: Generate additional LLM-friendly JSON format
- **Content Filtering**
- `includeTables`: List of tables to include
- `excludeTables`: List of tables to exclude
- `includeTypes`: Include user-defined types
- `includeRLS`: Include RLS policies
- `includeFunctions`: Include function definitions
- `includeDiagram`: Include ER diagram
- `includeToc`: Include table of contents
- **Database Connection**
- Support for connection string or individual parameters
- Environment variable support through `.env` files

## Usage

1. Install through npm
```
npm install @klarna/postgres-to-docs
```

2. Define a `json` config file
```
{
"host": "localhost",
"port": 5432,
"user": "user",
"password": "password",
"database": "database"
}
```
```bash
npm install @klarna/postgres-to-docs
```

2. Define a `postgrestodocs.json` config file
```json
{
"host": "localhost",
"port": 5432,
"user": "user",
"password": "password",
"database": "database",
"schema": "public",
"folder": "docs",
"fileName": "schema",
"includeTables": [],
"exludeTables": [],
"includeTypes": true,
"pureMarkdown": false,
"includeRLS": true,
"includeToc": true,
"includeFunctions": true,
"includeDiagram": true,
"llmFormat": false
}
```
3. Run the tool
```
postgres-to-docs --config=config.json --output=schema.md
```
Where `--config` is the path to your config file and `--output`is the path to the output markdown file

```bash
postgres-to-docs
```

## Problem
You need to get a quick and easy overview of your database schema but don't want to...
* Open the source code and find the model definitions
* Start your database and service, install dependencies, have a proper configuration, and open an external tool like TablePlus or DBeaver
* Read through your migrations directory to find the latest version of your schema
* Look through external documentation that might be out of date
### Environment Variables
You can use environment variables to avoid storing sensitive database credentials in your configuration file. The tool supports both `.env` and `.env.local` files, with `.env.local` taking precedence.

Create a `.env` or `.env.local` file or add the following to your existing `.env` file:
```env
# Database connection string
DB_STRING=postgresql://user:password@localhost:5432/database
```

## Introducing postgres-to-docs!
A Node CLI that renders your schemas as markdown and keeps it up to date! Generates documentation for
- [X] Tables - PKs, FKs, Nullable and Default values
- [X] Views
- [X] User defined types like composites and enums
The tool will:
1. Look for `.env.local` first (good for local development overrides)
2. Then look for `.env` (good for team-shared defaults)
3. Use DB_STRING to override the connection parameters if found
4. Fall back to the explicit values in the config file if DB_STRING is not found

## Future work
- [ ] Additional export formats like entity relationship-diagrams
- [ ] Materialized views
- [ ] Support for watch-mode to rerun the tool on file change
**Best Practice**: Add `.env.local` to your `.gitignore` file to keep sensitive credentials out of version control:
```gitignore
.env.local
```

### CLI Options
All configuration options can be overridden via CLI arguments:
```bash
postgres-to-docs --folder=my-docs --fileName=my-schema --llmFormat=true
```

## Development
Clone the repo, then:

```
```bash
npm install
npm run start:dev
```
Expand All @@ -71,11 +152,13 @@ Copyright © 2021 Klarna Bank AB

For license details, see the [LICENSE](LICENSE) file in the root of this project.

Contributors:
- [@hankanman](https://github.com/hankanman)

<!-- Markdown link & img dfn's -->
[ci-image]: https://img.shields.io/badge/build-passing-brightgreen?style=flat-square
[ci-url]: https://github.com/klarna-incubator/TODO
[license-image]: https://img.shields.io/badge/license-Apache%202-blue?style=flat-square
[license-url]: http://www.apache.org/licenses/LICENSE-2.0
[klarna-image]: https://img.shields.io/badge/%20-Developed%20at%20Klarna-black?labelColor=ffb3c7&style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAYAAAAmL5yKAAAAAXNSR0IArs4c6QAAAIRlWElmTU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAALQAAAAAQAAAtAAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAABCgAwAEAAAAAQAAAA4AAAAA0LMKiwAAAAlwSFlzAABuugAAbroB1t6xFwAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAAAVBJREFUKBVtkz0vREEUhsdXgo5qJXohkUgQ0fgFNFpR2V5ClP6CQu9PiB6lEL1I7B9A4/treZ47c252s97k2ffMmZkz5869m1JKL/AFbzAHaiRbmsIf4BdaMAZqMFsOXNxXkroKbxCPV5l8yHOJLVipn9/vEreLa7FguSN3S2ynA/ATeQuI8tTY6OOY34DQaQnq9mPCDtxoBwuRxPfAvPMWnARlB12KAi6eLTPruOOP4gcl33O6+Sjgc83DJkRH+h2MgorLzaPy68W48BG2S+xYnmAa1L+nOxEduMH3fgjGFvZeVkANZau68B6CrgJxWosFFpF7iG+h5wKZqwt42qIJtARu/ix+gqsosEq8D35o6R3c7OL4lAnTDljEe9B3Qa2BYzmHemDCt6Diwo6JY7E+A82OnN9HuoBruAQvUQ1nSxP4GVzBDRyBfygf6RW2/gD3NmEv+K/DZgAAAABJRU5ErkJggg==
[klarna-url]: https://github.com/klarna-incubator
[klarna-url]: https://github.com/klarna-incubator
Loading