femto-backend/Femto.Database/Seed/TestDataSeeder.cs
2025-05-18 22:22:20 +02:00

81 lines
3.8 KiB
C#

using System.Text;
using Geralt;
using Npgsql;
namespace Femto.Database.Seed;
public static class TestDataSeeder
{
private const int Iterations = 3;
private const int MemorySize = 67108864;
public static async Task Seed(NpgsqlDataSource dataSource)
{
var id = Guid.Parse("0196960c-6296-7532-ba66-8fabb38c6ae0");
var username = "johnbotris";
var salt = new byte[32];
var password = "hunter2"u8;
var hashInput = new byte[password.Length + salt.Length];
password.CopyTo(hashInput);
salt.CopyTo(hashInput, password.Length);
var passwordHash = new byte[128];
Argon2id.ComputeHash(
passwordHash,
hashInput,
Iterations,
MemorySize
);
await using var addToHistoryCommand = dataSource.CreateCommand(
$"""
INSERT INTO blog.author
(id, username)
VALUES
(@id, @username)
;
INSERT INTO blog.post
(id, author_id, content)
VALUES
('019691a0-48ed-7eba-b8d3-608e25e07d4b', @id, 'However, authors often misinterpret the zoology as a smothered advantage, when in actuality it feels more like a blindfold accordion. They were lost without the chastest puppy that composed their Santa.'),
('019691a0-4ace-7bb5-a8f3-e3362920eba0', @id, 'Extending this logic, a swim can hardly be considered a seasick duckling without also being a tornado. Some posit the whity voyage to be less than dippy.'),
('019691a0-4c3e-726f-b8f6-bcbaabe789ae', @id,'Few can name a springless sun that isn''t a thudding Vietnam. The burn of a competitor becomes a frosted target.'),
('019691a0-4dd3-7e89-909e-94a6fd19a05e', @id,'Some unwitched marbles are thought of simply as currencies. A boundary sees a nepal as a chordal railway.')
;
INSERT INTO blog.post_media
(id, post_id, url, ordering)
VALUES
('019691a2-c1b0-705e-8865-b5053bed9671', '019691a0-48ed-7eba-b8d3-608e25e07d4b', 'https://wallpaperaccess.com/full/1401569.jpg', 0),
('019691b5-bbfa-7481-ad74-25a6fea8db60', '019691a0-48ed-7eba-b8d3-608e25e07d4b', 'https://i.redd.it/4g8k43py9pi81.png', 1),
('019691b5-d813-7f46-87a5-8ee4e987622c', '019691a0-4ace-7bb5-a8f3-e3362920eba0', 'https://wallpapercave.com/wp/wp5305675.jpg', 0),
('019691b5-f345-7d86-9eba-2ca6780d8358', '019691a0-4c3e-726f-b8f6-bcbaabe789ae', 'https://wallpapers.com/images/hd/big-chungus-kpb89wgv5ov3znql.jpg', 0),
('019691b6-07cb-7353-8c33-68456188f462', '019691a0-4c3e-726f-b8f6-bcbaabe789ae', 'https://wallpapers.com/images/hd/big-chungus-2bxloyitgw7q1hfg.jpg', 1),
('019691b6-2608-7088-8110-f0f6e35fa633', '019691a0-4dd3-7e89-909e-94a6fd19a05e', 'https://www.pinclipart.com/picdir/big/535-5356059_big-transparent-chungus-png-background-big-chungus-clipart.png', 0)
;
INSERT INTO authn.user_identity
(id, username, password_hash, password_salt)
VALUES
(@id, @username, @passwordHash, @salt);
INSERT INTO authn.user_role
(user_id, role)
VALUES
(@id, 1);
INSERT INTO authn.signup_code
(code, recipient_email, recipient_name, expires_at, redeeming_user_id)
VALUES
('fickli', 'me@johnbotr.is', 'john', null, null);
"""
);
addToHistoryCommand.Parameters.AddWithValue("@id", id);
addToHistoryCommand.Parameters.AddWithValue("@username", username);
addToHistoryCommand.Parameters.AddWithValue("@passwordHash", passwordHash);
addToHistoryCommand.Parameters.AddWithValue("@salt", salt);
await addToHistoryCommand.ExecuteNonQueryAsync();
}
}