Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

It will be nice to have migration functionality. #7

Open
rohitkeshwani07 opened this issue Nov 14, 2016 · 4 comments
Open

It will be nice to have migration functionality. #7

rohitkeshwani07 opened this issue Nov 14, 2016 · 4 comments

Comments

@rohitkeshwani07
Copy link

How do you recommend setting migration with this structure?

@Robpol86
Copy link
Owner

I would probably put it in manage.py but I haven't had to implement migration in a Flask app using this template so I'm not too sure.

@rohitkeshwani07
Copy link
Author

rohitkeshwani07 commented Nov 15, 2016

But you need to register the 'db' command like in this example

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'

db = SQLAlchemy(app)
migrate = Migrate(app, db)

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

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128))

if __name__ == '__main__':
    manager.run()

And If you do this in manage.py file inside a command function. It will not work. As the command you will fire will be.
Python manage.py 'command/function name' db init

@rohitkeshwani07
Copy link
Author

rohitkeshwani07 commented Nov 15, 2016

How I managed to do. I made a new file called migration.py with the below code. I don't know how to do this in manage.py.

import sys
import os

from personalization_engine.application import create_app, get_config
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from personalization_engine.extensions import db

def parse_options():
    """Parses command line options for Flask.

    Returns:
    Config instance to pass into create_app().
    """
    # Figure out which class will be imported.
    if os.environ.get('CONFIG') == "production":
        config_class_string = 'personalization_engine.config.Production'
    else:
        config_class_string = 'personalization_engine.config.Config'
    config_obj = get_config(config_class_string)

    return config_obj

if __name__ == '__main__':
    app = create_app(parse_options())
    migrate = Migrate(app, db)
    manager = Manager(app)
    manager.add_command('db', MigrateCommand)
    manager.run()

@jstacoder
Copy link

manager.add_command('db',migrateCommand)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants