Commit b539c2df authored by Joshua Tauberer's avatar Joshua Tauberer

Merge pull request #347 from Toilal/feat/start-enhancements

If the migration file is missing but the storage directory exists, assume this is a fresh directory -- don't bother trying to migrate, and do write the migration file with the current migration ID.
parents a8669197 64fdb4dd
...@@ -84,13 +84,22 @@ def run_migrations(): ...@@ -84,13 +84,22 @@ def run_migrations():
env = load_environment() env = load_environment()
migration_id_file = os.path.join(env['STORAGE_ROOT'], 'mailinabox.version') migration_id_file = os.path.join(env['STORAGE_ROOT'], 'mailinabox.version')
migration_id = None
if os.path.exists(migration_id_file): if os.path.exists(migration_id_file):
with open(migration_id_file) as f: with open(migration_id_file) as f:
ourver = int(f.read().strip()) migration_id = f.read().strip();
else:
if migration_id is None:
# Load the legacy location of the migration ID. We'll drop support # Load the legacy location of the migration ID. We'll drop support
# for this eventually. # for this eventually.
ourver = int(env.get("MIGRATIONID", "0")) migration_id = env.get("MIGRATIONID")
if migration_id is None:
print()
print("%s file doesn't exists. Skipping migration..." % (migration_id_file,))
return
ourver = int(migration_id)
while True: while True:
next_ver = (ourver + 1) next_ver = (ourver + 1)
......
...@@ -109,6 +109,10 @@ fi ...@@ -109,6 +109,10 @@ fi
# Create the STORAGE_ROOT if it not exists # Create the STORAGE_ROOT if it not exists
if [ ! -d $STORAGE_ROOT ]; then if [ ! -d $STORAGE_ROOT ]; then
mkdir -p $STORAGE_ROOT mkdir -p $STORAGE_ROOT
fi
# Create mailinabox.version file if not exists
if [ ! -f $STORAGE_ROOT/mailinabox.version ]; then
echo $(setup/migrate.py --current) > $STORAGE_ROOT/mailinabox.version echo $(setup/migrate.py --current) > $STORAGE_ROOT/mailinabox.version
chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox.version chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox.version
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment