Factor out check_db_migrations_current
When initializing the database connection the current mongo based setup checked for new migrations and warned about them. This was mongo specific so factor'd it out into a more generic check_db_migrations_current function in the mongo backend. Also created a dummy one in the sql backend.
This commit is contained in:
@@ -18,6 +18,7 @@ import pymongo
|
||||
import mongokit
|
||||
from paste.deploy.converters import asint
|
||||
from mediagoblin.db.mongo import models
|
||||
from mediagoblin.db.util import MigrationManager
|
||||
|
||||
|
||||
def connect_database_from_config(app_config, use_pymongo=False):
|
||||
@@ -53,3 +54,25 @@ def setup_connection_and_db_from_config(app_config, use_pymongo=False):
|
||||
models.register_models(connection)
|
||||
|
||||
return (connection, db)
|
||||
|
||||
|
||||
def check_db_migrations_current(db):
|
||||
# This MUST be imported so as to set up the appropriate migrations!
|
||||
from mediagoblin.db.mongo import migrations
|
||||
|
||||
# Init the migration number if necessary
|
||||
migration_manager = MigrationManager(db)
|
||||
migration_manager.install_migration_version_if_missing()
|
||||
|
||||
# Tiny hack to warn user if our migration is out of date
|
||||
if not migration_manager.database_at_latest_migration():
|
||||
db_migration_num = migration_manager.database_current_migration()
|
||||
latest_migration_num = migration_manager.latest_migration()
|
||||
if db_migration_num < latest_migration_num:
|
||||
print (
|
||||
"*WARNING:* Your migrations are out of date, "
|
||||
"maybe run ./bin/gmg migrate?")
|
||||
elif db_migration_num > latest_migration_num:
|
||||
print (
|
||||
"*WARNING:* Your migrations are out of date... "
|
||||
"in fact they appear to be from the future?!")
|
||||
|
||||
@@ -14,4 +14,5 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from mediagoblin.db.mongo.open import setup_connection_and_db_from_config
|
||||
from mediagoblin.db.mongo.open import \
|
||||
setup_connection_and_db_from_config, check_db_migrations_current
|
||||
|
||||
@@ -27,3 +27,7 @@ def setup_connection_and_db_from_config(app_config):
|
||||
Session.configure(bind=engine)
|
||||
|
||||
return "dummy conn", DatabaseMaster(engine)
|
||||
|
||||
|
||||
def check_db_migrations_current(db):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user