using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Apollinare.Infrastructure.Migrations
{
///
public partial class AddPurchasesModule : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Suppliers",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Code = table.Column(type: "TEXT", nullable: false),
Name = table.Column(type: "TEXT", nullable: false),
VatNumber = table.Column(type: "TEXT", nullable: true),
FiscalCode = table.Column(type: "TEXT", nullable: true),
Address = table.Column(type: "TEXT", nullable: true),
City = table.Column(type: "TEXT", nullable: true),
Province = table.Column(type: "TEXT", nullable: true),
ZipCode = table.Column(type: "TEXT", nullable: true),
Country = table.Column(type: "TEXT", nullable: true),
Email = table.Column(type: "TEXT", nullable: true),
Pec = table.Column(type: "TEXT", nullable: true),
Phone = table.Column(type: "TEXT", nullable: true),
Website = table.Column(type: "TEXT", nullable: true),
PaymentTerms = table.Column(type: "TEXT", nullable: true),
Notes = table.Column(type: "TEXT", nullable: true),
IsActive = table.Column(type: "INTEGER", nullable: false),
CreatedAt = table.Column(type: "TEXT", nullable: true),
CreatedBy = table.Column(type: "TEXT", nullable: true),
UpdatedAt = table.Column(type: "TEXT", nullable: true),
UpdatedBy = table.Column(type: "TEXT", nullable: true),
CustomFieldsJson = table.Column(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Suppliers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "PurchaseOrders",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
OrderNumber = table.Column(type: "TEXT", nullable: false),
OrderDate = table.Column(type: "TEXT", nullable: false),
ExpectedDeliveryDate = table.Column(type: "TEXT", nullable: true),
SupplierId = table.Column(type: "INTEGER", nullable: false),
Status = table.Column(type: "INTEGER", nullable: false),
DestinationWarehouseId = table.Column(type: "INTEGER", nullable: true),
Notes = table.Column(type: "TEXT", nullable: true),
TotalNet = table.Column(type: "TEXT", precision: 18, scale: 4, nullable: false),
TotalTax = table.Column(type: "TEXT", precision: 18, scale: 4, nullable: false),
TotalGross = table.Column(type: "TEXT", precision: 18, scale: 4, nullable: false),
CreatedAt = table.Column(type: "TEXT", nullable: true),
CreatedBy = table.Column(type: "TEXT", nullable: true),
UpdatedAt = table.Column(type: "TEXT", nullable: true),
UpdatedBy = table.Column(type: "TEXT", nullable: true),
CustomFieldsJson = table.Column(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PurchaseOrders", x => x.Id);
table.ForeignKey(
name: "FK_PurchaseOrders_Suppliers_SupplierId",
column: x => x.SupplierId,
principalTable: "Suppliers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_PurchaseOrders_WarehouseLocations_DestinationWarehouseId",
column: x => x.DestinationWarehouseId,
principalTable: "WarehouseLocations",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "PurchaseOrderLines",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
PurchaseOrderId = table.Column(type: "INTEGER", nullable: false),
WarehouseArticleId = table.Column(type: "INTEGER", nullable: false),
Description = table.Column(type: "TEXT", nullable: false),
Quantity = table.Column(type: "TEXT", precision: 18, scale: 4, nullable: false),
ReceivedQuantity = table.Column(type: "TEXT", precision: 18, scale: 4, nullable: false),
UnitPrice = table.Column(type: "TEXT", precision: 18, scale: 4, nullable: false),
TaxRate = table.Column(type: "TEXT", precision: 18, scale: 2, nullable: false),
DiscountPercent = table.Column(type: "TEXT", precision: 18, scale: 2, nullable: false),
LineTotal = table.Column(type: "TEXT", precision: 18, scale: 4, nullable: false),
CreatedAt = table.Column(type: "TEXT", nullable: true),
CreatedBy = table.Column(type: "TEXT", nullable: true),
UpdatedAt = table.Column(type: "TEXT", nullable: true),
UpdatedBy = table.Column(type: "TEXT", nullable: true),
CustomFieldsJson = table.Column(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PurchaseOrderLines", x => x.Id);
table.ForeignKey(
name: "FK_PurchaseOrderLines_PurchaseOrders_PurchaseOrderId",
column: x => x.PurchaseOrderId,
principalTable: "PurchaseOrders",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PurchaseOrderLines_WarehouseArticles_WarehouseArticleId",
column: x => x.WarehouseArticleId,
principalTable: "WarehouseArticles",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_PurchaseOrderLines_PurchaseOrderId",
table: "PurchaseOrderLines",
column: "PurchaseOrderId");
migrationBuilder.CreateIndex(
name: "IX_PurchaseOrderLines_WarehouseArticleId",
table: "PurchaseOrderLines",
column: "WarehouseArticleId");
migrationBuilder.CreateIndex(
name: "IX_PurchaseOrders_DestinationWarehouseId",
table: "PurchaseOrders",
column: "DestinationWarehouseId");
migrationBuilder.CreateIndex(
name: "IX_PurchaseOrders_OrderDate",
table: "PurchaseOrders",
column: "OrderDate");
migrationBuilder.CreateIndex(
name: "IX_PurchaseOrders_OrderNumber",
table: "PurchaseOrders",
column: "OrderNumber",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_PurchaseOrders_Status",
table: "PurchaseOrders",
column: "Status");
migrationBuilder.CreateIndex(
name: "IX_PurchaseOrders_SupplierId",
table: "PurchaseOrders",
column: "SupplierId");
migrationBuilder.CreateIndex(
name: "IX_Suppliers_Code",
table: "Suppliers",
column: "Code",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Suppliers_IsActive",
table: "Suppliers",
column: "IsActive");
migrationBuilder.CreateIndex(
name: "IX_Suppliers_Name",
table: "Suppliers",
column: "Name");
migrationBuilder.CreateIndex(
name: "IX_Suppliers_VatNumber",
table: "Suppliers",
column: "VatNumber");
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PurchaseOrderLines");
migrationBuilder.DropTable(
name: "PurchaseOrders");
migrationBuilder.DropTable(
name: "Suppliers");
}
}
}