Added seed from config instead of code

This commit is contained in:
Richárd Kunkli 2020-10-31 15:57:19 +01:00
parent 853f05d63c
commit 1172d89484
14 changed files with 443 additions and 68 deletions

View File

@ -1,4 +1,7 @@
using Birdmap.API;
using Birdmap.DAL;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog;
@ -15,8 +18,14 @@ namespace Birdmap
try
{
logger.Debug("Main called...");
CreateHostBuilder(args).Build().Run();
logger.Debug("Building host...");
var host = CreateHostBuilder(args).Build();
logger.Debug("Seeding database...");
SeedDatabase(host);
logger.Debug("Running host...");
host.Run();
}
catch (Exception ex)
{
@ -41,5 +50,13 @@ namespace Birdmap
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
})
.UseNLog();
private static void SeedDatabase(IHost host)
{
using var scope = host.Services.CreateScope();
var dbInitializer = scope.ServiceProvider.GetRequiredService<DbInitializer>();
dbInitializer.Initialize();
}
}
}

View File

@ -1,4 +1,5 @@
using AutoMapper;
using Birdmap.API;
using Birdmap.API.Middlewares;
using Birdmap.BLL;
using Birdmap.DAL;

View File

@ -8,5 +8,23 @@
},
"AllowedHosts": "*",
"Secret": "7vj.3KW.hYE!}4u6",
"LocalDbConnectionString": "Data Source=DESKTOP-A6JQ6B5\\SQLEXPRESS;Initial Catalog=Birdmap;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
"LocalDbConnectionString": "Data Source=DESKTOP-A6JQ6B5\\SQLEXPRESS;Initial Catalog=Birdmap;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"Defaults": {
"Services": {
"Local Database": "https://localhost:44331/health",
"KMLabz Services": "https://birb.k8s.kmlabz.com/devices"
},
"Users": [
{
"Name": "admin",
"Password": "pass",
"Role": "Admin"
},
{
"Name": "user",
"Password": "pass",
"Role": "User"
}
]
}
}

View File

@ -0,0 +1,82 @@
using Birdmap.DAL.Entities;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using static Birdmap.Common.PasswordHelper;
namespace Birdmap.DAL
{
public class DbInitializer
{
private readonly BirdmapContext _context;
private readonly IConfiguration _configuration;
private readonly ILogger<DbInitializer> _logger;
public DbInitializer(BirdmapContext context, IConfiguration configuration, ILogger<DbInitializer> logger)
{
_context = context;
_configuration = configuration;
_logger = logger;
}
public void Initialize()
{
AddDefaultUsers();
AddDefaultServices();
}
private void AddDefaultServices()
{
_logger.LogInformation("Removing previously added default services...");
var alreadyAddedDefaultServices = _context.Services.Where(s => s.IsFromConfig);
_context.Services.RemoveRange(alreadyAddedDefaultServices);
_logger.LogInformation("Adding new default services...");
foreach (var service in _configuration.GetSection("Defaults:Services").GetChildren())
{
_context.Services.Add(new Service
{
Name = service.Key,
Uri = new Uri(service.Value),
IsFromConfig = true,
});
}
_context.SaveChanges();
}
private void AddDefaultUsers()
{
_logger.LogInformation("Removing previously added default users...");
var alreadyAddedDefaultUsers = _context.Users.Where(s => s.IsFromConfig);
_context.Users.RemoveRange(alreadyAddedDefaultUsers);
var users = _configuration.GetSection("Defaults:Users").GetChildren()
.Select(c => new
{
Name = c.GetValue<string>("Name"),
Password = c.GetValue<string>("Password"),
Role = Enum.Parse<Roles>(c.GetValue<string>("Role"))
});
_logger.LogInformation("Adding new default users...");
foreach (var user in users)
{
CreatePasswordHash(user.Password, out var hash, out var salt);
_context.Users.Add(new User
{
Name = user.Name,
PasswordHash = hash,
PasswordSalt = salt,
Role = user.Role,
IsFromConfig = true,
});
}
_context.SaveChanges();
}
}
}

View File

