From 70b44584ae4a81e53d39481781c63aec23b23884 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 29 Dec 2011 11:15:55 -0600 Subject: Big ol' start of the SQL migrations system. Things definitely don't work yet, but should be heading in the right direction. --- mediagoblin/gmg_commands/dbupdate.py | 84 ++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 mediagoblin/gmg_commands/dbupdate.py (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py new file mode 100644 index 00000000..52819c6d --- /dev/null +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -0,0 +1,84 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from mediagoblin.db.sql.open import setup_connection_and_db_from_config +from mediagoblin.db.sql.util import ( + MigrationManager, assure_migrations_table_setup) +from mediagoblin.init import setup_global_and_app_config +from mediagoblin.tools.common import import_component + + +class DatabaseData(object): + def __init__(self, name, models, migrations): + self.name = name + self.models = models + self.migrations = migrations + + def make_migration_manager(self, db): + return MigrationManager( + self.name, self.models, self.migrations, db) + + +def gather_database_data(self, media_types): + """ + Gather all database data relevant to the extensions we have + installed so we can do migrations and table initialization. + + Returns a list of DatabaseData objects. + """ + managed_dbdata = [] + + # Add main first + from mediagoblin.db.sql.models import MODELS as MAIN_MODELS + from mediagoblin.db.sql.migrations import MIGRATIONS as MAIN_MIGRATIONS + + managed_dbdata.append( + DatabaseData( + '__main__', MAIN_MODELS, MAIN_MIGRATIONS)) + + # Then get all registered media managers (eventually, plugins) + for media_type in media_types: + models = import_component('%s.models:MODELS' % media_type) + migrations = import_component('%s.migrations:MIGRATIONS' % media_type) + managed_dbdata.append( + DatabaseData(media_type, models, migrations)) + + return managed_dbdata + + +def dbupdate(args): + """ + Initialize or migrate the database as specified by the config file. + + Will also initialize or migrate all extensions (media types, and + in the future, plugins) + """ + globa_config, app_config = setup_global_and_app_config(args.conf_file) + + # Gather information from all media managers / projects + dbdatas = gather_database_data(app_config['media_types']) + + # Set up the database + connection, db = setup_connection_and_db_from_config(app_config) + + # If migrations table not made, make it! + assure_migrations_table_setup(db) + + # Setup media managers for all dbdata, run init/migrate and print info + # For each component, create/migrate tables + for dbdata in dbdatas: + migration_manager = dbdata.make_migration_manager(db) + migration_manager.init_or_migrate() -- cgit v1.2.3 From 3f2c6f96c191eb89f1c6ec7c903219b445f410a0 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 2 Jan 2012 16:08:32 -0600 Subject: No need for self here (thanks again Elrond ;)) --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 52819c6d..1fc5121a 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -32,7 +32,7 @@ class DatabaseData(object): self.name, self.models, self.migrations, db) -def gather_database_data(self, media_types): +def gather_database_data(media_types): """ Gather all database data relevant to the extensions we have installed so we can do migrations and table initialization. -- cgit v1.2.3 From 3ea1cf36fcfec9a381f2c425e626c4107e7dca43 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 18 Feb 2012 23:19:09 -0600 Subject: Updates so that dbupdate command works - Various fixes to dbupdate itself - Switching db/sql/migrations.py to use a dict instead of a list - Registering the function --- mediagoblin/gmg_commands/dbupdate.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 1fc5121a..27698170 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from sqlalchemy.orm import sessionmaker + from mediagoblin.db.sql.open import setup_connection_and_db_from_config from mediagoblin.db.sql.util import ( MigrationManager, assure_migrations_table_setup) @@ -21,15 +23,19 @@ from mediagoblin.init import setup_global_and_app_config from mediagoblin.tools.common import import_component +def dbupdate_parse_setup(subparser): + pass + + class DatabaseData(object): def __init__(self, name, models, migrations): self.name = name self.models = models self.migrations = migrations - def make_migration_manager(self, db): + def make_migration_manager(self, session): return MigrationManager( - self.name, self.models, self.migrations, db) + self.name, self.models, self.migrations, session) def gather_database_data(media_types): @@ -74,11 +80,10 @@ def dbupdate(args): # Set up the database connection, db = setup_connection_and_db_from_config(app_config) - # If migrations table not made, make it! - assure_migrations_table_setup(db) + Session = sessionmaker(bind=db.engine) # Setup media managers for all dbdata, run init/migrate and print info # For each component, create/migrate tables for dbdata in dbdatas: - migration_manager = dbdata.make_migration_manager(db) + migration_manager = dbdata.make_migration_manager(Session()) migration_manager.init_or_migrate() -- cgit v1.2.3 From d693f6bd867871ba084f0da0ff8ba5a667174fc7 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 26 Mar 2012 11:14:11 -0500 Subject: SQL based tests and refactored Celery setup stuff - Changed config files of test configs to use SQL - Updated celery initialization tools, factored them to be able to use the "big instance" application stuff --- mediagoblin/gmg_commands/dbupdate.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 27698170..5415b997 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -65,14 +65,13 @@ def gather_database_data(media_types): return managed_dbdata -def dbupdate(args): +def run_dbupdate(app_config): """ Initialize or migrate the database as specified by the config file. Will also initialize or migrate all extensions (media types, and in the future, plugins) """ - globa_config, app_config = setup_global_and_app_config(args.conf_file) # Gather information from all media managers / projects dbdatas = gather_database_data(app_config['media_types']) @@ -87,3 +86,8 @@ def dbupdate(args): for dbdata in dbdatas: migration_manager = dbdata.make_migration_manager(Session()) migration_manager.init_or_migrate() + + +def dbupdate(args): + global_config, app_config = setup_global_and_app_config(args.conf_file) + run_dbupdate(app_config) -- cgit v1.2.3 From a855e92a985a9bdc9c5062cad268eba3d8e19f84 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Sun, 3 Jun 2012 15:53:34 -0400 Subject: Fix problems from pyflakes output --- mediagoblin/gmg_commands/dbupdate.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 5415b997..dc36be82 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -17,8 +17,7 @@ from sqlalchemy.orm import sessionmaker from mediagoblin.db.sql.open import setup_connection_and_db_from_config -from mediagoblin.db.sql.util import ( - MigrationManager, assure_migrations_table_setup) +from mediagoblin.db.sql.util import MigrationManager from mediagoblin.init import setup_global_and_app_config from mediagoblin.tools.common import import_component -- cgit v1.2.3 From a00ac32045a7a03d91e0e64ee8470f0bd6f383d8 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Wed, 4 Jul 2012 10:54:44 -0400 Subject: Make sure MigrationManagers always get Unicode names. If we fail to do this, SQLAlchemy complains that we're binding a non-Unicode value to a Unicode column. --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index dc36be82..1c48ff57 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -52,7 +52,7 @@ def gather_database_data(media_types): managed_dbdata.append( DatabaseData( - '__main__', MAIN_MODELS, MAIN_MIGRATIONS)) + u'__main__', MAIN_MODELS, MAIN_MIGRATIONS)) # Then get all registered media managers (eventually, plugins) for media_type in media_types: -- cgit v1.2.3 From f46e2a4db9e70aba473bec537300103c9102ef1a Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Wed, 12 Sep 2012 22:41:04 +0200 Subject: Add OAuth models, plugin DB migrations, api_auth --- mediagoblin/gmg_commands/dbupdate.py | 46 ++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 1c48ff57..12329b54 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import logging + from sqlalchemy.orm import sessionmaker from mediagoblin.db.sql.open import setup_connection_and_db_from_config @@ -21,6 +23,9 @@ from mediagoblin.db.sql.util import MigrationManager from mediagoblin.init import setup_global_and_app_config from mediagoblin.tools.common import import_component +_log = logging.getLogger(__name__) +logging.basicConfig() +_log.setLevel(logging.DEBUG) def dbupdate_parse_setup(subparser): pass @@ -37,7 +42,7 @@ class DatabaseData(object): self.name, self.models, self.migrations, session) -def gather_database_data(media_types): +def gather_database_data(media_types, plugins): """ Gather all database data relevant to the extensions we have installed so we can do migrations and table initialization. @@ -61,10 +66,41 @@ def gather_database_data(media_types): managed_dbdata.append( DatabaseData(media_type, models, migrations)) + for plugin in plugins: + try: + models = import_component('{0}.models:MODELS'.format(plugin)) + except ImportError as exc: + _log.debug('No models found for {0}: {1}'.format( + plugin, + exc)) + + models = [] + except AttributeError as exc: + _log.warning('Could not find MODELS in {0}.models, have you \ +forgotten to add it? ({1})'.format(plugin, exc)) + + try: + migrations = import_component('{0}.migrations:MIGRATIONS'.format( + plugin)) + except ImportError as exc: + _log.debug('No migrations found for {0}: {1}'.format( + plugin, + exc)) + + migrations = {} + except AttributeError as exc: + _log.debug('Cloud not find MIGRATIONS in {0}.migrations, have you \ +forgotten to add it? ({1})'.format(plugin, exc)) + + if models: + managed_dbdata.append( + DatabaseData(plugin, models, migrations)) + + return managed_dbdata -def run_dbupdate(app_config): +def run_dbupdate(app_config, global_config): """ Initialize or migrate the database as specified by the config file. @@ -73,7 +109,9 @@ def run_dbupdate(app_config): """ # Gather information from all media managers / projects - dbdatas = gather_database_data(app_config['media_types']) + dbdatas = gather_database_data( + app_config['media_types'], + global_config['plugins'].keys()) # Set up the database connection, db = setup_connection_and_db_from_config(app_config) @@ -89,4 +127,4 @@ def run_dbupdate(app_config): def dbupdate(args): global_config, app_config = setup_global_and_app_config(args.conf_file) - run_dbupdate(app_config) + run_dbupdate(app_config, global_config) -- cgit v1.2.3 From 30520c92cc621bd0826259aca3d9b7b740f71ef0 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sat, 15 Sep 2012 17:54:34 +0200 Subject: Fixed tests - Adapt tests to new global_config arg for run_dbupdate - Account for [plugins] not being set in config --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 12329b54..67fdd69c 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -111,7 +111,7 @@ def run_dbupdate(app_config, global_config): # Gather information from all media managers / projects dbdatas = gather_database_data( app_config['media_types'], - global_config['plugins'].keys()) + global_config.get('plugins', {}).keys()) # Set up the database connection, db = setup_connection_and_db_from_config(app_config) -- cgit v1.2.3 From bc142abc5592975c08319416d0af12c108504887 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 29 Nov 2012 17:23:28 +0100 Subject: RIP out mongo Since sqlalchemy is providing our database abstraction and we have moved away from Mongo as the underlying database, it is now time to simplify things and rip out mongo. This provides the bulk of the changes, and can stand on its own. There are some followup tasks that can be done, such as removing now unneeded abstraction layers, e.g. db.sql.fake.py --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 67fdd69c..4b301178 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -114,7 +114,7 @@ def run_dbupdate(app_config, global_config): global_config.get('plugins', {}).keys()) # Set up the database - connection, db = setup_connection_and_db_from_config(app_config) + db = setup_connection_and_db_from_config(app_config) Session = sessionmaker(bind=db.engine) -- cgit v1.2.3 From 6eddc3b75e7cdf1e4d4015aeeccff6e250b10558 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 30 Nov 2012 09:32:25 +0100 Subject: Move db.sql.open to db.open Now that mongo has been ripped out and sqlalchemy is already providing the database abstraction, there is no need to hide everything in the sql module. Transition db.sql.open to db.open and adapt all direct importers. --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 4b301178..203179fd 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -18,7 +18,7 @@ import logging from sqlalchemy.orm import sessionmaker -from mediagoblin.db.sql.open import setup_connection_and_db_from_config +from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.db.sql.util import MigrationManager from mediagoblin.init import setup_global_and_app_config from mediagoblin.tools.common import import_component -- cgit v1.2.3 From 953698842532526afdeadaf6697b35ade84d379c Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 30 Nov 2012 10:03:53 +0100 Subject: Move db.sql.migrations to db.migrations --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 203179fd..2c34bb51 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -53,7 +53,7 @@ def gather_database_data(media_types, plugins): # Add main first from mediagoblin.db.sql.models import MODELS as MAIN_MODELS - from mediagoblin.db.sql.migrations import MIGRATIONS as MAIN_MIGRATIONS + from mediagoblin.db.migrations import MIGRATIONS as MAIN_MIGRATIONS managed_dbdata.append( DatabaseData( -- cgit v1.2.3 From 1e46dc2537c5ee706a55876c4dbf86129baafbbf Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 30 Nov 2012 09:49:45 +0100 Subject: Move db.sql.util to db.util Now that sqlalchemy is providing the database abstractions, there is no need to hide everything in db.sql. sub-modules. It complicates the code and provides a futher layer of indirection. Move the db.sql.util.py to db.util.py and adapt the importers. --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 2c34bb51..95898c08 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -19,7 +19,7 @@ import logging from sqlalchemy.orm import sessionmaker from mediagoblin.db.open import setup_connection_and_db_from_config -from mediagoblin.db.sql.util import MigrationManager +from mediagoblin.db.util import MigrationManager from mediagoblin.init import setup_global_and_app_config from mediagoblin.tools.common import import_component -- cgit v1.2.3 From b0c8328e547288028e7e43f0ceb1fa9f7c8dac4a Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 30 Nov 2012 10:10:35 +0100 Subject: Move db.sql.models* to db.models* --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 95898c08..5151ba9d 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -52,7 +52,7 @@ def gather_database_data(media_types, plugins): managed_dbdata = [] # Add main first - from mediagoblin.db.sql.models import MODELS as MAIN_MODELS + from mediagoblin.db.models import MODELS as MAIN_MODELS from mediagoblin.db.migrations import MIGRATIONS as MAIN_MIGRATIONS managed_dbdata.append( -- cgit v1.2.3 From a050e776c6d9c4970dd241e92b2f24a8c9deb36d Mon Sep 17 00:00:00 2001 From: Elrond Date: Thu, 13 Dec 2012 12:31:47 +0100 Subject: Move all the migration tools into new migration_tools.py Factor all the migration related stuff out into a new .db.sql.migration_tools. First we don't have to load this module for our normal server. Second it makes all the import dependencies a little more cleaner. --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 5151ba9d..dadb79c7 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -19,7 +19,7 @@ import logging from sqlalchemy.orm import sessionmaker from mediagoblin.db.open import setup_connection_and_db_from_config -from mediagoblin.db.util import MigrationManager +from mediagoblin.db.sql.migration_tools import MigrationManager from mediagoblin.init import setup_global_and_app_config from mediagoblin.tools.common import import_component -- cgit v1.2.3 From c130e3ee79affaf9e2e52a98506ffb1a7f5c9db6 Mon Sep 17 00:00:00 2001 From: Elrond Date: Tue, 8 Jan 2013 22:12:16 +0100 Subject: Move db.sql.migration_tools to db.migration_tools. Follow the new trend. --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index dadb79c7..65b3f922 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -19,7 +19,7 @@ import logging from sqlalchemy.orm import sessionmaker from mediagoblin.db.open import setup_connection_and_db_from_config -from mediagoblin.db.sql.migration_tools import MigrationManager +from mediagoblin.db.migration_tools import MigrationManager from mediagoblin.init import setup_global_and_app_config from mediagoblin.tools.common import import_component -- cgit v1.2.3 From 313b38f895332a700984adf8156ec9b3c4150b09 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 26 Apr 2013 15:09:03 -0500 Subject: Don't turn on sqlite refcheck stuff during migrations --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 65b3f922..f33d83d5 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -114,7 +114,7 @@ def run_dbupdate(app_config, global_config): global_config.get('plugins', {}).keys()) # Set up the database - db = setup_connection_and_db_from_config(app_config) + db = setup_connection_and_db_from_config(app_config, sqlite_refcheck=False) Session = sessionmaker(bind=db.engine) -- cgit v1.2.3 From ea5fb2d9d4785b1d0afc4185da15783629831fee Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 26 Apr 2013 15:27:44 -0500 Subject: Switch "sqlite_refcheck" keyword arg to "migrations" which Elrond thinks is cleaner Also, if migrations is true, *explicitly* say that foreign key checking is off --- mediagoblin/gmg_commands/dbupdate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index f33d83d5..32700c40 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -114,7 +114,7 @@ def run_dbupdate(app_config, global_config): global_config.get('plugins', {}).keys()) # Set up the database - db = setup_connection_and_db_from_config(app_config, sqlite_refcheck=False) + db = setup_connection_and_db_from_config(app_config, migrations=True) Session = sessionmaker(bind=db.engine) -- cgit v1.2.3 From 0ae38290488e39f2b3d0ec1248f0b78a6dceeba6 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 16 May 2013 16:56:20 -0500 Subject: Fixing bug in dbupdate where it would explode on plugin that is missing MODELS or MIGRATIONS The reason it blew up was because in the latter caught exception, it wouldn't set models/migrations to an empty set, so it would actually use the previous run's models/migrations! That's what we get for "leaky" variables on python for loops :) This commit sponsored by Pascal Diogo Antunes. Thank you! --- mediagoblin/gmg_commands/dbupdate.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'mediagoblin/gmg_commands/dbupdate.py') diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 32700c40..fa25ecb2 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -78,6 +78,7 @@ def gather_database_data(media_types, plugins): except AttributeError as exc: _log.warning('Could not find MODELS in {0}.models, have you \ forgotten to add it? ({1})'.format(plugin, exc)) + models = [] try: migrations = import_component('{0}.migrations:MIGRATIONS'.format( @@ -91,6 +92,7 @@ forgotten to add it? ({1})'.format(plugin, exc)) except AttributeError as exc: _log.debug('Cloud not find MIGRATIONS in {0}.migrations, have you \ forgotten to add it? ({1})'.format(plugin, exc)) + migrations = {} if models: managed_dbdata.append( -- cgit v1.2.3