[PATCH 3/6] Insert the alembic revision at the DB creation (prevent future crash)
Pierre-Yves Chibon
pingou at pingoured.fr
Mon Jan 7 20:26:14 UTC 2013
---
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()
--
1.7.1
More information about the copr-devel
mailing list