@ -15,19 +15,9 @@ namespace Birdmap.DAL.Entities.Configurations
.HasConversion(u => u.ToString(), u => new Uri(u))
.IsRequired();
builder.HasData(
new Service
{
Id = 1,
Name = "KMLabz services",
Uri = new Uri("https://birb.k8s.kmlabz.com/devices")
},
new Service
{
Id = 2,
Name = "Local Database",
Uri = new Uri("/health", UriKind.Relative)
});
builder.Property(s => s.IsFromConfig)
.HasDefaultValue(false)
.IsRequired();
}
}
}

View File

@ -1,6 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using static Birdmap.Common.PasswordHelper;
namespace Birdmap.DAL.Entities.Configurations
{
@ -23,25 +22,9 @@ namespace Birdmap.DAL.Entities.Configurations
builder.Property(u => u.Role)
.IsRequired();
CreatePasswordHash("pass", out var hash, out var salt);
builder.HasData(
new User
{
Id = 1,
Name = "admin",
PasswordHash = hash,
PasswordSalt = salt,
Role = Roles.Admin,
},
new User
{
Id = 2,
Name = "user",
PasswordHash = hash,
PasswordSalt = salt,
Role = Roles.User,
});
builder.Property(u => u.IsFromConfig)
.HasDefaultValue(false)
.IsRequired();
}
}
}

View File

@ -7,5 +7,7 @@ namespace Birdmap.DAL.Entities
public int Id { get; set; }
public string Name { get; set; }
public Uri Uri { get; set; }
public bool IsFromConfig { get; set; }
}
}

View File

@ -14,5 +14,7 @@
public byte[] PasswordSalt { get; set; }
public Roles Role { get; set; }
public bool IsFromConfig { get; set; }
}
}

View File

