Skip to content

Commit

Permalink
Refactor migrations and entities
Browse files Browse the repository at this point in the history
  • Loading branch information
si618 committed Mar 17, 2024
1 parent 0ff8a51 commit e517e57
Show file tree
Hide file tree
Showing 19 changed files with 934 additions and 86 deletions.
13 changes: 11 additions & 2 deletions Benchmarks.Core/Database/BenchmarkDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@
public class BenchmarkDbContext(DbContextOptions options) : DbContext(options)
{
public DbSet<ClusteredIndex> ClusteredIndexes { get; set; } = null!;
public DbSet<GuidPrimaryKey> GuidPrimaryKeys { get; set; } = null!;
public DbSet<HardDeleted> HardDeletes { get; set; } = null!;
public DbSet<NonClusteredIndex> NonClusteredIndexes { get; set; } = null!;
public DbSet<SimpleEntity> SimpleEntities { get; set; } = null!;
public DbSet<SoftDeleted> SoftDeletes { get; set; } = null!;

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ClusteredIndex>()
.HasKey(p => p.Id)
.IsClustered();

modelBuilder.Entity<GuidPrimaryKey>()
.HasKey(p => p.Id);

modelBuilder.Entity<HardDeleted>()
.HasKey(p => p.Id);

modelBuilder.Entity<NonClusteredIndex>()
.HasKey(p => p.Id)
.IsClustered(false);

modelBuilder.Entity<SimpleEntity>()
modelBuilder.Entity<SoftDeleted>()
.HasKey(p => p.Id);

}
}
2 changes: 1 addition & 1 deletion Benchmarks.Core/Database/BenchmarkDbContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static BenchmarkDbContext Create(DbServer server, string connectionString
return new SqlServerDbContext(sqlServerOptions.Options);

default:
throw new NotImplementedException();
throw new InvalidEnumArgumentException();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using System;

#nullable disable

namespace Benchmarks.Core.Database.Postgres.Migrations
{
/// <inheritdoc />
public partial class CurrentPostgres : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ClusteredIndexes",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Text = table.Column<string>(type: "text", nullable: false),
CreatedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
LongInteger = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ClusteredIndexes", x => x.Id);
});

migrationBuilder.CreateTable(
name: "GuidPrimaryKeys",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Text = table.Column<string>(type: "text", nullable: false),
CreatedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
LongInteger = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GuidPrimaryKeys", x => x.Id);
});

migrationBuilder.CreateTable(
name: "HardDeletes",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Text = table.Column<string>(type: "text", nullable: false),
CreatedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
LongInteger = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_HardDeletes", x => x.Id);
});

migrationBuilder.CreateTable(
name: "NonClusteredIndexes",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Text = table.Column<string>(type: "text", nullable: false),
CreatedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
LongInteger = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_NonClusteredIndexes", x => x.Id);
});

migrationBuilder.CreateTable(
name: "SoftDeletes",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false),
DeletedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
Text = table.Column<string>(type: "text", nullable: false),
CreatedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
LongInteger = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SoftDeletes", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ClusteredIndexes");

migrationBuilder.DropTable(
name: "GuidPrimaryKeys");

migrationBuilder.DropTable(
name: "HardDeletes");

migrationBuilder.DropTable(
name: "NonClusteredIndexes");

migrationBuilder.DropTable(
name: "SoftDeletes");
}
}
}
Loading

0 comments on commit e517e57

Please sign in to comment.