Browse Source

Add support for plugin migrations via branch labels

Peter Justin 8 years ago
parent
commit
9dd5f0c47b
2 changed files with 26 additions and 0 deletions
  1. 7 0
      flaskbb/configs/default.py
  2. 19 0
      flaskbb/utils/helpers.py

+ 7 - 0
flaskbb/configs/default.py

@@ -12,6 +12,8 @@
 import os
 import sys
 import datetime
+import glob
+from flaskbb.utils.helpers import get_alembic_branches
 
 
 class DefaultConfig(object):
@@ -70,6 +72,11 @@ class DefaultConfig(object):
     # This will print all SQL statements
     SQLALCHEMY_ECHO = False
 
+    ALEMBIC = {
+        'script_location': os.path.join(basedir, "migrations"),
+        'version_locations': get_alembic_branches()
+    }
+
     # Security
     # ------------------------------
     # This is the secret key that is used for session signing.

+ 19 - 0
flaskbb/utils/helpers.py

@@ -12,6 +12,8 @@ import re
 import time
 import itertools
 import operator
+import os
+import glob
 from datetime import datetime, timedelta
 from pytz import UTC
 from PIL import ImageFile
@@ -491,3 +493,20 @@ def check_image(url):
         return error, False
 
     return error, True
+
+
+def get_alembic_branches():
+    """Returns a tuple with (branchname, plugin_dir) combinations.
+    The branchname is the name of plugin directory which should also be
+    the unique identifier of the plugin.
+    """
+    basedir = os.path.dirname(os.path.dirname(__file__))
+    plugin_migration_dirs = glob.glob(
+        "{}/*/migrations".format(os.path.join(basedir, "plugins"))
+    )
+    branches_dirs = [
+        tuple([os.path.basename(os.path.dirname(p)), p])
+        for p in plugin_migration_dirs
+    ]
+
+    return branches_dirs