فهرست منبع

use integer data type to store lastwarntime

Mike 9 ماه پیش
والد
کامیت
087b71a72d
3فایلهای تغییر یافته به همراه17 افزوده شده و 2 حذف شده
  1. 6 0
      state/migrations/0024_fix_warn_timestamp.down.sql
  2. 7 0
      state/migrations/0024_fix_warn_timestamp.up.sql
  3. 4 2
      state/user_store.go

+ 6 - 0
state/migrations/0024_fix_warn_timestamp.down.sql

@@ -0,0 +1,6 @@
+-- Revert lastWarnUpdate back to DATETIME type
+
+ALTER TABLE users DROP COLUMN lastWarnUpdate;
+
+ALTER TABLE users ADD COLUMN lastWarnUpdate DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00';
+

+ 7 - 0
state/migrations/0024_fix_warn_timestamp.up.sql

@@ -0,0 +1,7 @@
+-- Change lastWarnUpdate from DATETIME to INTEGER (Unix timestamp)
+-- The old data is corrupted (Go string representation), so we'll drop and recreate
+
+ALTER TABLE users DROP COLUMN lastWarnUpdate;
+
+ALTER TABLE users ADD COLUMN lastWarnUpdate INTEGER NOT NULL DEFAULT 0;
+

+ 4 - 2
state/user_store.go

@@ -430,6 +430,7 @@ func (f SQLiteUserStore) queryUsers(ctx context.Context, whereClause string, que
 	for rows.Next() {
 		var u User
 		var sn string
+		var lastWarnUpdateUnix int64
 		err := rows.Scan(
 			&sn,
 			&u.DisplayScreenName,
@@ -509,13 +510,14 @@ func (f SQLiteUserStore) queryUsers(ctx context.Context, whereClause string, que
 			&u.AIMDirectoryInfo.ZIPCode,
 			&u.AIMDirectoryInfo.Address,
 			&u.TOCConfig,
-			&u.LastWarnUpdate,
+			&lastWarnUpdateUnix,
 			&u.LastWarnLevel,
 		)
 		if err != nil {
 			return nil, err
 		}
 		u.IdentScreenName = NewIdentScreenName(sn)
+		u.LastWarnUpdate = time.Unix(lastWarnUpdateUnix, 0).UTC()
 		users = append(users, u)
 	}
 	if err = rows.Err(); err != nil {
@@ -2043,7 +2045,7 @@ func (f SQLiteUserStore) SetWarnLevel(ctx context.Context, user IdentScreenName,
 	`
 	res, err := f.db.ExecContext(ctx,
 		q,
-		lastWarnUpdate,
+		lastWarnUpdate.Unix(),
 		lastWarnLevel,
 		user.String(),
 	)