Repository :
http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
---------------------------------------------------------------
commit 1d8511b957582b169992c1cdc8e1fa27f3a3bc6c
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Mon Dec 17 19:08:57 2012 +0100
When creating the database add the alembic version of the database
This allows to use correctly `alembic upgrade head` after.
---------------------------------------------------------------
createdb.py | 3 ++-
fedocal.cfg.sample | 6 ++++++
fedocal/fedocallib/model.py | 13 +++++++++++--
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/createdb.py b/createdb.py
index bccd5ac..482e4e0 100644
--- a/createdb.py
+++ b/createdb.py
@@ -3,4 +3,5 @@
from fedocal import APP
from fedocal.fedocallib import model
-model.create_tables(APP.config['DB_URL'], True)
+model.create_tables(APP.config['DB_URL'],
+ APP.config['PATH_ALEMBIC_INI'], True)
diff --git a/fedocal.cfg.sample b/fedocal.cfg.sample
index 3747a02..7d3cc39 100644
--- a/fedocal.cfg.sample
+++ b/fedocal.cfg.sample
@@ -21,3 +21,9 @@ SMTP_SERVER='localhost'
### avoid sending multiple reminders for a single meeting.
### Default: 30
CRON_FREQUENCY=30
+
+### Path to the alembic configuration file
+### When creating the database, we need to tell the database which
+### revision of alembic we are at and to do this we need access to the
+### alembic.ini file.
+PATH_ALEMBIC_INI='/path/to/alembic.ini'
diff --git a/fedocal/fedocallib/model.py b/fedocal/fedocallib/model.py
index 087b047..2c6283c 100644
--- a/fedocal/fedocallib/model.py
+++ b/fedocal/fedocallib/model.py
@@ -42,7 +42,7 @@ from sqlalchemy.sql import and_
BASE = declarative_base()
-def create_tables(db_url, debug=False):
+def create_tables(db_url, alembic_ini, debug=False):
""" Create the tables in the database using the information from the
url obtained.
@@ -50,12 +50,21 @@ def create_tables(db_url, debug=False):
information with regards to the database engine, the host to connect
to, the user and password and the database name.
ie: <engine>://<user>:<password>@<host>/<dbname>
- :arg debug, a boolean specifying wether we should have the verbose
+ :arg alembic_ini, path to the alembic ini file.
+ :kwarg debug, a boolean specifying wether we should have the verbose
output of sqlalchemy or not.
:return a session that can be used to query the database.
"""
engine = create_engine(db_url, echo=debug)
BASE.metadata.create_all(engine)
+
+ # 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")
+
sessionmak = sessionmaker(bind=engine)
return sessionmak()