MyTetra Share
Делитесь знаниями!
generate schema from db using SQLAlchemy / генерация схемы БД
Время создания: 11.10.2017 20:14
Текстовые метки: mine
Раздел: SQLAlchemy - generate schema
Запись: xintrea/mytetra_db_mcold/master/base/1507742065c1dadprarn/text.html на raw.githubusercontent.com

1)

Install all Dependencies


sudo pip install configparser

sudo pip install sqlalchemy

sudo pip install pydot

sudo pip install sqlalchemy_schemadisplay

sudo pip install graphviz


#sudo apt-get install GraphViz


Linux:

sudo apt-get install GraphViz


Windows:

использовать Python2.7 x32 bit

http://www.graphviz.org/Download_windows.php



2)


#!/usr/bin/env python
import ConfigParser
from sqlalchemy import MetaData
from sqlalchemy_schemadisplay import create_schema_graph

config = ConfigParser.RawConfigParser()
##Open nova.conf file
# config.read('/etc/nova/nova.conf')
##Read the flag "sql_connection" from nova.conf and make connection to database
# connection = config.get("DEFAULT", "sql_connection")


##Or you can directly specify the connection like
connection = "sqlite:///test.db"

##Generate graph of connected database
graph = create_schema_graph(metadata=MetaData(connection),
show_datatypes=False,
show_indexes=False,
rankdir='LR',
concentrate=False)

##Generate png image
graph.write_png('dbschema.png')

 
MyTetra Share v.0.59
Яндекс индекс цитирования