@ -0,0 +1,99 @@
// <auto-generated />
using System;
using Birdmap.DAL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Birdmap.DAL.Migrations
{
[DbContext(typeof(BirdmapContext))]
[Migration("20201031130431_RemovedServiceSeed")]
partial class RemovedServiceSeed
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.9")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Birdmap.DAL.Entities.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<bool>("IsFromConfig")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Uri")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Services");
});
modelBuilder.Entity("Birdmap.DAL.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<byte[]>("PasswordHash")
.IsRequired()
.HasColumnType("varbinary(max)");
b.Property<byte[]>("PasswordSalt")
.IsRequired()
.HasColumnType("varbinary(max)");
b.Property<int>("Role")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Users");
b.HasData(
new
{
Id = 1,
Name = "admin",
PasswordHash = new byte[] { 199, 171, 130, 140, 205, 64, 247, 225, 175, 173, 122, 115, 103, 75, 199, 52, 110, 6, 250, 217, 154, 54, 240, 42, 3, 235, 36, 247, 213, 195, 209, 45, 161, 149, 109, 240, 191, 73, 6, 222, 92, 173, 78, 160, 236, 108, 81, 151, 221, 151, 118, 74, 147, 210, 52, 93, 30, 121, 64, 45, 183, 14, 197, 48 },
PasswordSalt = new byte[] { 42, 203, 231, 146, 232, 253, 34, 97, 157, 190, 210, 214, 228, 134, 176, 104, 226, 45, 199, 167, 8, 244, 230, 73, 222, 203, 152, 158, 65, 237, 80, 34, 88, 138, 227, 34, 136, 218, 137, 164, 16, 10, 3, 67, 104, 199, 27, 100, 116, 169, 57, 12, 17, 2, 204, 87, 20, 218, 204, 228, 148, 219, 150, 34, 165, 57, 51, 245, 13, 208, 206, 131, 226, 200, 212, 147, 223, 97, 227, 152, 136, 131, 98, 72, 143, 9, 130, 214, 187, 102, 164, 92, 147, 34, 171, 149, 52, 12, 140, 213, 223, 85, 199, 63, 43, 70, 100, 240, 13, 150, 199, 7, 56, 14, 11, 38, 151, 115, 129, 20, 31, 193, 54, 69, 79, 244, 189, 211 },
Role = 1
},
new
{
Id = 2,
Name = "user",
PasswordHash = new byte[] { 199, 171, 130, 140, 205, 64, 247, 225, 175, 173, 122, 115, 103, 75, 199, 52, 110, 6, 250, 217, 154, 54, 240, 42, 3, 235, 36, 247, 213, 195, 209, 45, 161, 149, 109, 240, 191, 73, 6, 222, 92, 173, 78, 160, 236, 108, 81, 151, 221, 151, 118, 74, 147, 210, 52, 93, 30, 121, 64, 45, 183, 14, 197, 48 },
PasswordSalt = new byte[] { 42, 203, 231, 146, 232, 253, 34, 97, 157, 190, 210, 214, 228, 134, 176, 104, 226, 45, 199, 167, 8, 244, 230, 73, 222, 203, 152, 158, 65, 237, 80, 34, 88, 138, 227, 34, 136, 218, 137, 164, 16, 10, 3, 67, 104, 199, 27, 100, 116, 169, 57, 12, 17, 2, 204, 87, 20, 218, 204, 228, 148, 219, 150, 34, 165, 57, 51, 245, 13, 208, 206, 131, 226, 200, 212, 147, 223, 97, 227, 152, 136, 131, 98, 72, 143, 9, 130, 214, 187, 102, 164, 92, 147, 34, 171, 149, 52, 12, 140, 213, 223, 85, 199, 63, 43, 70, 100, 240, 13, 150, 199, 7, 56, 14, 11, 38, 151, 115, 129, 20, 31, 193, 54, 69, 79, 244, 189, 211 },
Role = 0
});
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,71 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Birdmap.DAL.Migrations
{
public partial class RemovedServiceSeed : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "Services",
keyColumn: "Id",
keyValue: 1);
migrationBuilder.DeleteData(
table: "Services",
keyColumn: "Id",
keyValue: 2);
migrationBuilder.AddColumn<bool>(
name: "IsFromConfig",
table: "Services",
nullable: false,
defaultValue: false);
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 1,
columns: new[] { "PasswordHash", "PasswordSalt" },
values: new object[] { new byte[] { 199, 171, 130, 140, 205, 64, 247, 225, 175, 173, 122, 115, 103, 75, 199, 52, 110, 6, 250, 217, 154, 54, 240, 42, 3, 235, 36, 247, 213, 195, 209, 45, 161, 149, 109, 240, 191, 73, 6, 222, 92, 173, 78, 160, 236, 108, 81, 151, 221, 151, 118, 74, 147, 210, 52, 93, 30, 121, 64, 45, 183, 14, 197, 48 }, new byte[] { 42, 203, 231, 146, 232, 253, 34, 97, 157, 190, 210, 214, 228, 134, 176, 104, 226, 45, 199, 167, 8, 244, 230, 73, 222, 203, 152, 158, 65, 237, 80, 34, 88, 138, 227, 34, 136, 218, 137, 164, 16, 10, 3, 67, 104, 199, 27, 100, 116, 169, 57, 12, 17, 2, 204, 87, 20, 218, 204, 228, 148, 219, 150, 34, 165, 57, 51, 245, 13, 208, 206, 131, 226, 200, 212, 147, 223, 97, 227, 152, 136, 131, 98, 72, 143, 9, 130, 214, 187, 102, 164, 92, 147, 34, 171, 149, 52, 12, 140, 213, 223, 85, 199, 63, 43, 70, 100, 240, 13, 150, 199, 7, 56, 14, 11, 38, 151, 115, 129, 20, 31, 193, 54, 69, 79, 244, 189, 211 } });
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 2,
columns: new[] { "PasswordHash", "PasswordSalt" },
values: new object[] { new byte[] { 199, 171, 130, 140, 205, 64, 247, 225, 175, 173, 122, 115, 103, 75, 199, 52, 110, 6, 250, 217, 154, 54, 240, 42, 3, 235, 36, 247, 213, 195, 209, 45, 161, 149, 109, 240, 191, 73, 6, 222, 92, 173, 78, 160, 236, 108, 81, 151, 221, 151, 118, 74, 147, 210, 52, 93, 30, 121, 64, 45, 183, 14, 197, 48 }, new byte[] { 42, 203, 231, 146, 232, 253, 34, 97, 157, 190, 210, 214, 228, 134, 176, 104, 226, 45, 199, 167, 8, 244, 230, 73, 222, 203, 152, 158, 65, 237, 80, 34, 88, 138, 227, 34, 136, 218, 137, 164, 16, 10, 3, 67, 104, 199, 27, 100, 116, 169, 57, 12, 17, 2, 204, 87, 20, 218, 204, 228, 148, 219, 150, 34, 165, 57, 51, 245, 13, 208, 206, 131, 226, 200, 212, 147, 223, 97, 227, 152, 136, 131, 98, 72, 143, 9, 130, 214, 187, 102, 164, 92, 147, 34, 171, 149, 52, 12, 140, 213, 223, 85, 199, 63, 43, 70, 100, 240, 13, 150, 199, 7, 56, 14, 11, 38, 151, 115, 129, 20, 31, 193, 54, 69, 79, 244, 189, 211 } });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsFromConfig",
table: "Services");
migrationBuilder.InsertData(
table: "Services",
columns: new[] { "Id", "Name", "Uri" },
values: new object[,]
{
{ 1, "KMLabz services", "https://birb.k8s.kmlabz.com/devices" },
{ 2, "Local Database", "/health" }
});
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 1,
columns: new[] { "PasswordHash", "PasswordSalt" },
values: new object[] { new byte[] { 39, 245, 218, 244, 76, 67, 218, 179, 59, 162, 232, 131, 226, 248, 3, 230, 80, 103, 100, 117, 82, 39, 78, 32, 162, 199, 30, 48, 27, 225, 221, 175, 254, 114, 202, 98, 247, 169, 246, 12, 56, 123, 114, 8, 116, 175, 184, 175, 208, 224, 115, 86, 214, 98, 150, 229, 198, 135, 60, 30, 201, 174, 64, 231 }, new byte[] { 218, 221, 155, 56, 172, 243, 205, 43, 182, 187, 43, 213, 186, 95, 254, 120, 72, 235, 231, 42, 232, 132, 40, 167, 249, 103, 233, 155, 17, 14, 239, 87, 115, 252, 135, 54, 61, 97, 201, 109, 158, 134, 102, 122, 63, 166, 29, 59, 139, 221, 196, 54, 133, 146, 78, 228, 134, 75, 115, 20, 31, 239, 15, 110, 228, 114, 208, 240, 25, 222, 17, 180, 13, 181, 148, 45, 143, 79, 26, 198, 151, 129, 52, 152, 36, 56, 45, 21, 83, 40, 234, 107, 70, 119, 66, 122, 92, 240, 85, 167, 101, 69, 233, 125, 29, 104, 69, 39, 253, 221, 19, 13, 66, 114, 17, 252, 0, 202, 161, 170, 115, 99, 246, 49, 237, 6, 211, 76 } });
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 2,
columns: new[] { "PasswordHash", "PasswordSalt" },
values: new object[] { new byte[] { 39, 245, 218, 244, 76, 67, 218, 179, 59, 162, 232, 131, 226, 248, 3, 230, 80, 103, 100, 117, 82, 39, 78, 32, 162, 199, 30, 48, 27, 225, 221, 175, 254, 114, 202, 98, 247, 169, 246, 12, 56, 123, 114, 8, 116, 175, 184, 175, 208, 224, 115, 86, 214, 98, 150, 229, 198, 135, 60, 30, 201, 174, 64, 231 }, new byte[] { 218, 221, 155, 56, 172, 243, 205, 43, 182, 187, 43, 213, 186, 95, 254, 120, 72, 235, 231, 42, 232, 132, 40, 167, 249, 103, 233, 155, 17, 14, 239, 87, 115, 252, 135, 54, 61, 97, 201, 109, 158, 134, 102, 122, 63, 166, 29, 59, 139, 221, 196, 54, 133, 146, 78, 228, 134, 75, 115, 20, 31, 239, 15, 110, 228, 114, 208, 240, 25, 222, 17, 180, 13, 181, 148, 45, 143, 79, 26, 198, 151, 129, 52, 152, 36, 56, 45, 21, 83, 40, 234, 107, 70, 119, 66, 122, 92, 240, 85, 167, 101, 69, 233, 125, 29, 104, 69, 39, 253, 221, 19, 13, 66, 114, 17, 252, 0, 202, 161, 170, 115, 99, 246, 49, 237, 6, 211, 76 } });
}
}
}

