summary refs log tree commit diff
path: root/database.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--database.h30
1 files changed, 25 insertions, 5 deletions
diff --git a/database.h b/database.h
index d9b2718..5893f77 100644
--- a/database.h
+++ b/database.h
@@ -31,7 +31,7 @@
 
 #define DATABASE_PATH "litterbox/litterbox.sqlite"
 
-enum { DatabaseVersion = 1 };
+enum { DatabaseVersion = 2 };
 
 #define ENUM_TYPE \
 	X(Privmsg, "privmsg") \
@@ -172,9 +172,10 @@ static inline void dbBindNull(sqlite3_stmt *stmt, const char *param) {
 	errx(EX_SOFTWARE, "sqlite3_bind_null: %s", sqlite3_errmsg(db));
 }
 
-static inline void dbBindInt(sqlite3_stmt *stmt, const char *param, int value) {
-	if (!sqlite3_bind_int(stmt, dbParam(stmt, param), value)) return;
-	errx(EX_SOFTWARE, "sqlite3_bind_int: %s", sqlite3_errmsg(db));
+static inline void
+dbBindInt(sqlite3_stmt *stmt, const char *param, sqlite3_int64 value) {
+	if (!sqlite3_bind_int64(stmt, dbParam(stmt, param), value)) return;
+	errx(EX_SOFTWARE, "sqlite3_bind_int64: %s", sqlite3_errmsg(db));
 }
 
 static inline void dbBindText5(
@@ -301,7 +302,14 @@ static const char *InitSQL = SQL(
 		) SELECT 'delete', * FROM text WHERE event = old.event;
 	END;
 
-	PRAGMA user_version = 1;
+	CREATE TABLE consumers (
+		host STRING NOT NULL,
+		port INTEGER NOT NULL,
+		pos INTEGER NOT NULL,
+		UNIQUE (host, port)
+	);
+
+	PRAGMA user_version = 2;
 
 	COMMIT TRANSACTION;
 );
@@ -328,6 +336,18 @@ static const char *MigrationSQL[] = {
 		PRAGMA user_version = 1;
 		COMMIT TRANSACTION;
 	),
+
+	SQL(
+		BEGIN TRANSACTION;
+		CREATE TABLE consumers (
+			host STRING NOT NULL,
+			port INTEGER NOT NULL,
+			pos INTEGER NOT NULL,
+			UNIQUE (host, port)
+		);
+		PRAGMA user_version = 2;
+		COMMIT TRANSACTION;
+	),
 };
 
 static inline void dbMigrate(void) {