aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db.c2
-rwxr-xr-xmigrate_2_to_3.sh26
-rw-r--r--schema.sql4
3 files changed, 29 insertions, 3 deletions
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" <schema.sql
+
+sqlite3 "$INDB" '.dump' |
+ sed '/^INSERT INTO/!d' |
+ sqlite3 "$OUTDB"
+
+sqlite3 "$OUTDB" 'update Meta set version = 3'
+
+echo "Migrated '$INDB' to '$OUTDB'."
diff --git a/schema.sql b/schema.sql
index 5a1938c..f1d33fc 100644
--- a/schema.sql
+++ b/schema.sql
@@ -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,