View File

@ -0,0 +1,86 @@
// <auto-generated />
using System;
using Birdmap.DAL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Birdmap.DAL.Migrations
{
[DbContext(typeof(BirdmapContext))]
[Migration("20201031145128_RemoveUserSeed")]
partial class RemoveUserSeed
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.9")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Birdmap.DAL.Entities.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<bool>("IsFromConfig")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Uri")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Services");
});
modelBuilder.Entity("Birdmap.DAL.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<bool>("IsFromConfig")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<byte[]>("PasswordHash")
.IsRequired()
.HasColumnType("varbinary(max)");
b.Property<byte[]>("PasswordSalt")
.IsRequired()
.HasColumnType("varbinary(max)");
b.Property<int>("Role")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,44 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Birdmap.DAL.Migrations
{
public partial class RemoveUserSeed : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "Users",
keyColumn: "Id",
keyValue: 1);
migrationBuilder.DeleteData(
table: "Users",
keyColumn: "Id",
keyValue: 2);
migrationBuilder.AddColumn<bool>(
name: "IsFromConfig",
table: "Users",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsFromConfig",
table: "Users");
migrationBuilder.InsertData(
table: "Users",
columns: new[] { "Id", "Name", "PasswordHash", "PasswordSalt", "Role" },
values: new object[] { 1, "admin", new byte[] { 199, 171, 130, 140, 205, 64, 247, 225, 175, 173, 122, 115, 103, 75, 199, 52, 110, 6, 250, 217, 154, 54, 240, 42, 3, 235, 36, 247, 213, 195, 209, 45, 161, 149, 109, 240, 191, 73, 6, 222, 92, 173, 78, 160, 236, 108, 81, 151, 221, 151, 118, 74, 147, 210, 52, 93, 30, 121, 64, 45, 183, 14, 197, 48 }, new byte[] { 42, 203, 231, 146, 232, 253, 34, 97, 157, 190, 210, 214, 228, 134, 176, 104, 226, 45, 199, 167, 8, 244, 230, 73, 222, 203, 152, 158, 65, 237, 80, 34, 88, 138, 227, 34, 136, 218, 137, 164, 16, 10, 3, 67, 104, 199, 27, 100, 116, 169, 57, 12, 17, 2, 204, 87, 20, 218, 204, 228, 148, 219, 150, 34, 165, 57, 51, 245, 13, 208, 206, 131, 226, 200, 212, 147, 223, 97, 227, 152, 136, 131, 98, 72, 143, 9, 130, 214, 187, 102, 164, 92, 147, 34, 171, 149, 52, 12, 140, 213, 223, 85, 199, 63, 43, 70, 100, 240, 13, 150, 199, 7, 56, 14, 11, 38, 151, 115, 129, 20, 31, 193, 54, 69, 79, 244, 189, 211 }, 1 });
migrationBuilder.InsertData(
table: "Users",
columns: new[] { "Id", "Name", "PasswordHash", "PasswordSalt", "Role" },
values: new object[] { 2, "user", new byte[] { 199, 171, 130, 140, 205, 64, 247, 225, 175, 173, 122, 115, 103, 75, 199, 52, 110, 6, 250, 217, 154, 54, 240, 42, 3, 235, 36, 247, 213, 195, 209, 45, 161, 149, 109, 240, 191, 73, 6, 222, 92, 173, 78, 160, 236, 108, 81, 151, 221, 151, 118, 74, 147, 210, 52, 93, 30, 121, 64, 45, 183, 14, 197, 48 }, new byte[] { 42, 203, 231, 146, 232, 253, 34, 97, 157, 190, 210, 214, 228, 134, 176, 104, 226, 45, 199, 167, 8, 244, 230, 73, 222, 203, 152, 158, 65, 237, 80, 34, 88, 138, 227, 34, 136, 218, 137, 164, 16, 10, 3, 67, 104, 199, 27, 100, 116, 169, 57, 12, 17, 2, 204, 87, 20, 218, 204, 228, 148, 219, 150, 34, 165, 57, 51, 245, 13, 208, 206, 131, 226, 200, 212, 147, 223, 97, 227, 152, 136, 131, 98, 72, 143, 9, 130, 214, 187, 102, 164, 92, 147, 34, 171, 149, 52, 12, 140, 213, 223, 85, 199, 63, 43, 70, 100, 240, 13, 150, 199, 7, 56, 14, 11, 38, 151, 115, 129, 20, 31, 193, 54, 69, 79, 244, 189, 211 }, 0 });
}
}
}

