def db_create_tables(): app = create_app() with app.app_context(): db.drop_all() db.create_all() yield with app.app_context(): db.drop_all()
def initdb(): "Clear the existing database and create a fresh one (drop_all && create_all)" if prompt_bool("Are you sure you want to lose all your data"): db.drop_all() db.create_all() load_all_fixtures(db, app) db.session.commit()
def setUp(self): app = create_app(TestingConfig) self.test_db_file = tempfile.mkstemp()[1] app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + self.test_db_file app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False with app.app_context(): db.create_all() app.app_context().push() self.app = app.test_client()
def setUp(self): self.app = create_app() self.app_context = self.app.app_context() self.app_context.push() self.provider = plugins.get_plugin( StaticProviders.crossref_event_data).PROVIDER db.create_all() for uri_id, uri_raw in dois_all: db.session.add(Uri(id=uri_id, raw=uri_raw)) db.session.commit()
def app(monkey_session) -> Flask: """A testing instance of the Flask application.""" monkey_session.setenv('APP_ENV', 'testing') app = create_app() # Creates in memory tables.. with app.app_context(): db.create_all() yield app # Drops from memory tables. with app.app_context(): db.drop_all()
def create_app(): """Construct the core application.""" app = Flask(__name__, instance_relative_config=False) CORS(app) app.config["SQLALCHEMY_DATABASE_URI"] = DB_URL app.config[ "SQLALCHEMY_TRACK_MODIFICATIONS"] = False # silence the deprecation warning app.secret_key = getenv("FLASK_SECRET_KEY") db.init_app(app) from settings import board_bp app.register_blueprint(board_bp, url_prefix=URL_PREFIX) with app.app_context(): db.create_all() return app
def insertdata(): """Recreate and repopulate an existing testing database.""" with app.test_request_context(): flask.g.cache_keys = defaultdict(set) try: user = User.from_pk(1) except sqlalchemy.exc.ProgrammingError as e: click.secho( 'Please manually create the database before running the createdata command.', fg='red', bold=True, ) raise click.Abort if user and user.username != 'user_one': click.secho( 'The username of the first user is not user_one. Are you sure this ' 'is a testing database? Please clear it yourself and re-try.', fg='red', bold=True, ) raise click.Abort cache.clear() db.session.commit() with app.app_context(): db.drop_all() db.create_all() with app.test_request_context(): for p in POPULATORS: p.populate() CorePopulator.add_permissions(SitePermissions.GOD_MODE) cache.clear() click.echo(f'Updated and inserted development data into the database!')
def create_db(): db.create_all()
def setUp(self): db.create_all()
def testSetUp(self): if os.path.isfile(DATABASE_PATH): os.remove(DATABASE_PATH) db.create_all() bootstrapTestDB(db)
def create_tables(): """Create initial db tables.""" db.create_all() print('***** Datebase Tables Created ****')
def setUp(self): db.drop_all() with self.app.app_context(): db.create_all() self.init_db()
def recreate_db(): db.drop_all() db.create_all() db.session.commit() return 'Database Recreated'
def createdb(): """Create an empty database per the current schema.""" db.create_all()
from core import db from auth import models from admin import models db.create_all()
return 'ok' if __name__ == "__main__": port = 7000 # Read port from commandline if len(sys.argv) >= 2: port = sys.argv[1] # Setup app app.register_blueprint(bp) app.config.from_object('settings') db.init_app(app) db.create_all(app=app) security.init_app(app, user_datastore) if app.debug: CORS(app, resources=r'/*', allow_headers=['Content-Type', 'Authentication'], supports_credentials=True) # Register to discovery service discoveryServiceRequest = 'http://' + app.config[ 'DISCOVERY_SERVICE_URL'] + '/' + bp.name discoveryServiceData = { 'service_id': bp.name, 'host': 'localhost',
app = Flask(__name__) # Update configuration. app.config.from_object('settings') app.config.from_pyfile('settings.cfg', silent=True) app.config.from_object(settings_override) # Initialize extensions on the application. db.init_app(app) oauth.init_app(app) oauth._validator = MyRequestValidator() # Register views on the application. app.register_blueprint(yoloapi) return app if __name__ == '__main__': # Enable Flask-OAuthlib logging for this application. import logging logger = logging.getLogger('flask_oauthlib') logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.DEBUG) # Create app and SQL schemas in database, then run the application. app = create_app() db.create_all(app=app) app.run(ssl_context='adhoc')
from core.models import Admin, Orders, Products, ProductLevel, ProductView, Users from core import db from datetime import datetime db.create_all() print('All tables created') admin = Admin('Nur', 'Mohsin', '*****@*****.**', '01677876551', 'Dhaka', '$5$rounds=535000$w/MRBgS3SCDxMfkt$q.6o0T3/bF6wpch9ErkAuvOItlJeWq/hw5zgpEBOiY0', 'manager', '0'); db.session.add(admin) db.session.commit() print('Admin Created') time = str(datetime(2012, 3, 3, 10, 10, 10)) print(time) one = Orders(1, 'Kashmiri Chador', 1,'01609876543', '*****@*****.**','2018-09-22 03:03:36') two = Orders(2, 'Kashmiri Chador', 1,'01609876543', '*****@*****.**','2018-09-22 03:03:36') three = Orders(3, 'Kashmiri Chador', 1,'01609876543', '*****@*****.**','2018-09-22 03:03:36') four = Orders(4, 'Kashmiri Chador', 1,'01609876543', '*****@*****.**','2018-09-22 03:03:36') five = Orders(5, 'Kashmiri Chador', 1,'01609876543', '*****@*****.**','2018-09-22 03:03:36') six = Orders(6, 'Kashmiri Chador', 1,'01609876543', '*****@*****.**','2018-09-22 03:03:36') seven = Orders(7, 'Kashmiri Chador', 1,'01609876543', '*****@*****.**','2018-09-22 03:03:36') eight = Orders(8, 'Kashmiri Chador', 1,'01609876543', '*****@*****.**','2018-09-22 03:03:36') nine = Orders(9, 'Kashmiri Chador', 1,'01609876543', '*****@*****.**','2018-09-22 03:03:36') ten = Orders(10, 'Kashmiri Chador', 1,'01609876543', '*****@*****.**','2018-09-22 03:03:36') db.session.add_all([one, two, three, four, five, six, seven, eight, nine, ten]) db.session.commit() print('Orders created') # one = Products("Top Gear","FEB,2019",100,"Most wanted! 19 must have cars of 2019","United Kingdom","magazines","BBC","1st","BBC_Top_Gear_February2019_ UK.jpg","https://drive.google.com/open?id=1-viCrN_Hz--bTQZ5PEQOkCQTWB-HSTto")
def setUp(self): self.app = create_app() self.app_context = self.app.app_context() self.app_context.push() db.create_all()
def create_db(): """Creates the db tables.""" db.create_all()
def db_create(): db.create_all() print('Database created!')
def main(): app = create_app() with app.app_context(): db.drop_all() db.create_all() db.session.commit()