From 4c5dee222b940dcfdf6f7356b6fa3b3bf4dbcb73 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 1 Aug 2020 14:54:19 +0200 Subject: server: autoincrement on msgid to prevent reuse if room is deleted --- db.c | 2 +- migrate_2_to_3.sh | 26 ++++++++++++++++++++++++++ schema.sql | 4 ++-- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100755 migrate_2_to_3.sh diff --git a/db.c b/db.c index d94b13c..f5f2572 100644 --- a/db.c +++ b/db.c @@ -10,7 +10,7 @@ #define SQLITE(func,...) do{if(sqlite3_##func(__VA_ARGS__)!=SQLITE_OK){die_sqlite("sqlite3_" #func);}}while(0) -#define DATABASE_VERSION 2 +#define DATABASE_VERSION 3 #define PASSHASH_OPSLIMIT 3 #define PASSHASH_MEMLIMIT crypto_pwhash_MEMLIMIT_INTERACTIVE diff --git a/migrate_2_to_3.sh b/migrate_2_to_3.sh new file mode 100755 index 0000000..a56382b --- /dev/null +++ b/migrate_2_to_3.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail +INDB=db.db +OUTDB=db_migrated.db + +inversion="$(sqlite3 "$INDB" 'select version from Meta')" + +if [[ $inversion != "2" ]]; then + echo >&2 "$0 migrates from version 2 to version 3, but the database is at version $inversion." + exit 1 +fi + +if [[ -f "$OUTDB" ]]; then + echo >&2 "Output database $OUTDB already exists; remove before running this script" + exit 1 +fi + +sqlite3 "$OUTDB"