示例#1
0
from flask import Flask
from flask_migrate import Migrate, Manager, MigrateCommand

from app.model.base import db

app = Flask(__name__)
app.config.from_pyfile('secure.py')
app.config.from_pyfile('settings.py')

migrate = Migrate(app, db)

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

if __name__ == '__main__':
    manager.run()
示例#2
0
from app import create_app, db, base, twitter, document_model, user_model, features
from personality_recogniser import Recogniser
from sqlalchemy import create_engine
from itertools import zip_longest
from flask_migrate import Manager
from bot import Tweety
import pandas as pd
import time

app = create_app()
manager = Manager(app)
engine = create_engine(app.config["SQLALCHEMY_DATABASE_URI"])


@manager.option("-s",
                "--schema",
                dest="s",
                help="Schema to featurise documents of.",
                default="personality")
@manager.option("-b",
                "--batch_size",
                dest="b",
                help="Batch size to commit to database.",
                default=100)
@manager.option("-f",
                "--force_all",
                dest="f",
                help="Featurise entries that have a feature already.",
                default=0)
def featurise_documents(s, b, f):
示例#3
0
#!/usr/bin/env python

from flask_migrate import Manager, MigrateCommand
from website import app

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

if __name__ == '__main__':
    manager.run()
示例#4
0
#Importujeme
import root
from root import models
from flask_migrate import Migrate, Manager, MigrateCommand
app = root.app
#Nastavíme novou relativní cestu k databázi, jelikož script nespouštíme ze složky root
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///databaze.sqlite3"
#Provedeme inicializaci
migrate = Migrate(app, root.db)
manager = Manager(app)
#Přidáme přikaz pro manager
manager.add_command("db", MigrateCommand)
#Přikaz spustíme, pokud byl script spuštěn
if __name__ == "__main__":
    manager.run()
示例#5
0
                'message': 'FORBIDDEN | Internal Only'
            }, 403
        else:
            return fn(*args, **kwargs)

    return wrapper


####Database####

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://a:b@c:3306/LKNU'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command(
    'db', MigrateCommand
)  # command 'db' dapat menjalankan semua command MigrateCommand


###########Middleware#############
@app.after_request
def after_request(response):
    try:
        requestData = request.get_json()
    except Exception as e:
        requestData = request.args.to_dict()
    app.logger.warning(
        "REQUEST_LOG\t%s",
        json.dumps({
示例#6
0
from flask_script import Shell, Server
from flask_migrate import Manager, MigrateCommand
from services.config import db, migrate
from services.app import app
from services.resources import Calculation

manager = Manager(app)

manager.add_command('db', MigrateCommand)
manager.add_command('runserver', Server(host='0.0.0.0', port=5000))

if __name__ == '__main__':
    # manager.run()
    app.run(debug=True)
示例#7
0
import pymysql
from flask_migrate import Manager, MigrateCommand, Migrate

from app import create_app

pymysql.install_as_MySQLdb()
app = create_app(config='dev')
manage = Manager(app=app)
manage.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manage.run()
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
from flask_migrate import Migrate, Manager, MigrateCommand
from flask_script import Shell

from app import create_app, db
from app.models import User, Role

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
migrate = Migrate(app, db)
manager = Manager(app)


def make_shell_context():
    return dict(db=db, User=User, Role=Role)


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


@manager.command
def test():
    """Run the unit tests."""
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)


if __name__ == '__main__':
示例#9
0
# !/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
python3 program to store and manipulate personal contact information for current contacts as
class-objects in Postgresql using SQLAlchemy and Flask.

make database migration command from extension flask_migrate available
"""

from cntct import create_app
from flask_migrate import MigrateCommand, Manager

manager = Manager(create_app)
manager.add_command('db', MigrateCommand)
示例#10
0
from . import create_app
from flask_script import Command
from flask_migrate import MigrateCommand, Manager


class Init_Admin(Command):
    def run(self):
        from .models.Admin import Administrator
        Administrator.init()


manager = Manager(create_app)
manager.add_command('init_admin', Init_Admin)

if __name__ == '__main__':
    manager.run()
示例#11
0
If you want to see a list of commands that you can use with Flask-Migrate:
python -m service.db_migrate db --help

A useful URL:
https://www.youtube.com/watch?v=BAOfjPuVby0&t=384s

A useful URL for migration with non-nullable columns
https://medium.com/the-andela-way/alembic-how-to-add-a-non-nullable-field-to-a-populated-table-998554003134

Useful bug:
https://stackoverflow.com/questions/32311366/alembic-util-command-error-cant-find-identifier

Detect minor changes:
https://stackoverflow.com/questions/58532518/why-flask-migrations-does-not-detect-a-fields-length-change
"""

from app import create_app

from flask_migrate import Manager, MigrateCommand

# Set up the database migration
manager = Manager(create_app)

manager.add_command('db', MigrateCommand)
manager.add_option("-env", "--environment", default='d', required=False)

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

示例#12
0
import os
from app import create_app
from flask_migrate import MigrateCommand, Manager

from dotenv import load_dotenv
load_dotenv()

manager = Manager(create_app("production"))
manager.add_command('db', MigrateCommand)

print(os.environ.get("FLASK_CONFIG"))
if __name__ == '__main__':
    manager.run()
示例#13
0
def init_app(app):
    migrate.init_app(app, db)
    manager = Manager(app)
    manager.add_command("db", MigrateCommand)
示例#14
0
# 导入扩展Flask_cript
from flask_migrate import Manager
from flask_migrate import Migrate
#  ManagerCommand
# 导入flask_sqlalchemy扩展
from flask_sqlalchemy import SQLAlchemy
# 导入配置对象
from .config1 import Config
# 导入配置对象

app = Flask(__name__)
# 使用配置对象
app.config.from_object(Config)
# 数据库实例
db = SQLAlchemy(app)
# 实例化管理对象
manage = Manager(app)
# 使用迁移框架
Migrate(app)
# 通过管理器对象,添加迁移命令
# 不可以使用
# manage.add_command('db', MigrateCommand)


@app.route('/')
def index():
    return "this is index"


if __name__ == '__main__':
    app.run(debug=True, port=8080)