diff options
-rw-r--r-- | db.c | 2 | ||||
-rwxr-xr-x | migrate_2_to_3.sh | 26 | ||||
-rw-r--r-- | schema.sql | 4 |
3 files changed, 29 insertions, 3 deletions
@@ -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" <schema.sql + +sqlite3 "$INDB" '.dump' | + sed '/^INSERT INTO/!d' | + sqlite3 "$OUTDB" + +sqlite3 "$OUTDB" 'update Meta set version = 3' + +echo "Migrated '$INDB' to '$OUTDB'." @@ -1,4 +1,4 @@ --- Database schema version 2 +-- Database schema version 3 pragma foreign_keys = on; @@ -29,7 +29,7 @@ create table Users ( create unique index users_name_index on Users(name); create table Messages ( - id integer primary key not null, + id integer primary key autoincrement not null, room integer not null, user integer null, time integer not null, |