Skip to content

Commit a8dcf22

Browse files
Merge pull request #12 from DilmurodDeveloper/users/DilmurodDeveloper/data-book-migrate
DATA: Model & Migrate Books
2 parents 2384e0b + 8a87e1a commit a8dcf22

File tree

8 files changed

+219
-0
lines changed

8 files changed

+219
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//-----------------------------------------------------------
2+
// Copyright (c) Coalition of Good-Hearted Engineers
3+
// Free To Use To Build Reliable Library Management Solutions
4+
//-----------------------------------------------------------
5+
6+
using LibraryManagement.Api.Models.Foundations.Books;
7+
using Microsoft.EntityFrameworkCore;
8+
9+
namespace LibraryManagement.Api.Brokers.Storages
10+
{
11+
public partial class StorageBroker
12+
{
13+
public DbSet<Book> Books { get; set; }
14+
}
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//-----------------------------------------------------------
2+
// Copyright (c) Coalition of Good-Hearted Engineers
3+
// Free To Use To Build Reliable Library Management Solutions
4+
//-----------------------------------------------------------
5+
6+
using EFxceptions;
7+
using Microsoft.EntityFrameworkCore;
8+
9+
namespace LibraryManagement.Api.Brokers.Storages
10+
{
11+
public partial class StorageBroker : EFxceptionsContext
12+
{
13+
private readonly IConfiguration configuration;
14+
15+
public StorageBroker(IConfiguration configuration)
16+
{
17+
this.configuration = configuration;
18+
this.Database.Migrate();
19+
}
20+
21+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
22+
{
23+
string connectionString =
24+
this.configuration.GetConnectionString(name: "DefaultConnection");
25+
26+
optionsBuilder.UseSqlServer(connectionString);
27+
}
28+
29+
public override void Dispose() { }
30+
}
31+
}

LibraryManagement.Api/LibraryManagement.Api.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<PackageReference Include="EFxceptions" Version="0.4.5" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.18">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.18" />
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.18">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
1020
<PackageReference Include="RESTFulSense" Version="3.2.0" />
1121
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
1222
</ItemGroup>

LibraryManagement.Api/Migrations/20250719192841_InitialCreateAllTables.Designer.cs

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace LibraryManagement.Api.Migrations
6+
{
7+
/// <inheritdoc />
8+
public partial class InitialCreateAllTables : Migration
9+
{
10+
/// <inheritdoc />
11+
protected override void Up(MigrationBuilder migrationBuilder)
12+
{
13+
migrationBuilder.CreateTable(
14+
name: "Books",
15+
columns: table => new
16+
{
17+
BookId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
18+
ReaderId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
19+
BookTitle = table.Column<string>(type: "nvarchar(max)", nullable: false),
20+
Author = table.Column<string>(type: "nvarchar(max)", nullable: false),
21+
Genre = table.Column<string>(type: "nvarchar(max)", nullable: false)
22+
},
23+
constraints: table =>
24+
{
25+
table.PrimaryKey("PK_Books", x => x.BookId);
26+
});
27+
}
28+
29+
/// <inheritdoc />
30+
protected override void Down(MigrationBuilder migrationBuilder)
31+
{
32+
migrationBuilder.DropTable(
33+
name: "Books");
34+
}
35+
}
36+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// <auto-generated />
2+
using System;
3+
using LibraryManagement.Api.Brokers.Storages;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Infrastructure;
6+
using Microsoft.EntityFrameworkCore.Metadata;
7+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8+
9+
#nullable disable
10+
11+
namespace LibraryManagement.Api.Migrations
12+
{
13+
[DbContext(typeof(StorageBroker))]
14+
partial class StorageBrokerModelSnapshot : ModelSnapshot
15+
{
16+
protected override void BuildModel(ModelBuilder modelBuilder)
17+
{
18+
#pragma warning disable 612, 618
19+
modelBuilder
20+
.HasAnnotation("ProductVersion", "8.0.18")
21+
.HasAnnotation("Relational:MaxIdentifierLength", 128);
22+
23+
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
24+
25+
modelBuilder.Entity("LibraryManagement.Api.Models.Foundations.Books.Book", b =>
26+
{
27+
b.Property<Guid>("BookId")
28+
.ValueGeneratedOnAdd()
29+
.HasColumnType("uniqueidentifier");
30+
31+
b.Property<string>("Author")
32+
.IsRequired()
33+
.HasColumnType("nvarchar(max)");
34+
35+
b.Property<string>("BookTitle")
36+
.IsRequired()
37+
.HasColumnType("nvarchar(max)");
38+
39+
b.Property<string>("Genre")
40+
.IsRequired()
41+
.HasColumnType("nvarchar(max)");
42+
43+
b.Property<Guid>("ReaderId")
44+
.HasColumnType("uniqueidentifier");
45+
46+
b.HasKey("BookId");
47+
48+
b.ToTable("Books");
49+
});
50+
#pragma warning restore 612, 618
51+
}
52+
}
53+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//-----------------------------------------------------------
2+
// Copyright (c) Coalition of Good-Hearted Engineers
3+
// Free To Use To Build Reliable Library Management Solutions
4+
//-----------------------------------------------------------
5+
6+
namespace LibraryManagement.Api.Models.Foundations.Books
7+
{
8+
public class Book
9+
{
10+
public Guid BookId { get; set; }
11+
public Guid ReaderId { get; set; }
12+
public string BookTitle { get; set; }
13+
public string Author { get; set; }
14+
public string Genre { get; set; }
15+
}
16+
}

LibraryManagement.Api/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Free To Use To Build Reliable Library Management Solutions
44
//-----------------------------------------------------------
55

6+
using LibraryManagement.Api.Brokers.Storages;
67
using Microsoft.OpenApi.Models;
78

89
var builder = WebApplication.CreateBuilder(args);
@@ -13,6 +14,7 @@
1314
Version = "v1"
1415
};
1516

17+
builder.Services.AddDbContext<StorageBroker>();
1618
builder.Services.AddControllers();
1719
builder.Services.AddEndpointsApiExplorer();
1820

0 commit comments

Comments
 (0)