From 863f14e25f7a602debfaa7e4d03febb97c8136f9 Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 13 Jun 2022 16:00:02 +0100 Subject: [PATCH] Include created timestamp in user migration --- .../Services/Migrations/MigrateToPostgres.cs | 23 +++++++++++++++++-- VoidCat/Services/Users/PostgresUserStore.cs | 5 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/VoidCat/Services/Migrations/MigrateToPostgres.cs b/VoidCat/Services/Migrations/MigrateToPostgres.cs index 5d1a677..68fa7d2 100644 --- a/VoidCat/Services/Migrations/MigrateToPostgres.cs +++ b/VoidCat/Services/Migrations/MigrateToPostgres.cs @@ -105,8 +105,21 @@ public class MigrateToPostgres : IMigration { try { - var privateUser = await cacheUsers.GetPrivate(user.Id); - await _userStore.Set(privateUser!.Id, privateUser); + var privateUser = await cacheUsers.Get(user.Id); + privateUser!.Password ??= privateUser.PasswordHash; + + await _userStore.Set(privateUser!.Id, new InternalVoidUser() + { + Id = privateUser.Id, + Avatar = privateUser.Avatar, + Created = privateUser.Created, + DisplayName = privateUser.DisplayName, + Email = privateUser.Email, + Flags = privateUser.Flags, + LastLogin = privateUser.LastLogin, + Password = privateUser.Password!, + Roles = privateUser.Roles + }); _logger.LogInformation("Migrated user {USer}", user.Id); } catch (Exception ex) @@ -115,4 +128,10 @@ public class MigrateToPostgres : IMigration } } } + + private class PrivateUser : PrivateVoidUser + { + public string? PasswordHash { get; set; } + public string? Password { get; set; } + } } \ No newline at end of file diff --git a/VoidCat/Services/Users/PostgresUserStore.cs b/VoidCat/Services/Users/PostgresUserStore.cs index cb740ca..f449acc 100644 --- a/VoidCat/Services/Users/PostgresUserStore.cs +++ b/VoidCat/Services/Users/PostgresUserStore.cs @@ -32,13 +32,14 @@ public class PostgresUserStore : IUserStore await using var conn = await _connection.Get(); await conn.ExecuteAsync( @"insert into -""Users""(""Id"", ""Email"", ""Password"", ""LastLogin"", ""DisplayName"", ""Avatar"", ""Flags"") -values(:id, :email, :password, :lastLogin, :displayName, :avatar, :flags)", +""Users""(""Id"", ""Email"", ""Password"", ""Created"", ""LastLogin"", ""DisplayName"", ""Avatar"", ""Flags"") +values(:id, :email, :password, :created, :lastLogin, :displayName, :avatar, :flags)", new { Id = id, email = obj.Email, password = obj.Password, + created = obj.Created, displayName = obj.DisplayName, lastLogin = obj.LastLogin.ToUniversalTime(), avatar = obj.Avatar,