Skip to content

Instantly share code, notes, and snippets.

@z4y4ts
Forked from theskumar/app.py
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z4y4ts/5914a55ff4b0deb7e44d to your computer and use it in GitHub Desktop.
Save z4y4ts/5914a55ff4b0deb7e44d to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
''' Generates database schema graph from a relational database.
Usages:
Add database configuation in this file and then
python app.py
Note: You must have your latest database schema in the database
engine you are running against.
'''
from __future__ import unicode_literals, absolute_import
from sqlalchemy import MetaData
from sqlalchemy_schemadisplay import create_schema_graph
# Change here
db_name = 'your_db_name_here'
db_type = 'postgres' # postgres, mysql
DATABASE_CONFIG = {
'db_name': db_name,
'db_type': db_type,
'db_host': '127.0.0.1',
}
database_url_template = "%(db_type)s://%(db_host)s/%(db_name)s"
# database_url = 'mysql://root:password@127.0.0.1/your_db_name'
# database_url = 'postgres://127.0.0.1/onydo'
database_url = database_url_template % DATABASE_CONFIG
graph = create_schema_graph(metadata=MetaData(database_url),
show_datatypes=False,
show_indexes=False,
rankdir='TB',
concentrate=True,)
graph.write_png('%s_dbschema.png' % db_name)
graph.write_svg('%s_dbschema.svg' % db_name)
graph.write_pdf('%s_dbschema.pdf' % db_name)
https://pypi.python.org/packages/source/p/pyparsing/pyparsing-1.5.7.tar.gz\#md5\=9be0fcdcc595199c646ab317c1d9a709
pydot
sqlalchemy
sqlalchemy_schemadisplay
graphviz
# Database drivers (uncomment whichever you need)
# ---------------------------------
# mysql-python
# psycopg2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment