add sectors to laps table

This commit is contained in:
ntr committed 2023-08-29 20:18:34 +10:00
1 parent 5ddbe1cacf
commit c66c6654c5
7 files changed
+143 -131

No files matched your search

@@ -1,79 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace Server.Migrations
{
/// <inheritdoc />
public partial class Beginninging : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Laps",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Created = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
Time = table.Column<double>(type: "double precision", nullable: false),
Map = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Laps", x => x.Id);
});
migrationBuilder.CreateTable(
name: "PbDTO",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
Created = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Time = table.Column<double>(type: "double precision", nullable: false),
Map = table.Column<string>(type: "text", nullable: true),
Completions = table.Column<int>(type: "integer", nullable: false),
Position = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
});
migrationBuilder.InsertData(
table: "Laps",
columns: new[] { "Id", "Created", "Map", "Time", "UserId" },
values: new object[,]
{
{ new Guid("42ee5177-d287-4ea1-91ed-ddd1d596e81f"), new DateTimeOffset(new DateTime(2023, 8, 29, 6, 24, 56, 272, DateTimeKind.Unspecified).AddTicks(1375), new TimeSpan(0, 0, 0, 0, 0)), "sr_TestTrack", 128.0, new Guid("11111111-1111-1111-1111-111111111111") },
{ new Guid("69002b76-54e2-455f-99aa-2fdb7f11c130"), new DateTimeOffset(new DateTime(2023, 8, 29, 6, 24, 56, 272, DateTimeKind.Unspecified).AddTicks(1471), new TimeSpan(0, 0, 0, 0, 0)), "sr_TestTrack", 148.0, new Guid("33333333-3333-3333-3333-333333333333") },
{ new Guid("81eb5dcb-1dd4-483b-993e-e73e1b95c5ff"), new DateTimeOffset(new DateTime(2023, 8, 29, 6, 24, 56, 272, DateTimeKind.Unspecified).AddTicks(1459), new TimeSpan(0, 0, 0, 0, 0)), "sr_TestTrack", 132.0, new Guid("22222222-2222-2222-2222-222222222222") }
});
migrationBuilder.CreateIndex(
name: "IX_Laps_Map",
table: "Laps",
column: "Map");
migrationBuilder.CreateIndex(
name: "IX_Laps_UserId_Map",
table: "Laps",
columns: new[] { "UserId", "Map" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Laps");
migrationBuilder.DropTable(
name: "PbDTO");
}
}
}
@@ -1,5 +1,6 @@
// <auto-generated /> // <auto-generated />
using System; using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
@@ -12,8 +13,8 @@ using Server;
namespace Server.Migrations namespace Server.Migrations
{ {
[DbContext(typeof(SpaceRaceDbContext))] [DbContext(typeof(SpaceRaceDbContext))]
[Migration("20230829062456_Beginninging")] [Migration("20230829101729_InitSectors")]
partial class Beginninging partial class InitSectors
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -38,6 +39,10 @@ namespace Server.Migrations
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");
b.Property<List<double>>("Sectors")
.IsRequired()
.HasColumnType("double precision[]");
b.Property<double>("Time") b.Property<double>("Time")
.HasColumnType("double precision"); .HasColumnType("double precision");
@@ -56,25 +61,28 @@ namespace Server.Migrations
b.HasData( b.HasData(
new new
{ {
Id = new Guid("42ee5177-d287-4ea1-91ed-ddd1d596e81f"), Id = new Guid("589bfb11-59c1-4f7e-beef-973c301b8e08"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 6, 24, 56, 272, DateTimeKind.Unspecified).AddTicks(1375), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(467), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack", Map = "sr_TestTrack",
Sectors = new List<double> { 64.0, 24.0, 24.0 },
Time = 128.0, Time = 128.0,
UserId = new Guid("11111111-1111-1111-1111-111111111111") UserId = new Guid("11111111-1111-1111-1111-111111111111")
}, },
new new
{ {
Id = new Guid("81eb5dcb-1dd4-483b-993e-e73e1b95c5ff"), Id = new Guid("67bda0f2-ecf8-4521-ba21-08d252d9ce59"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 6, 24, 56, 272, DateTimeKind.Unspecified).AddTicks(1459), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(723), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack", Map = "sr_TestTrack",
Sectors = new List<double> { 64.0, 38.0, 24.0 },
Time = 132.0, Time = 132.0,
UserId = new Guid("22222222-2222-2222-2222-222222222222") UserId = new Guid("22222222-2222-2222-2222-222222222222")
}, },
new new
{ {
Id = new Guid("69002b76-54e2-455f-99aa-2fdb7f11c130"), Id = new Guid("678183de-9df4-4d98-9807-f288b54a7f3a"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 6, 24, 56, 272, DateTimeKind.Unspecified).AddTicks(1471), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(745), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack", Map = "sr_TestTrack",
Sectors = new List<double> { 64.0, 64.0, 24.0 },
Time = 148.0, Time = 148.0,
UserId = new Guid("33333333-3333-3333-3333-333333333333") UserId = new Guid("33333333-3333-3333-3333-333333333333")
}); });
@@ -97,13 +105,16 @@ namespace Server.Migrations
b.Property<int>("Position") b.Property<int>("Position")
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<List<double>>("Sectors")
.HasColumnType("double precision[]");
b.Property<double>("Time") b.Property<double>("Time")
.HasColumnType("double precision"); .HasColumnType("double precision");
b.Property<Guid>("UserId") b.Property<Guid>("UserId")
.HasColumnType("uuid"); .HasColumnType("uuid");
b.ToTable("PbDTO"); b.ToTable((string)null);
b.ToSqlQuery("WITH ranked AS (\n SELECT *, rank() OVER (ORDER BY \"Time\" ASC) AS \"Position\", COUNT(\"Id\") OVER () AS \"Completions\"\n FROM \"Laps\"\n)\n\nSELECT * FROM ranked"); b.ToSqlQuery("WITH ranked AS (\n SELECT *, rank() OVER (ORDER BY \"Time\" ASC) AS \"Position\", COUNT(\"Id\") OVER () AS \"Completions\"\n FROM \"Laps\"\n)\n\nSELECT * FROM ranked");
}); });
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace Server.Migrations
{
/// <inheritdoc />
public partial class InitSectors : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Laps",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
Created = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Time = table.Column<double>(type: "double precision", nullable: false),
Sectors = table.Column<List<double>>(type: "double precision[]", nullable: false),
Map = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Laps", x => x.Id);
});
migrationBuilder.InsertData(
table: "Laps",
columns: new[] { "Id", "Created", "Map", "Sectors", "Time", "UserId" },
values: new object[,]
{
{ new Guid("589bfb11-59c1-4f7e-beef-973c301b8e08"), new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(467), new TimeSpan(0, 0, 0, 0, 0)), "sr_TestTrack", new List<double> { 64.0, 24.0, 24.0 }, 128.0, new Guid("11111111-1111-1111-1111-111111111111") },
{ new Guid("678183de-9df4-4d98-9807-f288b54a7f3a"), new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(745), new TimeSpan(0, 0, 0, 0, 0)), "sr_TestTrack", new List<double> { 64.0, 64.0, 24.0 }, 148.0, new Guid("33333333-3333-3333-3333-333333333333") },
{ new Guid("67bda0f2-ecf8-4521-ba21-08d252d9ce59"), new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(723), new TimeSpan(0, 0, 0, 0, 0)), "sr_TestTrack", new List<double> { 64.0, 38.0, 24.0 }, 132.0, new Guid("22222222-2222-2222-2222-222222222222") }
});
migrationBuilder.CreateIndex(
name: "IX_Laps_Map",
table: "Laps",
column: "Map");
migrationBuilder.CreateIndex(
name: "IX_Laps_UserId_Map",
table: "Laps",
columns: new[] { "UserId", "Map" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Laps");
}
}
}
@@ -1,5 +1,6 @@
// <auto-generated /> // <auto-generated />
using System; using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
@@ -35,6 +36,10 @@ namespace Server.Migrations
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");
b.Property<List<double>>("Sectors")
.IsRequired()
.HasColumnType("double precision[]");
b.Property<double>("Time") b.Property<double>("Time")
.HasColumnType("double precision"); .HasColumnType("double precision");
@@ -53,25 +58,28 @@ namespace Server.Migrations
b.HasData( b.HasData(
new new
{ {
Id = new Guid("42ee5177-d287-4ea1-91ed-ddd1d596e81f"), Id = new Guid("589bfb11-59c1-4f7e-beef-973c301b8e08"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 6, 24, 56, 272, DateTimeKind.Unspecified).AddTicks(1375), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(467), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack", Map = "sr_TestTrack",
Sectors = new List<double> { 64.0, 24.0, 24.0 },
Time = 128.0, Time = 128.0,
UserId = new Guid("11111111-1111-1111-1111-111111111111") UserId = new Guid("11111111-1111-1111-1111-111111111111")
}, },
new new
{ {
Id = new Guid("81eb5dcb-1dd4-483b-993e-e73e1b95c5ff"), Id = new Guid("67bda0f2-ecf8-4521-ba21-08d252d9ce59"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 6, 24, 56, 272, DateTimeKind.Unspecified).AddTicks(1459), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(723), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack", Map = "sr_TestTrack",
Sectors = new List<double> { 64.0, 38.0, 24.0 },
Time = 132.0, Time = 132.0,
UserId = new Guid("22222222-2222-2222-2222-222222222222") UserId = new Guid("22222222-2222-2222-2222-222222222222")
}, },
new new
{ {
Id = new Guid("69002b76-54e2-455f-99aa-2fdb7f11c130"), Id = new Guid("678183de-9df4-4d98-9807-f288b54a7f3a"),
Created = new DateTimeOffset(new DateTime(2023, 8, 29, 6, 24, 56, 272, DateTimeKind.Unspecified).AddTicks(1471), new TimeSpan(0, 0, 0, 0, 0)), Created = new DateTimeOffset(new DateTime(2023, 8, 29, 10, 17, 29, 656, DateTimeKind.Unspecified).AddTicks(745), new TimeSpan(0, 0, 0, 0, 0)),
Map = "sr_TestTrack", Map = "sr_TestTrack",
Sectors = new List<double> { 64.0, 64.0, 24.0 },
Time = 148.0, Time = 148.0,
UserId = new Guid("33333333-3333-3333-3333-333333333333") UserId = new Guid("33333333-3333-3333-3333-333333333333")
}); });
@@ -94,13 +102,16 @@ namespace Server.Migrations
b.Property<int>("Position") b.Property<int>("Position")
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<List<double>>("Sectors")
.HasColumnType("double precision[]");
b.Property<double>("Time") b.Property<double>("Time")
.HasColumnType("double precision"); .HasColumnType("double precision");
b.Property<Guid>("UserId") b.Property<Guid>("UserId")
.HasColumnType("uuid"); .HasColumnType("uuid");
b.ToTable("PbDTO"); b.ToTable((string)null);
b.ToSqlQuery("WITH ranked AS (\n SELECT *, rank() OVER (ORDER BY \"Time\" ASC) AS \"Position\", COUNT(\"Id\") OVER () AS \"Completions\"\n FROM \"Laps\"\n)\n\nSELECT * FROM ranked"); b.ToSqlQuery("WITH ranked AS (\n SELECT *, rank() OVER (ORDER BY \"Time\" ASC) AS \"Position\", COUNT(\"Id\") OVER () AS \"Completions\"\n FROM \"Laps\"\n)\n\nSELECT * FROM ranked");
}); });
+9 -7
View File
@@ -7,15 +7,17 @@ namespace SpaceRace.Shared {
public Guid UserId { get; set; } public Guid UserId { get; set; }
public string Map { get; set; } public string Map { get; set; }
public double Time { get; set; } public double Time { get; set; }
public List<double> Sectors { get; set; }
} }
public class PbDTO { public class PbDTO {
public Guid Id { get; set; } public Guid Id { get; set; }
public Guid UserId { get; set; } public Guid UserId { get; set; }
public DateTimeOffset Created { get; set; } public DateTimeOffset Created { get; set; }
public double Time { get; set; } public double Time { get; set; }
public string Map { get; set; } public List<double> Sectors { get; set; }
public int Completions { get; set; } public string Map { get; set; }
public int Position { get; set; } public int Completions { get; set; }
public int Position { get; set; }
} }
} }
+21 -16
View File
@@ -15,29 +15,31 @@ public class SpaceRaceDbContext : DbContext {
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
new SpaceRaceInitialiser(modelBuilder).Seed(); new SpaceRaceInitialiser(modelBuilder).Seed();
modelBuilder.Entity<PbDTO>(pb => { var pbQuery = $$"""
var pbQuery = $$""" WITH ranked AS (
WITH ranked AS ( SELECT *, rank() OVER (ORDER BY "Time" ASC) AS "Position", COUNT("Id") OVER () AS "Completions"
SELECT *, rank() OVER (ORDER BY "Time" ASC) AS "Position", COUNT("Id") OVER () AS "Completions" FROM "Laps"
FROM "Laps" )
)
SELECT * FROM ranked SELECT * FROM ranked
"""; """;
pb.HasNoKey();
pb.ToSqlQuery(pbQuery); modelBuilder.Entity<PbDTO>()
}); .HasNoKey()
.ToSqlQuery(pbQuery)
.ToTable(null as string);
} }
} }
[Index(nameof(UserId), nameof(Map), IsUnique = true)] [Index(nameof(UserId), nameof(Map), IsUnique = true)]
[Index(nameof(Map))] [Index(nameof(Map))]
public class Lap { public class Lap {
public DateTimeOffset Created { get; set; } public Guid Id { get; set; }
public Guid Id { get; set; } public Guid UserId { get; set; }
public Guid UserId { get; set; } [Required] public DateTimeOffset Created { get; set; }
public double Time { get; set; } [Required] public double Time { get; set; }
[Required] public string Map { get; set; } [Required] public List<double> Sectors { get; set; }
[Required] public string Map { get; set; }
} }
class SpaceRaceInitialiser { class SpaceRaceInitialiser {
@@ -54,6 +56,7 @@ class SpaceRaceInitialiser {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
UserId = new Guid("11111111-1111-1111-1111-111111111111"), UserId = new Guid("11111111-1111-1111-1111-111111111111"),
Time = 128f, Time = 128f,
Sectors = new List<double> { 64f, 24f, 24f },
Map = "sr_TestTrack", Map = "sr_TestTrack",
}, },
new Lap { new Lap {
@@ -61,6 +64,7 @@ class SpaceRaceInitialiser {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
UserId = new Guid("22222222-2222-2222-2222-222222222222"), UserId = new Guid("22222222-2222-2222-2222-222222222222"),
Time = 132f, Time = 132f,
Sectors = new List<double> { 64f, 38f, 24f },
Map = "sr_TestTrack", Map = "sr_TestTrack",
}, },
new Lap { new Lap {
@@ -68,6 +72,7 @@ class SpaceRaceInitialiser {
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
UserId = new Guid("33333333-3333-3333-3333-333333333333"), UserId = new Guid("33333333-3333-3333-3333-333333333333"),
Time = 148f, Time = 148f,
Sectors = new List<double> { 64f, 64f, 24f },
Map = "sr_TestTrack", Map = "sr_TestTrack",
} }
); );
+13 -13
View File
@@ -4,17 +4,17 @@ services:
file: common.yaml file: common.yaml
service: pg service: pg
server: # server:
image: mcr.microsoft.com/dotnet/sdk:7.0 # image: mcr.microsoft.com/dotnet/sdk:7.0
depends_on: # depends_on:
- 'pg' # - 'pg'
ports: # ports:
- '40080:80' # - '40080:80'
environment: # environment:
CONNECTIONSTRINGS__SPACERACE: "Server=pg;Port=5432;Database=${POSTGRES_DB};User Id=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}" # CONNECTIONSTRINGS__SPACERACE: "Server=pg;Port=5432;Database=${POSTGRES_DB};User Id=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}"
DOTNET_WATCH_RESTART_ON_RUDE_EDIT: 1 # DOTNET_WATCH_RESTART_ON_RUDE_EDIT: 1
command: dotnet watch # command: dotnet watch
working_dir: "/Server" # working_dir: "/Server"
volumes: # volumes:
- "./Server:/Server" # - "./Server:/Server"