3

In my flask project I wrote on my manage.py file:

from app import app, db
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand
migrate = Migrate(app, db)

manager = Manager(app)
manager.add_command('db', MigrateCommand)


def make_shell_context():
    return dict(app=app, db=db)

manager.add_command("shell", Shell(make_context=make_shell_context))

if __name__ == '__main__':

    manager.run()

I've two models, user and dashboard. The idea is, in my postgres database user table would be in the default public schema and after creating a new user I need to create a private schema where the dashboard table will be created.

For the default public schema we usually run python manage.py db migrate. It'll then create the tables in default public schema. But what should I do in my case? First I've to run migrate command to generate the User table in public schema. Then after adding a successful row in user table I need to run a script for creating a private schema where a new table dashboard will be generated. How can I achieve this?

Emu
  • 5,763
  • 3
  • 31
  • 51
  • I'd have to think about how this can be done, not sure SQLAlchemy or the Flask extension provide enough support for this. If you have figured out how to make Flask-SQLAlchemy's binds attach to all your schemas, then Alembic and Flask-Migrate should be able to handle migrations with the multidb support, but my impression is that getting binds set up for all your schemas is going to be tricky. – Miguel Grinberg Nov 10 '16 at 06:40
  • @Miguel, I can create a different schema while a new row inserts in my `User` table using `create_schema` from sqlAlchemy. But I'm bit confused how to run the migrations for that newly created schema. Have any clue? – Emu Nov 14 '16 at 11:22

0 Answers0