Merge remote-tracking branch 'remotes/lotusecho/trac_711_test_speed'

This commit is contained in:
Christopher Allan Webber 2013-07-03 14:07:11 -05:00
commit 41a14c6efc
7 changed files with 38 additions and 15 deletions

View File

@ -87,7 +87,7 @@ class MediaGoblinApp(object):
setup_plugins()
# Set up the database
self.db = setup_database()
self.db = setup_database(app_config['run_migrations'])
# Register themes
self.theme_registry, self.current_theme = register_themes(app_config)

View File

@ -11,6 +11,10 @@ media_types = string_list(default=list("mediagoblin.media_types.image"))
# database stuff
sql_engine = string(default="sqlite:///%(here)s/mediagoblin.db")
# This flag is used during testing to allow use of in-memory SQLite
# databases. It is not recommended to be used on a running instance.
run_migrations = boolean(default=False)
# Where temporary files used in processing and etc are kept
workbench_path = string(default="%(here)s/user_dev/media/workbench")

View File

@ -110,14 +110,26 @@ def run_dbupdate(app_config, global_config):
in the future, plugins)
"""
# Set up the database
db = setup_connection_and_db_from_config(app_config, migrations=True)
#Run the migrations
run_all_migrations(db, app_config, global_config)
def run_all_migrations(db, app_config, global_config):
"""
Initializes or migrates a database that already has a
connection setup and also initializes or migrates all
extensions based on the config files.
It can be used to initialize an in-memory database for
testing.
"""
# Gather information from all media managers / projects
dbdatas = gather_database_data(
app_config['media_types'],
global_config.get('plugins', {}).keys())
# Set up the database
db = setup_connection_and_db_from_config(app_config, migrations=True)
Session = sessionmaker(bind=db.engine)
# Setup media managers for all dbdata, run init/migrate and print info

View File

@ -58,15 +58,19 @@ def setup_global_and_app_config(config_path):
return global_config, app_config
def setup_database():
def setup_database(run_migrations=False):
app_config = mg_globals.app_config
global_config = mg_globals.global_config
# Load all models for media types (plugins, ...)
load_models(app_config)
# Set up the database
db = setup_connection_and_db_from_config(app_config)
db = setup_connection_and_db_from_config(app_config, run_migrations)
if run_migrations:
#Run the migrations to initialize/update the database.
from mediagoblin.gmg_commands.dbupdate import run_all_migrations
run_all_migrations(db, app_config, global_config)
else:
check_db_migrations_current(db)
setup_globals(database=db)

View File

@ -3,8 +3,9 @@ direct_remote_path = /test_static/
email_sender_address = "notice@mediagoblin.example.org"
email_debug_mode = true
# TODO: Switch to using an in-memory database
sql_engine = "sqlite:///%(here)s/user_dev/mediagoblin.db"
#Runs with an in-memory sqlite db for speed.
sql_engine = "sqlite://"
run_migrations = true
# Celery shouldn't be set up by the application as it's setup via
# mediagoblin.init.celery.from_celery

View File

@ -3,8 +3,9 @@ direct_remote_path = /test_static/
email_sender_address = "notice@mediagoblin.example.org"
email_debug_mode = true
# TODO: Switch to using an in-memory database
sql_engine = "sqlite:///%(here)s/user_dev/mediagoblin.db"
#Runs with an in-memory sqlite db for speed.
sql_engine = "sqlite://"
run_migrations = true
# Celery shouldn't be set up by the application as it's setup via
# mediagoblin.init.celery.from_celery

View File

@ -3,8 +3,9 @@ direct_remote_path = /test_static/
email_sender_address = "notice@mediagoblin.example.org"
email_debug_mode = true
# TODO: Switch to using an in-memory database
sql_engine = "sqlite:///%(here)s/user_dev/mediagoblin.db"
#Runs with an in-memory sqlite db for speed.
sql_engine = "sqlite://"
run_migrations = true
# tag parsing
tags_max_length = 50