Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call flask migrate api in script

I have a database db. I want to judge if flask_migrate has created tables in db. If not, upgrade db. There are commands, but no examples about calling migrate, upgrade in python script. The test files in flask_migrate also run commands:

(o, e, s) = run_cmd('python app.py db migrate')
like image 958
Jojo Avatar asked Apr 07 '26 15:04

Jojo


1 Answers

This should do the trick for you.

from flask_migrate import upgrade


@ns.route('/migrate_db')
class Units(Resource):
    def get(self):
        upgrade(directory=<path_to_migrations_folder>)
like image 53
Simon Avatar answered Apr 09 '26 04:04

Simon