Migration works
This commit is contained in:
parent
05f09e57ff
commit
3ffd8d23a0
@ -120,6 +120,8 @@ namespace Api.DBAccess
|
|||||||
|
|
||||||
device1.ReferenceId = device.ReferenceId;
|
device1.ReferenceId = device.ReferenceId;
|
||||||
|
|
||||||
|
device1.Name = device.Name;
|
||||||
|
|
||||||
return await _context.SaveChangesAsync() == 1;
|
return await _context.SaveChangesAsync() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
132
backend/Api/Migrations/20250319124149_AddedSaltUserNameDevice.Designer.cs
generated
Normal file
132
backend/Api/Migrations/20250319124149_AddedSaltUserNameDevice.Designer.cs
generated
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Api;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Api.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DBContext))]
|
||||||
|
[Migration("20250319124149_AddedSaltUserNameDevice")]
|
||||||
|
partial class AddedSaltUserNameDevice
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
|
||||||
|
|
||||||
|
modelBuilder.Entity("Api.Models.Device", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("ReferenceId")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<double>("TempHigh")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("TempLow")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<int?>("UserId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("Devices");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Api.Models.TemperatureLogs", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Date")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int?>("DeviceId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<double>("TempHigh")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("TempLow")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.Property<double>("Temperature")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("DeviceId");
|
||||||
|
|
||||||
|
b.ToTable("TemperatureLogs");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Api.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Salt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("UserName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Api.Models.Device", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Api.Models.User", null)
|
||||||
|
.WithMany("Devices")
|
||||||
|
.HasForeignKey("UserId");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Api.Models.TemperatureLogs", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Api.Models.Device", null)
|
||||||
|
.WithMany("Logs")
|
||||||
|
.HasForeignKey("DeviceId");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Api.Models.Device", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Logs");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Api.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Devices");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Api.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddedSaltUserNameDevice : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "Salt",
|
||||||
|
table: "Users",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "Name",
|
||||||
|
table: "Devices",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Salt",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Name",
|
||||||
|
table: "Devices");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,12 +17,16 @@ namespace Api.Migrations
|
|||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
|
modelBuilder.HasAnnotation("ProductVersion", "9.0.3");
|
||||||
|
|
||||||
modelBuilder.Entity("Models.Device", b =>
|
modelBuilder.Entity("Api.Models.Device", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("ReferenceId")
|
b.Property<string>("ReferenceId")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
@ -42,7 +46,7 @@ namespace Api.Migrations
|
|||||||
b.ToTable("Devices");
|
b.ToTable("Devices");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Models.TemperatureLogs", b =>
|
modelBuilder.Entity("Api.Models.TemperatureLogs", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@ -70,7 +74,7 @@ namespace Api.Migrations
|
|||||||
b.ToTable("TemperatureLogs");
|
b.ToTable("TemperatureLogs");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Models.User", b =>
|
modelBuilder.Entity("Api.Models.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@ -84,6 +88,9 @@ namespace Api.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Salt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("UserName")
|
b.Property<string>("UserName")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
@ -93,26 +100,26 @@ namespace Api.Migrations
|
|||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Models.Device", b =>
|
modelBuilder.Entity("Api.Models.Device", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Models.User", null)
|
b.HasOne("Api.Models.User", null)
|
||||||
.WithMany("Devices")
|
.WithMany("Devices")
|
||||||
.HasForeignKey("UserId");
|
.HasForeignKey("UserId");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Models.TemperatureLogs", b =>
|
modelBuilder.Entity("Api.Models.TemperatureLogs", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Models.Device", null)
|
b.HasOne("Api.Models.Device", null)
|
||||||
.WithMany("Logs")
|
.WithMany("Logs")
|
||||||
.HasForeignKey("DeviceId");
|
.HasForeignKey("DeviceId");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Models.Device", b =>
|
modelBuilder.Entity("Api.Models.Device", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Logs");
|
b.Navigation("Logs");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Models.User", b =>
|
modelBuilder.Entity("Api.Models.User", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Devices");
|
b.Navigation("Devices");
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
public double TempHigh { get; set; }
|
public double TempHigh { get; set; }
|
||||||
|
|
||||||
public double TempLow { get; set; }
|
public double TempLow { get; set; }
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
|
|
||||||
public string Salt { get; set; }
|
public string? Salt { get; set; }
|
||||||
|
|
||||||
public List<Device>? Devices { get; set; }
|
public List<Device>? Devices { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,28 @@ using Api;
|
|||||||
using Microsoft.AspNetCore;
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
var app = WebHost.CreateDefaultBuilder(args)
|
class Program
|
||||||
.UseUrls("http://0.0.0.0:5000")
|
{
|
||||||
.UseStartup<Startup>()
|
public static void Main(string[] args)
|
||||||
.Build();
|
{
|
||||||
|
var app = CreateWebHostBuilder(args).Build();
|
||||||
|
|
||||||
await using var scope = app.Services.CreateAsyncScope();
|
RunMigrations(app);
|
||||||
await using var db = scope.ServiceProvider.GetService<DBContext>();
|
|
||||||
await db.Database.MigrateAsync();
|
app.Run();
|
||||||
|
}
|
||||||
|
// Calls the startup class and creates the webinterface
|
||||||
|
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||||
|
WebHost.CreateDefaultBuilder(args)
|
||||||
|
.UseUrls("0.0.0.0:5000")
|
||||||
|
.UseStartup<Startup>();
|
||||||
|
|
||||||
|
public static async void RunMigrations(IWebHost app)
|
||||||
|
{
|
||||||
|
await using var scope = app.Services.CreateAsyncScope();
|
||||||
|
await using var db = scope.ServiceProvider.GetService<DbContext>();
|
||||||
|
await db.Database.MigrateAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.Run();
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user