[copr] master: Insert the alembic revision at the DB creation (prevent future crash) (f1bb3e5)

bkabrda at fedoraproject.org bkabrda at fedoraproject.org
Tue Jan 8 07:47:16 UTC 2013


Repository : http://git.fedorahosted.org/cgit/copr.git

On branch  : master

>---------------------------------------------------------------

commit f1bb3e5a8d6f563c235055b297e30d9558d63741
Author: Pierre-Yves Chibon <pingou at pingoured.fr>
Date:   Tue Jan 8 08:17:32 2013 +0100

    Insert the alembic revision at the DB creation (prevent future crash)


>---------------------------------------------------------------

 coprs_frontend/manage.py |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/coprs_frontend/manage.py b/coprs_frontend/manage.py
index d032f26..7716e86 100755
--- a/coprs_frontend/manage.py
+++ b/coprs_frontend/manage.py
@@ -16,9 +16,16 @@ class DBManager(object):
             if not os.path.exists(datadir_name):
                 os.makedirs(datadir_name)
 
-    def create_db(self):
+    def create_db(self, alembic_ini=None):
         self.create_sqlite_file()
         self.db.create_all()
+        if alembic_ini is not None:
+            # then, load the Alembic configuration and generate the
+            # version table, "stamping" it with the most recent rev:
+            from alembic.config import Config
+            from alembic import command
+            alembic_cfg = Config(alembic_ini)
+            command.stamp(alembic_cfg, "head")
 
     def delete_db(self):
         self.db.drop_all()
@@ -39,12 +46,19 @@ parser.add_argument('-d', '--delete-db',
                     help = 'Delete DB',
                     action = 'store_true')
 
+parser.add_argument('-f', '--alembic',
+                    required = False,
+                    help = 'Path to the alembic configuration file (alembic.ini)')
+
 args = parser.parse_args()
 
 manager = DBManager(db)
 if args.create_sqlite_file:
     manager.create_sqlite_file()
 elif args.create_db:
-    manager.create_db()
+    if not args.alembic:
+        print "Please provide the path to the alembic configuration file."
+    else:
+        manager.create_db(args.alembic)
 elif args.delete_db:
     manager.delete_db()



More information about the copr-devel mailing list