Skip to content

Commit

Permalink
Merge pull request #1265 from privacyidea/1255/no-stamping
Browse files Browse the repository at this point in the history
Allow no schema stamping during update
  • Loading branch information
plettich committed Oct 1, 2018
2 parents 6f16fab + a2c43cd commit 7a18294
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
8 changes: 8 additions & 0 deletions doc/installation/upgrade.rst
Expand Up @@ -37,6 +37,14 @@ backup) and run the command:

privacyidea-pip-update

The following parameters are allowed:

``-f`` or ``--force`` skips the safety question, if you really want to update.

``-s`` or ``--skipstamp`` skips the version stamping during schema update.

``-n`` or ``--noshema`` completely skips the schema update and only updates the code.


Manual upgrade
..............
Expand Down
24 changes: 18 additions & 6 deletions tools/privacyidea-pip-update
Expand Up @@ -14,8 +14,10 @@ def usage():
print("""
privacyidea-pip-update
-f, --force force the update
-h, --help show this help
-f, --force force the update
-s, --skipstamp skip the stamping of the database. Use this, if you know your DB has the correct version.
-n, --noschema do not run the schema update.
-h, --help show this help
""")


Expand All @@ -42,14 +44,19 @@ def update():
call(PIP_EXECUTABLE + ["install", "--upgrade", "privacyidea"])


def update_db_schema(environment):
def update_db_schema(environment, skip_stamp=False):
mig_path = environment + "/lib/privacyidea/migrations"
command = "privacyidea-schema-upgrade {0}".format(pipes.quote(mig_path))
if skip_stamp:
command += " --skipstamp"
# update the database schema
call("privacyidea-schema-upgrade {0}".format(pipes.quote(mig_path)), shell=True)
call(command, shell=True)


def main():
force = False
skip_stamp = False
no_schema = False

environment = os.environ.get("VIRTUAL_ENV")

Expand All @@ -58,14 +65,18 @@ def main():
sys.exit(2)

try:
opts, args = getopt.getopt(sys.argv[1:], "hf", ["help", "force"])
opts, args = getopt.getopt(sys.argv[1:], "snhf", ["help", "force", "skipstamp", "noschema"])
except getopt.GetoptError as e:
print(str(e))
sys.exit(1)

for o, a in opts:
if o in ("-f", "--force"):
force = True
if o in ("-s", "--skipstamp"):
skip_stamp = True
if o in ("-n", "--noschema"):
no_schema = True
if o in ("-h", "--help"):
usage()
sys.exit(2)
Expand All @@ -81,7 +92,8 @@ def main():

if res.lower() == 'y':
update()
update_db_schema(environment)
if not no_schema:
update_db_schema(environment, skip_stamp)
else:
print("You canceled the update process.")

Expand Down
9 changes: 6 additions & 3 deletions tools/privacyidea-schema-upgrade
Expand Up @@ -2,6 +2,7 @@

MIGRATION_PATH=$1
FIRST_VERSION="4f32a4e1bf33"
SKIP_STAMP=$2

if [ -z "$MIGRATION_PATH" ]; then
echo "Please specify the path with the migration files."
Expand All @@ -10,9 +11,11 @@ fi

# check if we do not have DB versioning, yet.
if [ -z "$(pi-manage db current -d $MIGRATION_PATH | grep "(head)$")" ]; then
# Set the version to the first PI 2.0 version
echo "++ Stamping DB to $FIRST_VERSION"
pi-manage db stamp $FIRST_VERSION -d $MIGRATION_PATH > /dev/null
if [ "$SKIP_STAMP" != "--skipstamp" ]; then
# Set the version to the first PI 2.0 version
echo "++ Stamping DB to $FIRST_VERSION"
pi-manage db stamp $FIRST_VERSION -d $MIGRATION_PATH > /dev/null
fi
fi
# Upgrade the database
echo "++ Upgrading DB schema."
Expand Down

0 comments on commit 7a18294

Please sign in to comment.