From 3e66983042eb53a7c9392fbe2ae1bf0d4a12fa07 Mon Sep 17 00:00:00 2001 From: Erman Date: Wed, 9 Sep 2026 04:07:24 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=20SQLite=20+=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BC?= =?UTF-8?q?=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + DEMO/DEMO.csproj | 2 +- DEMO/Data/AppDbContextFactory.cs | 7 +- .../20260908211451_InitialCreate.Designer.cs | 46 ---- .../20260908211451_InitialCreate.cs | 34 --- .../20260908211931_AddProducts.Designer.cs | 82 ------ DEMO/Migrations/20260908211931_AddProducts.cs | 47 ---- .../20260908215804_AddWarehouses.Designer.cs | 103 -------- .../20260908215804_AddWarehouses.cs | 35 --- .../20260908220130_AddStock.Designer.cs | 148 ----------- DEMO/Migrations/20260908220130_AddStock.cs | 58 ----- ...0260908220723_AddUsersAndRoles.Designer.cs | 207 --------------- .../20260908220723_AddUsersAndRoles.cs | 63 ----- .../20260908221344_AddOrders.Designer.cs | 239 ------------------ DEMO/Migrations/20260908221344_AddOrders.cs | 48 ---- .../20260908221738_AddOrderItems.cs | 59 ----- ... 20260908230647_InitialCreate.Designer.cs} | 83 +++--- .../20260908230647_InitialCreate.cs | 236 +++++++++++++++++ DEMO/Migrations/AppDbContextModelSnapshot.cs | 79 +++--- DEMO/Program.cs | 11 +- DEMO/appsettings.json | 2 +- 21 files changed, 312 insertions(+), 1279 deletions(-) delete mode 100644 DEMO/Migrations/20260908211451_InitialCreate.Designer.cs delete mode 100644 DEMO/Migrations/20260908211451_InitialCreate.cs delete mode 100644 DEMO/Migrations/20260908211931_AddProducts.Designer.cs delete mode 100644 DEMO/Migrations/20260908211931_AddProducts.cs delete mode 100644 DEMO/Migrations/20260908215804_AddWarehouses.Designer.cs delete mode 100644 DEMO/Migrations/20260908215804_AddWarehouses.cs delete mode 100644 DEMO/Migrations/20260908220130_AddStock.Designer.cs delete mode 100644 DEMO/Migrations/20260908220130_AddStock.cs delete mode 100644 DEMO/Migrations/20260908220723_AddUsersAndRoles.Designer.cs delete mode 100644 DEMO/Migrations/20260908220723_AddUsersAndRoles.cs delete mode 100644 DEMO/Migrations/20260908221344_AddOrders.Designer.cs delete mode 100644 DEMO/Migrations/20260908221344_AddOrders.cs delete mode 100644 DEMO/Migrations/20260908221738_AddOrderItems.cs rename DEMO/Migrations/{20260908221738_AddOrderItems.Designer.cs => 20260908230647_InitialCreate.Designer.cs} (72%) create mode 100644 DEMO/Migrations/20260908230647_InitialCreate.cs diff --git a/.gitignore b/.gitignore index e707d33..4e56230 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ obj/ # юзерские настройки *.user *.suo +# файл базы sqlite (создается сам) +*.db diff --git a/DEMO/DEMO.csproj b/DEMO/DEMO.csproj index 021abc7..eded5be 100644 --- a/DEMO/DEMO.csproj +++ b/DEMO/DEMO.csproj @@ -12,7 +12,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/DEMO/Data/AppDbContextFactory.cs b/DEMO/Data/AppDbContextFactory.cs index c1497cd..2420a8e 100644 --- a/DEMO/Data/AppDbContextFactory.cs +++ b/DEMO/Data/AppDbContextFactory.cs @@ -6,14 +6,13 @@ namespace DEMO.Data; public class AppDbContextFactory : IDesignTimeDbContextFactory // фабрика для создания базы { - // создаю базу с моей строкой подключения + // создаю базу (простой файл sqlite) public AppDbContext CreateDbContext(string[] args) { var optionsBuilder = new DbContextOptionsBuilder(); // настройки - // говорю где лежит база (у меня на компе) - optionsBuilder.UseSqlServer( - "Server=(localdb)\\MSSQLLocalDB;Database=DemoDB;Trusted_Connection=True;TrustServerCertificate=True;"); + // файл базы лежит рядом + optionsBuilder.UseSqlite("Data Source=DemoDB.db"); return new AppDbContext(optionsBuilder.Options); // отдаю готовую базу } diff --git a/DEMO/Migrations/20260908211451_InitialCreate.Designer.cs b/DEMO/Migrations/20260908211451_InitialCreate.Designer.cs deleted file mode 100644 index 2de8e6e..0000000 --- a/DEMO/Migrations/20260908211451_InitialCreate.Designer.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -using DEMO.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace DEMO.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260908211451_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.12") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("DEMO.Models.Category", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Categories"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/DEMO/Migrations/20260908211451_InitialCreate.cs b/DEMO/Migrations/20260908211451_InitialCreate.cs deleted file mode 100644 index 108adad..0000000 --- a/DEMO/Migrations/20260908211451_InitialCreate.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DEMO.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Categories", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Categories", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Categories"); - } - } -} diff --git a/DEMO/Migrations/20260908211931_AddProducts.Designer.cs b/DEMO/Migrations/20260908211931_AddProducts.Designer.cs deleted file mode 100644 index d093e1e..0000000 --- a/DEMO/Migrations/20260908211931_AddProducts.Designer.cs +++ /dev/null @@ -1,82 +0,0 @@ -// -using DEMO.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace DEMO.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260908211931_AddProducts")] - partial class AddProducts - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.12") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("DEMO.Models.Category", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Categories"); - }); - - modelBuilder.Entity("DEMO.Models.Product", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CategoryId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("decimal(18,2)"); - - b.HasKey("Id"); - - b.HasIndex("CategoryId"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("DEMO.Models.Product", b => - { - b.HasOne("DEMO.Models.Category", "Category") - .WithMany() - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Category"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/DEMO/Migrations/20260908211931_AddProducts.cs b/DEMO/Migrations/20260908211931_AddProducts.cs deleted file mode 100644 index 3938e69..0000000 --- a/DEMO/Migrations/20260908211931_AddProducts.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DEMO.Migrations -{ - /// - public partial class AddProducts : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Products", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "decimal(18,2)", nullable: false), - CategoryId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Products", x => x.Id); - table.ForeignKey( - name: "FK_Products_Categories_CategoryId", - column: x => x.CategoryId, - principalTable: "Categories", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Products_CategoryId", - table: "Products", - column: "CategoryId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Products"); - } - } -} diff --git a/DEMO/Migrations/20260908215804_AddWarehouses.Designer.cs b/DEMO/Migrations/20260908215804_AddWarehouses.Designer.cs deleted file mode 100644 index 217cc78..0000000 --- a/DEMO/Migrations/20260908215804_AddWarehouses.Designer.cs +++ /dev/null @@ -1,103 +0,0 @@ -// -using DEMO.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace DEMO.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260908215804_AddWarehouses")] - partial class AddWarehouses - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.12") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("DEMO.Models.Category", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Categories"); - }); - - modelBuilder.Entity("DEMO.Models.Product", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CategoryId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("decimal(18,2)"); - - b.HasKey("Id"); - - b.HasIndex("CategoryId"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("DEMO.Models.Warehouse", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Warehouses"); - }); - - modelBuilder.Entity("DEMO.Models.Product", b => - { - b.HasOne("DEMO.Models.Category", "Category") - .WithMany() - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Category"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/DEMO/Migrations/20260908215804_AddWarehouses.cs b/DEMO/Migrations/20260908215804_AddWarehouses.cs deleted file mode 100644 index 5e0ba32..0000000 --- a/DEMO/Migrations/20260908215804_AddWarehouses.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DEMO.Migrations -{ - /// - public partial class AddWarehouses : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Warehouses", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(type: "nvarchar(max)", nullable: false), - Address = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Warehouses", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Warehouses"); - } - } -} diff --git a/DEMO/Migrations/20260908220130_AddStock.Designer.cs b/DEMO/Migrations/20260908220130_AddStock.Designer.cs deleted file mode 100644 index da4e3dd..0000000 --- a/DEMO/Migrations/20260908220130_AddStock.Designer.cs +++ /dev/null @@ -1,148 +0,0 @@ -// -using DEMO.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace DEMO.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260908220130_AddStock")] - partial class AddStock - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.12") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("DEMO.Models.Category", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Categories"); - }); - - modelBuilder.Entity("DEMO.Models.Product", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CategoryId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("decimal(18,2)"); - - b.HasKey("Id"); - - b.HasIndex("CategoryId"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("DEMO.Models.Stock", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ProductId") - .HasColumnType("int"); - - b.Property("Quantity") - .HasColumnType("int"); - - b.Property("WarehouseId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ProductId"); - - b.HasIndex("WarehouseId"); - - b.ToTable("Stocks"); - }); - - modelBuilder.Entity("DEMO.Models.Warehouse", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Warehouses"); - }); - - modelBuilder.Entity("DEMO.Models.Product", b => - { - b.HasOne("DEMO.Models.Category", "Category") - .WithMany() - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Category"); - }); - - modelBuilder.Entity("DEMO.Models.Stock", b => - { - b.HasOne("DEMO.Models.Product", "Product") - .WithMany() - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DEMO.Models.Warehouse", "Warehouse") - .WithMany() - .HasForeignKey("WarehouseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Product"); - - b.Navigation("Warehouse"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/DEMO/Migrations/20260908220130_AddStock.cs b/DEMO/Migrations/20260908220130_AddStock.cs deleted file mode 100644 index f266ed4..0000000 --- a/DEMO/Migrations/20260908220130_AddStock.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DEMO.Migrations -{ - /// - public partial class AddStock : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Stocks", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ProductId = table.Column(type: "int", nullable: false), - WarehouseId = table.Column(type: "int", nullable: false), - Quantity = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Stocks", x => x.Id); - table.ForeignKey( - name: "FK_Stocks_Products_ProductId", - column: x => x.ProductId, - principalTable: "Products", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Stocks_Warehouses_WarehouseId", - column: x => x.WarehouseId, - principalTable: "Warehouses", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Stocks_ProductId", - table: "Stocks", - column: "ProductId"); - - migrationBuilder.CreateIndex( - name: "IX_Stocks_WarehouseId", - table: "Stocks", - column: "WarehouseId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Stocks"); - } - } -} diff --git a/DEMO/Migrations/20260908220723_AddUsersAndRoles.Designer.cs b/DEMO/Migrations/20260908220723_AddUsersAndRoles.Designer.cs deleted file mode 100644 index 31e077f..0000000 --- a/DEMO/Migrations/20260908220723_AddUsersAndRoles.Designer.cs +++ /dev/null @@ -1,207 +0,0 @@ -// -using DEMO.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace DEMO.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260908220723_AddUsersAndRoles")] - partial class AddUsersAndRoles - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.12") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("DEMO.Models.Category", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Categories"); - }); - - modelBuilder.Entity("DEMO.Models.Product", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CategoryId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("decimal(18,2)"); - - b.HasKey("Id"); - - b.HasIndex("CategoryId"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("DEMO.Models.Role", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Roles"); - }); - - modelBuilder.Entity("DEMO.Models.Stock", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ProductId") - .HasColumnType("int"); - - b.Property("Quantity") - .HasColumnType("int"); - - b.Property("WarehouseId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ProductId"); - - b.HasIndex("WarehouseId"); - - b.ToTable("Stocks"); - }); - - modelBuilder.Entity("DEMO.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Login") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("RoleId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("DEMO.Models.Warehouse", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Warehouses"); - }); - - modelBuilder.Entity("DEMO.Models.Product", b => - { - b.HasOne("DEMO.Models.Category", "Category") - .WithMany() - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Category"); - }); - - modelBuilder.Entity("DEMO.Models.Stock", b => - { - b.HasOne("DEMO.Models.Product", "Product") - .WithMany() - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DEMO.Models.Warehouse", "Warehouse") - .WithMany() - .HasForeignKey("WarehouseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Product"); - - b.Navigation("Warehouse"); - }); - - modelBuilder.Entity("DEMO.Models.User", b => - { - b.HasOne("DEMO.Models.Role", "Role") - .WithMany("Users") - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Role"); - }); - - modelBuilder.Entity("DEMO.Models.Role", b => - { - b.Navigation("Users"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/DEMO/Migrations/20260908220723_AddUsersAndRoles.cs b/DEMO/Migrations/20260908220723_AddUsersAndRoles.cs deleted file mode 100644 index 2358d8d..0000000 --- a/DEMO/Migrations/20260908220723_AddUsersAndRoles.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DEMO.Migrations -{ - /// - public partial class AddUsersAndRoles : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Roles", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Roles", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Users", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Login = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false), - RoleId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.Id); - table.ForeignKey( - name: "FK_Users_Roles_RoleId", - column: x => x.RoleId, - principalTable: "Roles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Users_RoleId", - table: "Users", - column: "RoleId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Users"); - - migrationBuilder.DropTable( - name: "Roles"); - } - } -} diff --git a/DEMO/Migrations/20260908221344_AddOrders.Designer.cs b/DEMO/Migrations/20260908221344_AddOrders.Designer.cs deleted file mode 100644 index 6765868..0000000 --- a/DEMO/Migrations/20260908221344_AddOrders.Designer.cs +++ /dev/null @@ -1,239 +0,0 @@ -// -using System; -using DEMO.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace DEMO.Migrations -{ - [DbContext(typeof(AppDbContext))] - [Migration("20260908221344_AddOrders")] - partial class AddOrders - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.12") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("DEMO.Models.Category", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Categories"); - }); - - modelBuilder.Entity("DEMO.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Date") - .HasColumnType("datetime2"); - - b.Property("Status") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("DEMO.Models.Product", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CategoryId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("decimal(18,2)"); - - b.HasKey("Id"); - - b.HasIndex("CategoryId"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("DEMO.Models.Role", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Roles"); - }); - - modelBuilder.Entity("DEMO.Models.Stock", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ProductId") - .HasColumnType("int"); - - b.Property("Quantity") - .HasColumnType("int"); - - b.Property("WarehouseId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ProductId"); - - b.HasIndex("WarehouseId"); - - b.ToTable("Stocks"); - }); - - modelBuilder.Entity("DEMO.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Login") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("RoleId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("DEMO.Models.Warehouse", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Warehouses"); - }); - - modelBuilder.Entity("DEMO.Models.Order", b => - { - b.HasOne("DEMO.Models.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("DEMO.Models.Product", b => - { - b.HasOne("DEMO.Models.Category", "Category") - .WithMany() - .HasForeignKey("CategoryId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Category"); - }); - - modelBuilder.Entity("DEMO.Models.Stock", b => - { - b.HasOne("DEMO.Models.Product", "Product") - .WithMany() - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DEMO.Models.Warehouse", "Warehouse") - .WithMany() - .HasForeignKey("WarehouseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Product"); - - b.Navigation("Warehouse"); - }); - - modelBuilder.Entity("DEMO.Models.User", b => - { - b.HasOne("DEMO.Models.Role", "Role") - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Role"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/DEMO/Migrations/20260908221344_AddOrders.cs b/DEMO/Migrations/20260908221344_AddOrders.cs deleted file mode 100644 index d98c2af..0000000 --- a/DEMO/Migrations/20260908221344_AddOrders.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DEMO.Migrations -{ - /// - public partial class AddOrders : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - UserId = table.Column(type: "int", nullable: false), - Date = table.Column(type: "datetime2", nullable: false), - Status = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_UserId", - table: "Orders", - column: "UserId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Orders"); - } - } -} diff --git a/DEMO/Migrations/20260908221738_AddOrderItems.cs b/DEMO/Migrations/20260908221738_AddOrderItems.cs deleted file mode 100644 index 858a30b..0000000 --- a/DEMO/Migrations/20260908221738_AddOrderItems.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace DEMO.Migrations -{ - /// - public partial class AddOrderItems : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "OrderItems", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - OrderId = table.Column(type: "int", nullable: false), - ProductId = table.Column(type: "int", nullable: false), - Quantity = table.Column(type: "int", nullable: false), - Price = table.Column(type: "decimal(18,2)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OrderItems", x => x.Id); - table.ForeignKey( - name: "FK_OrderItems_Orders_OrderId", - column: x => x.OrderId, - principalTable: "Orders", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_OrderItems_Products_ProductId", - column: x => x.ProductId, - principalTable: "Products", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_OrderItems_OrderId", - table: "OrderItems", - column: "OrderId"); - - migrationBuilder.CreateIndex( - name: "IX_OrderItems_ProductId", - table: "OrderItems", - column: "ProductId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "OrderItems"); - } - } -} diff --git a/DEMO/Migrations/20260908221738_AddOrderItems.Designer.cs b/DEMO/Migrations/20260908230647_InitialCreate.Designer.cs similarity index 72% rename from DEMO/Migrations/20260908221738_AddOrderItems.Designer.cs rename to DEMO/Migrations/20260908230647_InitialCreate.Designer.cs index f60e3ca..b3fc497 100644 --- a/DEMO/Migrations/20260908221738_AddOrderItems.Designer.cs +++ b/DEMO/Migrations/20260908230647_InitialCreate.Designer.cs @@ -3,7 +3,6 @@ using System; using DEMO.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -12,30 +11,24 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace DEMO.Migrations { [DbContext(typeof(AppDbContext))] - [Migration("20260908221738_AddOrderItems")] - partial class AddOrderItems + [Migration("20260908230647_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.12") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.HasAnnotation("ProductVersion", "10.0.12"); modelBuilder.Entity("DEMO.Models.Category", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("Name") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -46,19 +39,17 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("Date") - .HasColumnType("datetime2"); + .HasColumnType("TEXT"); b.Property("Status") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.Property("UserId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.HasKey("Id"); @@ -71,21 +62,19 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("OrderId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Price") - .HasColumnType("decimal(18,2)"); + .HasColumnType("TEXT"); b.Property("ProductId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Quantity") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.HasKey("Id"); @@ -100,19 +89,17 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("CategoryId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Name") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.Property("Price") - .HasColumnType("decimal(18,2)"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -125,13 +112,11 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("Name") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -142,18 +127,16 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("ProductId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Quantity") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("WarehouseId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.HasKey("Id"); @@ -168,20 +151,18 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("Login") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.Property("Password") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.Property("RoleId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.HasKey("Id"); @@ -194,17 +175,15 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("Address") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.Property("Name") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.HasKey("Id"); diff --git a/DEMO/Migrations/20260908230647_InitialCreate.cs b/DEMO/Migrations/20260908230647_InitialCreate.cs new file mode 100644 index 0000000..b494f5b --- /dev/null +++ b/DEMO/Migrations/20260908230647_InitialCreate.cs @@ -0,0 +1,236 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DEMO.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Categories", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Categories", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Roles", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Roles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Warehouses", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Address = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Warehouses", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Products", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Price = table.Column(type: "TEXT", nullable: false), + CategoryId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Products", x => x.Id); + table.ForeignKey( + name: "FK_Products_Categories_CategoryId", + column: x => x.CategoryId, + principalTable: "Categories", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Login = table.Column(type: "TEXT", nullable: false), + Password = table.Column(type: "TEXT", nullable: false), + RoleId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + table.ForeignKey( + name: "FK_Users_Roles_RoleId", + column: x => x.RoleId, + principalTable: "Roles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Stocks", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ProductId = table.Column(type: "INTEGER", nullable: false), + WarehouseId = table.Column(type: "INTEGER", nullable: false), + Quantity = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Stocks", x => x.Id); + table.ForeignKey( + name: "FK_Stocks_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Stocks_Warehouses_WarehouseId", + column: x => x.WarehouseId, + principalTable: "Warehouses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(type: "INTEGER", nullable: false), + Date = table.Column(type: "TEXT", nullable: false), + Status = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "OrderItems", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + OrderId = table.Column(type: "INTEGER", nullable: false), + ProductId = table.Column(type: "INTEGER", nullable: false), + Quantity = table.Column(type: "INTEGER", nullable: false), + Price = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OrderItems", x => x.Id); + table.ForeignKey( + name: "FK_OrderItems_Orders_OrderId", + column: x => x.OrderId, + principalTable: "Orders", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_OrderItems_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_OrderItems_OrderId", + table: "OrderItems", + column: "OrderId"); + + migrationBuilder.CreateIndex( + name: "IX_OrderItems_ProductId", + table: "OrderItems", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_UserId", + table: "Orders", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Products_CategoryId", + table: "Products", + column: "CategoryId"); + + migrationBuilder.CreateIndex( + name: "IX_Stocks_ProductId", + table: "Stocks", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_Stocks_WarehouseId", + table: "Stocks", + column: "WarehouseId"); + + migrationBuilder.CreateIndex( + name: "IX_Users_RoleId", + table: "Users", + column: "RoleId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "OrderItems"); + + migrationBuilder.DropTable( + name: "Stocks"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Products"); + + migrationBuilder.DropTable( + name: "Warehouses"); + + migrationBuilder.DropTable( + name: "Users"); + + migrationBuilder.DropTable( + name: "Categories"); + + migrationBuilder.DropTable( + name: "Roles"); + } + } +} diff --git a/DEMO/Migrations/AppDbContextModelSnapshot.cs b/DEMO/Migrations/AppDbContextModelSnapshot.cs index 1c3243c..7824653 100644 --- a/DEMO/Migrations/AppDbContextModelSnapshot.cs +++ b/DEMO/Migrations/AppDbContextModelSnapshot.cs @@ -3,7 +3,6 @@ using System; using DEMO.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable @@ -16,23 +15,17 @@ namespace DEMO.Migrations protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.12") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.HasAnnotation("ProductVersion", "10.0.12"); modelBuilder.Entity("DEMO.Models.Category", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("Name") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -43,19 +36,17 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("Date") - .HasColumnType("datetime2"); + .HasColumnType("TEXT"); b.Property("Status") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.Property("UserId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.HasKey("Id"); @@ -68,21 +59,19 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("OrderId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Price") - .HasColumnType("decimal(18,2)"); + .HasColumnType("TEXT"); b.Property("ProductId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Quantity") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.HasKey("Id"); @@ -97,19 +86,17 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("CategoryId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Name") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.Property("Price") - .HasColumnType("decimal(18,2)"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -122,13 +109,11 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("Name") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.HasKey("Id"); @@ -139,18 +124,16 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("ProductId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("Quantity") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.Property("WarehouseId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.HasKey("Id"); @@ -165,20 +148,18 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("Login") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.Property("Password") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.Property("RoleId") - .HasColumnType("int"); + .HasColumnType("INTEGER"); b.HasKey("Id"); @@ -191,17 +172,15 @@ namespace DEMO.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + .HasColumnType("INTEGER"); b.Property("Address") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.Property("Name") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("TEXT"); b.HasKey("Id"); diff --git a/DEMO/Program.cs b/DEMO/Program.cs index 8783c20..76619dc 100644 --- a/DEMO/Program.cs +++ b/DEMO/Program.cs @@ -7,15 +7,22 @@ var builder = WebApplication.CreateBuilder(args); // говорю что у меня есть контроллеры (api) builder.Services.AddControllers(); -// подключаю базу данных +// подключаю базу данных (простой файл sqlite, лежит рядом) builder.Services.AddDbContext(options => - options.UseSqlServer( + options.UseSqlite( builder.Configuration.GetConnectionString("DefaultConnection"))); // беру строку из настроек builder.Services.AddOpenApi(); // для проверки api var app = builder.Build(); // строю программу +// сам создаю базу если ее нет (чтоб на сервере все завелось само) +using (var scope = app.Services.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.Migrate(); // применяю миграции +} + // в режиме разработки показываю api if (app.Environment.IsDevelopment()) { diff --git a/DEMO/appsettings.json b/DEMO/appsettings.json index d68e734..cdbf07c 100644 --- a/DEMO/appsettings.json +++ b/DEMO/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=DemoDB;Trusted_Connection=True;TrustServerCertificate=True;" + "DefaultConnection": "Data Source=DemoDB.db" }, "Logging": { "LogLevel": {