View File

@ -26,6 +26,11 @@ namespace Birdmap.DAL.Migrations
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<bool>("IsFromConfig")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -37,20 +42,6 @@ namespace Birdmap.DAL.Migrations
b.HasKey("Id");
b.ToTable("Services");
b.HasData(
new
{
Id = 1,
Name = "KMLabz services",
Uri = "https://birb.k8s.kmlabz.com/devices"
},
new
{
Id = 2,
Name = "Local Database",
Uri = "/health"
});
});
modelBuilder.Entity("Birdmap.DAL.Entities.User", b =>
@ -60,6 +51,11 @@ namespace Birdmap.DAL.Migrations
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<bool>("IsFromConfig")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(450)");
@ -81,24 +77,6 @@ namespace Birdmap.DAL.Migrations
.IsUnique();
b.ToTable("Users");
b.HasData(
new
{
Id = 1,
Name = "admin",
PasswordHash = new byte[] { 39, 245, 218, 244, 76, 67, 218, 179, 59, 162, 232, 131, 226, 248, 3, 230, 80, 103, 100, 117, 82, 39, 78, 32, 162, 199, 30, 48, 27, 225, 221, 175, 254, 114, 202, 98, 247, 169, 246, 12, 56, 123, 114, 8, 116, 175, 184, 175, 208, 224, 115, 86, 214, 98, 150, 229, 198, 135, 60, 30, 201, 174, 64, 231 },
PasswordSalt = new byte[] { 218, 221, 155, 56, 172, 243, 205, 43, 182, 187, 43, 213, 186, 95, 254, 120, 72, 235, 231, 42, 232, 132, 40, 167, 249, 103, 233, 155, 17, 14, 239, 87, 115, 252, 135, 54, 61, 97, 201, 109, 158, 134, 102, 122, 63, 166, 29, 59, 139, 221, 196, 54, 133, 146, 78, 228, 134, 75, 115, 20, 31, 239, 15, 110, 228, 114, 208, 240, 25, 222, 17, 180, 13, 181, 148, 45, 143, 79, 26, 198, 151, 129, 52, 152, 36, 56, 45, 21, 83, 40, 234, 107, 70, 119, 66, 122, 92, 240, 85, 167, 101, 69, 233, 125, 29, 104, 69, 39, 253, 221, 19, 13, 66, 114, 17, 252, 0, 202, 161, 170, 115, 99, 246, 49, 237, 6, 211, 76 },
Role = 1
},
new
{
Id = 2,
Name = "user",
PasswordHash = new byte[] { 39, 245, 218, 244, 76, 67, 218, 179, 59, 162, 232, 131, 226, 248, 3, 230, 80, 103, 100, 117, 82, 39, 78, 32, 162, 199, 30, 48, 27, 225, 221, 175, 254, 114, 202, 98, 247, 169, 246, 12, 56, 123, 114, 8, 116, 175, 184, 175, 208, 224, 115, 86, 214, 98, 150, 229, 198, 135, 60, 30, 201, 174, 64, 231 },
PasswordSalt = new byte[] { 218, 221, 155, 56, 172, 243, 205, 43, 182, 187, 43, 213, 186, 95, 254, 120, 72, 235, 231, 42, 232, 132, 40, 167, 249, 103, 233, 155, 17, 14, 239, 87, 115, 252, 135, 54, 61, 97, 201, 109, 158, 134, 102, 122, 63, 166, 29, 59, 139, 221, 196, 54, 133, 146, 78, 228, 134, 75, 115, 20, 31, 239, 15, 110, 228, 114, 208, 240, 25, 222, 17, 180, 13, 181, 148, 45, 143, 79, 26, 198, 151, 129, 52, 152, 36, 56, 45, 21, 83, 40, 234, 107, 70, 119, 66, 122, 92, 240, 85, 167, 101, 69, 233, 125, 29, 104, 69, 39, 253, 221, 19, 13, 66, 114, 17, 252, 0, 202, 161, 170, 115, 99, 246, 49, 237, 6, 211, 76 },
Role = 0
});
});
#pragma warning restore 612, 618
}

View File

@ -14,6 +14,8 @@ namespace Birdmap.DAL
services.AddHealthChecks()
.AddDbContextCheck<BirdmapContext>();
services.AddTransient<DbInitializer>();
return services;
}
}