Make failure to run appropraite upgrade scripts more helpful.

This commit is contained in:
Erik Johnston 2014-12-16 14:20:32 +00:00
parent 592ba14b36
commit 2e44714214
2 changed files with 22 additions and 3 deletions

View File

@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from synapse.storage import prepare_database from synapse.storage import prepare_database, UpgradeDatabaseException
from synapse.server import HomeServer from synapse.server import HomeServer
@ -228,8 +228,15 @@ def setup():
logger.info("Preparing database: %s...", db_name) logger.info("Preparing database: %s...", db_name)
with sqlite3.connect(db_name) as db_conn: try:
prepare_database(db_conn) with sqlite3.connect(db_name) as db_conn:
prepare_database(db_conn)
except UpgradeDatabaseException:
sys.stderr.write(
"\nFailed to upgrade database.\n"
"Have you followed any instructions in UPGRADES.rst?\n"
)
sys.exit(1)
logger.info("Database prepared in %s.", db_name) logger.info("Database prepared in %s.", db_name)

View File

@ -526,6 +526,14 @@ def read_schema(schema):
return schema_file.read() return schema_file.read()
class PrepareDatabaseException(Exception):
pass
class UpgradeDatabaseException(PrepareDatabaseException):
pass
def prepare_database(db_conn): def prepare_database(db_conn):
""" Set up all the dbs. Since all the *.sql have IF NOT EXISTS, so we """ Set up all the dbs. Since all the *.sql have IF NOT EXISTS, so we
don't have to worry about overwriting existing content. don't have to worry about overwriting existing content.
@ -542,6 +550,10 @@ def prepare_database(db_conn):
"Cannot use this database as it is too " + "Cannot use this database as it is too " +
"new for the server to understand" "new for the server to understand"
) )
elif user_version < 10:
raise UpgradeDatabaseException(
"No delta for versions less than 10"
)
elif user_version < SCHEMA_VERSION: elif user_version < SCHEMA_VERSION:
logger.info( logger.info(
"Upgrading database from version %d", "Upgrading database from version %d",