예제 #1
0
 def run(self, debug_flag, dbname):
     app = flask.current_app
     for db in dbname:
         conn_str = app.config['DATABASE_%s_URL' % db.upper()]
         meta_path = app.config['%s_META_PATH' % db.upper()]
         meta_path = os.path.abspath(meta_path)
         app.db_engine = space.cs_create_engine(app, conn_str)
         inspector = space.DBInspector(app.db_engine)
         # call inspector
         for tbl_name in inspector.tables():
             meta = inspector.table_define(tbl_name)
             meta_file = os.path.join(meta_path, "%s.json" % tbl_name)
             with open(meta_file, 'wb') as fh:
                 json.dump(meta.to_jsonable(), fh,  sort_keys=True,
                           indent=4, separators=(',', ': '))
         app.db_engine = None
     pass
예제 #2
0
 def run(self, debug_flag, dbname):
     app = flask.current_app
     for db in dbname:
         conn_str = app.config['DATABASE_%s_URL' % db.upper()]
         meta_path = app.config['%s_META_PATH' % db.upper()]
         meta_path = os.path.abspath(meta_path)
         app.db_engine = space.cs_create_engine(app, conn_str)
         inspector = space.DBInspector(app.db_engine)
         # call inspector
         for tbl_name in inspector.tables():
             meta = inspector.table_define(tbl_name)
             meta_file = os.path.join(meta_path, "%s.json" % tbl_name)
             with open(meta_file, 'wb') as fh:
                 json.dump(meta.to_jsonable(),
                           fh,
                           sort_keys=True,
                           indent=4,
                           separators=(',', ': '))
         app.db_engine = None
     pass
예제 #3
0
    def run(self, debug_flag, db_schema, db_names):
        app = flask.current_app
        for db in db_names:
            conn_str = app.config['DATABASE_%s_DEV_URL' % db.upper()]
            schema_cls_name = app.config['DATABASE_%s_SCHEMA_DEFINE' % db.upper()]
            #print schema_cls_name
            meta_path = app.config['%s_META_PATH' % db.upper()]
            meta_path = os.path.abspath(meta_path)
            app.db_engine = space.cs_create_engine(app, conn_str, True)
            # set schema.
            obj = space.load_class(schema_cls_name)
            if obj is None:
                print 'can not found %s.' % schema_cls_name
                return

            db_syncer = space.DBSync(app.db_engine)

            obj = obj()         # create the schema object.
            for tbl in obj._tables:
                db_syncer.sync_table(tbl, obj._tables[tbl])
예제 #4
0
    def run(self, debug_flag, db_schema, db_names):
        app = flask.current_app
        for db in db_names:
            conn_str = app.config['DATABASE_%s_DEV_URL' % db.upper()]
            schema_cls_name = app.config['DATABASE_%s_SCHEMA_DEFINE' %
                                         db.upper()]
            #print schema_cls_name
            meta_path = app.config['%s_META_PATH' % db.upper()]
            meta_path = os.path.abspath(meta_path)
            app.db_engine = space.cs_create_engine(app, conn_str, True)
            # set schema.
            obj = space.load_class(schema_cls_name)
            if obj is None:
                print 'can not found %s.' % schema_cls_name
                return

            db_syncer = space.DBSync(app.db_engine)

            obj = obj()  # create the schema object.
            for tbl in obj._tables:
                db_syncer.sync_table(tbl, obj._tables[tbl])
예제 #5
0
    def run(self, debug_flag, db_names):
        app = flask.current_app
        for db in db_names:
            conn_str = app.config['DATABASE_%s_URL' % db.upper()]

            meta_path = app.config['%s_META_PATH' % db.upper()]
            meta_path = os.path.abspath(meta_path)

            app_path = app.config['%s_APP_PATH' % db.upper()]
            app_path = os.path.abspath(app_path)
            sqlalchemy_file = os.path.join(app_path, 'schema', 'sql_schema.py')
            app.db_engine = space.cs_create_engine(app, conn_str)
            gen = space.DBSchemaCodeGen(app.db_engine)
            if conn_str.find('mysql') == 0:
                code = gen.generate(meta_path, 'mysql', 'sqlalchemy')
                with open(sqlalchemy_file, 'wb') as fh:
                    fh.write(code)
                code = gen.generate(meta_path, 'mysql', 'pony')
            else:
                code = gen.generate(meta_path, 'postgresql', 'sqlalchemy')
            # write to file
            #print code
            pass
예제 #6
0
    def run(self, debug_flag, db_names):
        app = flask.current_app
        for db in db_names:
            conn_str = app.config['DATABASE_%s_URL' % db.upper()]

            meta_path = app.config['%s_META_PATH' % db.upper()]
            meta_path = os.path.abspath(meta_path)

            app_path = app.config['%s_APP_PATH' % db.upper()]
            app_path = os.path.abspath(app_path)
            sqlalchemy_file = os.path.join(app_path, 'schema', 'sql_schema.py')
            app.db_engine = space.cs_create_engine(app, conn_str)
            gen = space.DBSchemaCodeGen(app.db_engine)
            if conn_str.find('mysql') == 0:
                code = gen.generate(meta_path, 'mysql', 'sqlalchemy')
                with open(sqlalchemy_file, 'wb') as fh:
                    fh.write(code)
                code = gen.generate(meta_path, 'mysql', 'pony')
            else:
                code = gen.generate(meta_path, 'postgresql', 'sqlalchemy')
            # write to file
            #print code
            pass