项目作者: chop-dbhi

项目描述 :
Utility to export schema information from a relational database to JSON.
高级语言: Python
项目地址: git://github.com/chop-dbhi/sql-schema-exporter.git
创建时间: 2017-08-15T18:00:02Z
项目社区:https://github.com/chop-dbhi/sql-schema-exporter

开源协议:

下载


SQL Schema Exporter

This program exports table schema information from a relational database.

Install

  1. pip install -r requirements.txt

Usage

The only argument is the URI of the database. The schema (as an array of tables) is emitted to stdout as JSON.

  1. python main.py 'postgresql://postgres:secret@127.0.0.1:5432/data' > schema.json

Supported databases:

  • PostgreSQL
  • Oracle (requires instantclient libraries to be installed)
  • MySQL
  • SQLite

Docker

A pre-baked Docker image is available which includes the Oracle driver.

  1. docker run --rm dbhi/sql-schema-exporter 'postgresql://postgres:secret@127.0.0.1:5432/data' > schema.json

To build the Docker image locally, the instantclient-* libraries must be in this directly. See the Dockerfile for the file names.

Data Model

  1. [
  2. {
  3. "schema": "<SCHEMA-NAME>",
  4. "table": "<TABLE-NAME>",
  5. "columns": [
  6. {
  7. "name": "<COLUMN-NAME>",
  8. "nullable": <BOOLEAN>,
  9. "type": "<DATA-TYPE>"
  10. },
  11. // ...
  12. ],
  13. "primary_key": [
  14. "<COLUMN-NAME>",
  15. // ...
  16. ],
  17. "foreign_keys": [
  18. {
  19. "constrained_columns": [
  20. "<COLUMN-NAME>",
  21. // ...
  22. ],
  23. "referred_schema": "<SCHEMA-NAME>",
  24. "referred_table": "<TABLE-NAME>",
  25. "referred_columns": [
  26. "<COLUMN-NAME>",
  27. // ...
  28. ]
  29. },
  30. //...
  31. ],
  32. "unique_constraints": [
  33. {
  34. "name": "<CONSTRAINT-NAME>",
  35. "columns": [
  36. "<COLUMN-NAME>",
  37. // ...
  38. ],
  39. },
  40. // ...
  41. ],
  42. },
  43. // ...
  44. ]