using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Apollinare.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class InitialCreate : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AppModules",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Code = table.Column<string>(type: "TEXT", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: false),
                    Description = table.Column<string>(type: "TEXT", nullable: true),
                    Icon = table.Column<string>(type: "TEXT", nullable: true),
                    BasePrice = table.Column<decimal>(type: "TEXT", precision: 18, scale: 2, nullable: false),
                    MonthlyMultiplier = table.Column<decimal>(type: "TEXT", precision: 5, scale: 2, nullable: false),
                    SortOrder = table.Column<int>(type: "INTEGER", nullable: false),
                    IsCore = table.Column<bool>(type: "INTEGER", nullable: false),
                    Dependencies = table.Column<string>(type: "TEXT", nullable: true),
                    RoutePath = table.Column<string>(type: "TEXT", nullable: true),
                    IsAvailable = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppModules", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Clienti",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    RagioneSociale = table.Column<string>(type: "TEXT", nullable: false),
                    Indirizzo = table.Column<string>(type: "TEXT", nullable: true),
                    Cap = table.Column<string>(type: "TEXT", nullable: true),
                    Citta = table.Column<string>(type: "TEXT", nullable: true),
                    Provincia = table.Column<string>(type: "TEXT", nullable: true),
                    Telefono = table.Column<string>(type: "TEXT", nullable: true),
                    Email = table.Column<string>(type: "TEXT", nullable: true),
                    Pec = table.Column<string>(type: "TEXT", nullable: true),
                    CodiceFiscale = table.Column<string>(type: "TEXT", nullable: true),
                    PartitaIva = table.Column<string>(type: "TEXT", nullable: true),
                    CodiceDestinatario = table.Column<string>(type: "TEXT", nullable: true),
                    Note = table.Column<string>(type: "TEXT", nullable: true),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Clienti", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "CodiciCategoria",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Codice = table.Column<string>(type: "TEXT", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: false),
                    CoeffA = table.Column<decimal>(type: "TEXT", nullable: false),
                    CoeffB = table.Column<decimal>(type: "TEXT", nullable: false),
                    CoeffS = table.Column<decimal>(type: "TEXT", nullable: false),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CodiciCategoria", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Configurazioni",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Chiave = table.Column<string>(type: "TEXT", nullable: false),
                    Valore = table.Column<string>(type: "TEXT", nullable: true),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Configurazioni", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Location",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Nome = table.Column<string>(type: "TEXT", nullable: false),
                    Indirizzo = table.Column<string>(type: "TEXT", nullable: true),
                    Cap = table.Column<string>(type: "TEXT", nullable: true),
                    Citta = table.Column<string>(type: "TEXT", nullable: true),
                    Provincia = table.Column<string>(type: "TEXT", nullable: true),
                    Telefono = table.Column<string>(type: "TEXT", nullable: true),
                    Email = table.Column<string>(type: "TEXT", nullable: true),
                    Referente = table.Column<string>(type: "TEXT", nullable: true),
                    DistanzaKm = table.Column<decimal>(type: "TEXT", nullable: true),
                    Note = table.Column<string>(type: "TEXT", nullable: true),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Location", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MovementReasons",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Code = table.Column<string>(type: "TEXT", nullable: false),
                    Description = table.Column<string>(type: "TEXT", nullable: false),
                    MovementType = table.Column<int>(type: "INTEGER", nullable: false),
                    StockSign = table.Column<int>(type: "INTEGER", nullable: false),
                    RequiresExternalReference = table.Column<bool>(type: "INTEGER", nullable: false),
                    RequiresValuation = table.Column<bool>(type: "INTEGER", nullable: false),
                    UpdatesAverageCost = table.Column<bool>(type: "INTEGER", nullable: false),
                    IsSystem = table.Column<bool>(type: "INTEGER", nullable: false),
                    IsActive = table.Column<bool>(type: "INTEGER", nullable: false),
                    SortOrder = table.Column<int>(type: "INTEGER", nullable: false),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MovementReasons", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ReportFonts",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Nome = table.Column<string>(type: "TEXT", nullable: false),
                    FontFamily = table.Column<string>(type: "TEXT", nullable: false),
                    FontStyle = table.Column<string>(type: "TEXT", nullable: false),
                    FontData = table.Column<byte[]>(type: "BLOB", nullable: false),
                    MimeType = table.Column<string>(type: "TEXT", nullable: false),
                    FileSize = table.Column<long>(type: "INTEGER", nullable: false),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ReportFonts", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ReportImages",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Nome = table.Column<string>(type: "TEXT", nullable: false),
                    Categoria = table.Column<string>(type: "TEXT", nullable: false),
                    ImageData = table.Column<byte[]>(type: "BLOB", nullable: false),
                    MimeType = table.Column<string>(type: "TEXT", nullable: false),
                    Width = table.Column<int>(type: "INTEGER", nullable: false),
                    Height = table.Column<int>(type: "INTEGER", nullable: false),
                    FileSize = table.Column<long>(type: "INTEGER", nullable: false),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ReportImages", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ReportTemplates",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Nome = table.Column<string>(type: "TEXT", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: true),
                    Categoria = table.Column<string>(type: "TEXT", nullable: false),
                    TemplateJson = table.Column<string>(type: "TEXT", nullable: false),
                    Thumbnail = table.Column<byte[]>(type: "BLOB", nullable: true),
                    ThumbnailMimeType = table.Column<string>(type: "TEXT", nullable: true),
                    PageSize = table.Column<string>(type: "TEXT", nullable: false),
                    Orientation = table.Column<string>(type: "TEXT", nullable: false),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ReportTemplates", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "TipiMateriale",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Codice = table.Column<string>(type: "TEXT", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: false),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TipiMateriale", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "TipiOspite",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Codice = table.Column<string>(type: "TEXT", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: false),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TipiOspite", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "TipiPasto",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Codice = table.Column<string>(type: "TEXT", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: false),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TipiPasto", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "TipiRisorsa",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Codice = table.Column<string>(type: "TEXT", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: false),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TipiRisorsa", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Utenti",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Username = table.Column<string>(type: "TEXT", nullable: false),
                    Nome = table.Column<string>(type: "TEXT", nullable: true),
                    Cognome = table.Column<string>(type: "TEXT", nullable: true),
                    Email = table.Column<string>(type: "TEXT", nullable: true),
                    SolaLettura = table.Column<bool>(type: "INTEGER", nullable: false),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    Ruolo = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Utenti", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "VirtualDatasets",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Nome = table.Column<string>(type: "TEXT", nullable: false),
                    DisplayName = table.Column<string>(type: "TEXT", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: true),
                    Icon = table.Column<string>(type: "TEXT", nullable: false),
                    Categoria = table.Column<string>(type: "TEXT", nullable: false),
                    ConfigurationJson = table.Column<string>(type: "TEXT", nullable: false),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_VirtualDatasets", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "WarehouseArticleCategories",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Code = table.Column<string>(type: "TEXT", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: false),
                    Description = table.Column<string>(type: "TEXT", nullable: true),
                    ParentCategoryId = table.Column<int>(type: "INTEGER", nullable: true),
                    Level = table.Column<int>(type: "INTEGER", nullable: false),
                    FullPath = table.Column<string>(type: "TEXT", nullable: true),
                    Icon = table.Column<string>(type: "TEXT", nullable: true),
                    Color = table.Column<string>(type: "TEXT", nullable: true),
                    DefaultValuationMethod = table.Column<int>(type: "INTEGER", nullable: true),
                    SortOrder = table.Column<int>(type: "INTEGER", nullable: false),
                    IsActive = table.Column<bool>(type: "INTEGER", nullable: false),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WarehouseArticleCategories", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WarehouseArticleCategories_WarehouseArticleCategories_ParentCategoryId",
                        column: x => x.ParentCategoryId,
                        principalTable: "WarehouseArticleCategories",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "WarehouseLocations",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Code = table.Column<string>(type: "TEXT", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: false),
                    Description = table.Column<string>(type: "TEXT", nullable: true),
                    Address = table.Column<string>(type: "TEXT", nullable: true),
                    City = table.Column<string>(type: "TEXT", nullable: true),
                    Province = table.Column<string>(type: "TEXT", nullable: true),
                    PostalCode = table.Column<string>(type: "TEXT", nullable: true),
                    Country = table.Column<string>(type: "TEXT", nullable: true),
                    Type = table.Column<int>(type: "INTEGER", nullable: false),
                    IsDefault = table.Column<bool>(type: "INTEGER", nullable: false),
                    IsActive = table.Column<bool>(type: "INTEGER", nullable: false),
                    SortOrder = table.Column<int>(type: "INTEGER", nullable: false),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WarehouseLocations", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "ModuleSubscriptions",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    ModuleId = table.Column<int>(type: "INTEGER", nullable: false),
                    IsEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
                    SubscriptionType = table.Column<int>(type: "INTEGER", nullable: false),
                    StartDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    EndDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    AutoRenew = table.Column<bool>(type: "INTEGER", nullable: false),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    LastRenewalDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    PaidPrice = table.Column<decimal>(type: "TEXT", precision: 18, scale: 2, nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ModuleSubscriptions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ModuleSubscriptions_AppModules_ModuleId",
                        column: x => x.ModuleId,
                        principalTable: "AppModules",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Articoli",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Codice = table.Column<string>(type: "TEXT", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: false),
                    TipoMaterialeId = table.Column<int>(type: "INTEGER", nullable: true),
                    CategoriaId = table.Column<int>(type: "INTEGER", nullable: true),
                    QtaDisponibile = table.Column<decimal>(type: "TEXT", nullable: true),
                    QtaStdA = table.Column<decimal>(type: "TEXT", nullable: true),
                    QtaStdB = table.Column<decimal>(type: "TEXT", nullable: true),
                    QtaStdS = table.Column<decimal>(type: "TEXT", nullable: true),
                    UnitaMisura = table.Column<string>(type: "TEXT", nullable: true),
                    Immagine = table.Column<byte[]>(type: "BLOB", nullable: true),
                    MimeType = table.Column<string>(type: "TEXT", nullable: true),
                    Note = table.Column<string>(type: "TEXT", nullable: true),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Articoli", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Articoli_CodiciCategoria_CategoriaId",
                        column: x => x.CategoriaId,
                        principalTable: "CodiciCategoria",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_Articoli_TipiMateriale_TipoMaterialeId",
                        column: x => x.TipoMaterialeId,
                        principalTable: "TipiMateriale",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateTable(
                name: "TipiEvento",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Codice = table.Column<string>(type: "TEXT", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: false),
                    TipoPastoId = table.Column<int>(type: "INTEGER", nullable: true),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TipiEvento", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TipiEvento_TipiPasto_TipoPastoId",
                        column: x => x.TipoPastoId,
                        principalTable: "TipiPasto",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateTable(
                name: "Risorse",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Nome = table.Column<string>(type: "TEXT", nullable: false),
                    Cognome = table.Column<string>(type: "TEXT", nullable: true),
                    Telefono = table.Column<string>(type: "TEXT", nullable: true),
                    Email = table.Column<string>(type: "TEXT", nullable: true),
                    TipoRisorsaId = table.Column<int>(type: "INTEGER", nullable: true),
                    Note = table.Column<string>(type: "TEXT", nullable: true),
                    Attivo = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Risorse", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Risorse_TipiRisorsa_TipoRisorsaId",
                        column: x => x.TipoRisorsaId,
                        principalTable: "TipiRisorsa",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateTable(
                name: "WarehouseArticles",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Code = table.Column<string>(type: "TEXT", nullable: false),
                    Description = table.Column<string>(type: "TEXT", nullable: false),
                    ShortDescription = table.Column<string>(type: "TEXT", nullable: true),
                    Barcode = table.Column<string>(type: "TEXT", nullable: true),
                    ManufacturerCode = table.Column<string>(type: "TEXT", nullable: true),
                    CategoryId = table.Column<int>(type: "INTEGER", nullable: true),
                    UnitOfMeasure = table.Column<string>(type: "TEXT", nullable: false),
                    SecondaryUnitOfMeasure = table.Column<string>(type: "TEXT", nullable: true),
                    UnitConversionFactor = table.Column<decimal>(type: "TEXT", precision: 18, scale: 6, nullable: true),
                    StockManagement = table.Column<int>(type: "INTEGER", nullable: false),
                    IsBatchManaged = table.Column<bool>(type: "INTEGER", nullable: false),
                    IsSerialManaged = table.Column<bool>(type: "INTEGER", nullable: false),
                    HasExpiry = table.Column<bool>(type: "INTEGER", nullable: false),
                    ExpiryWarningDays = table.Column<int>(type: "INTEGER", nullable: true),
                    MinimumStock = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    MaximumStock = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    ReorderPoint = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    ReorderQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    LeadTimeDays = table.Column<int>(type: "INTEGER", nullable: true),
                    ValuationMethod = table.Column<int>(type: "INTEGER", nullable: true),
                    StandardCost = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    LastPurchaseCost = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    WeightedAverageCost = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    BaseSellingPrice = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    Weight = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    Volume = table.Column<decimal>(type: "TEXT", precision: 18, scale: 6, nullable: true),
                    Width = table.Column<decimal>(type: "TEXT", nullable: true),
                    Height = table.Column<decimal>(type: "TEXT", nullable: true),
                    Depth = table.Column<decimal>(type: "TEXT", nullable: true),
                    Image = table.Column<byte[]>(type: "BLOB", nullable: true),
                    ImageMimeType = table.Column<string>(type: "TEXT", nullable: true),
                    IsActive = table.Column<bool>(type: "INTEGER", nullable: false),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WarehouseArticles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WarehouseArticles_WarehouseArticleCategories_CategoryId",
                        column: x => x.CategoryId,
                        principalTable: "WarehouseArticleCategories",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateTable(
                name: "StockMovements",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    DocumentNumber = table.Column<string>(type: "TEXT", nullable: false),
                    MovementDate = table.Column<DateTime>(type: "TEXT", nullable: false),
                    Type = table.Column<int>(type: "INTEGER", nullable: false),
                    ReasonId = table.Column<int>(type: "INTEGER", nullable: true),
                    SourceWarehouseId = table.Column<int>(type: "INTEGER", nullable: true),
                    DestinationWarehouseId = table.Column<int>(type: "INTEGER", nullable: true),
                    ExternalReference = table.Column<string>(type: "TEXT", nullable: true),
                    ExternalDocumentType = table.Column<int>(type: "INTEGER", nullable: true),
                    SupplierId = table.Column<int>(type: "INTEGER", nullable: true),
                    CustomerId = table.Column<int>(type: "INTEGER", nullable: true),
                    Status = table.Column<int>(type: "INTEGER", nullable: false),
                    ConfirmedDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    ConfirmedBy = table.Column<string>(type: "TEXT", nullable: true),
                    TotalValue = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_StockMovements", x => x.Id);
                    table.ForeignKey(
                        name: "FK_StockMovements_MovementReasons_ReasonId",
                        column: x => x.ReasonId,
                        principalTable: "MovementReasons",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_StockMovements_WarehouseLocations_DestinationWarehouseId",
                        column: x => x.DestinationWarehouseId,
                        principalTable: "WarehouseLocations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_StockMovements_WarehouseLocations_SourceWarehouseId",
                        column: x => x.SourceWarehouseId,
                        principalTable: "WarehouseLocations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Eventi",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Codice = table.Column<string>(type: "TEXT", nullable: true),
                    DataEvento = table.Column<DateTime>(type: "TEXT", nullable: false),
                    OraInizio = table.Column<TimeSpan>(type: "TEXT", nullable: true),
                    OraFine = table.Column<TimeSpan>(type: "TEXT", nullable: true),
                    ClienteId = table.Column<int>(type: "INTEGER", nullable: true),
                    LocationId = table.Column<int>(type: "INTEGER", nullable: true),
                    TipoEventoId = table.Column<int>(type: "INTEGER", nullable: true),
                    Stato = table.Column<int>(type: "INTEGER", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: true),
                    NumeroOspiti = table.Column<int>(type: "INTEGER", nullable: true),
                    NumeroOspitiAdulti = table.Column<int>(type: "INTEGER", nullable: true),
                    NumeroOspitiBambini = table.Column<int>(type: "INTEGER", nullable: true),
                    NumeroOspitiSeduti = table.Column<int>(type: "INTEGER", nullable: true),
                    NumeroOspitiBuffet = table.Column<int>(type: "INTEGER", nullable: true),
                    CostoTotale = table.Column<decimal>(type: "TEXT", nullable: true),
                    CostoPersona = table.Column<decimal>(type: "TEXT", nullable: true),
                    TotaleAcconti = table.Column<decimal>(type: "TEXT", nullable: true),
                    Saldo = table.Column<decimal>(type: "TEXT", nullable: true),
                    DataScadenzaPreventivo = table.Column<DateTime>(type: "TEXT", nullable: true),
                    NoteInterne = table.Column<string>(type: "TEXT", nullable: true),
                    NoteCliente = table.Column<string>(type: "TEXT", nullable: true),
                    NoteCucina = table.Column<string>(type: "TEXT", nullable: true),
                    NoteAllestimento = table.Column<string>(type: "TEXT", nullable: true),
                    Confermato = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Eventi", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Eventi_Clienti_ClienteId",
                        column: x => x.ClienteId,
                        principalTable: "Clienti",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_Eventi_Location_LocationId",
                        column: x => x.LocationId,
                        principalTable: "Location",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_Eventi_TipiEvento_TipoEventoId",
                        column: x => x.TipoEventoId,
                        principalTable: "TipiEvento",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateTable(
                name: "ArticleBarcodes",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    ArticleId = table.Column<int>(type: "INTEGER", nullable: false),
                    Barcode = table.Column<string>(type: "TEXT", nullable: false),
                    Type = table.Column<int>(type: "INTEGER", nullable: false),
                    Description = table.Column<string>(type: "TEXT", nullable: true),
                    Quantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    IsPrimary = table.Column<bool>(type: "INTEGER", nullable: false),
                    IsActive = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArticleBarcodes", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ArticleBarcodes_WarehouseArticles_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "WarehouseArticles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArticleBatches",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    ArticleId = table.Column<int>(type: "INTEGER", nullable: false),
                    BatchNumber = table.Column<string>(type: "TEXT", nullable: false),
                    ProductionDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    ExpiryDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    SupplierBatch = table.Column<string>(type: "TEXT", nullable: true),
                    SupplierId = table.Column<int>(type: "INTEGER", nullable: true),
                    UnitCost = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    InitialQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    CurrentQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    ReservedQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    Status = table.Column<int>(type: "INTEGER", nullable: false),
                    QualityStatus = table.Column<int>(type: "INTEGER", nullable: true),
                    LastQualityCheckDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    Certifications = table.Column<string>(type: "TEXT", nullable: true),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArticleBatches", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ArticleBatches_WarehouseArticles_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "WarehouseArticles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "StockValuations",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    ValuationDate = table.Column<DateTime>(type: "TEXT", nullable: false),
                    Period = table.Column<int>(type: "INTEGER", nullable: false),
                    ArticleId = table.Column<int>(type: "INTEGER", nullable: false),
                    WarehouseId = table.Column<int>(type: "INTEGER", nullable: true),
                    Quantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    Method = table.Column<int>(type: "INTEGER", nullable: false),
                    UnitCost = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    TotalValue = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    InboundQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    InboundValue = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    OutboundQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    OutboundValue = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    IsClosed = table.Column<bool>(type: "INTEGER", nullable: false),
                    ClosedDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    ClosedBy = table.Column<string>(type: "TEXT", nullable: true),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_StockValuations", x => x.Id);
                    table.ForeignKey(
                        name: "FK_StockValuations_WarehouseArticles_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "WarehouseArticles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_StockValuations_WarehouseLocations_WarehouseId",
                        column: x => x.WarehouseId,
                        principalTable: "WarehouseLocations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateTable(
                name: "InventoryCounts",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Code = table.Column<string>(type: "TEXT", nullable: false),
                    Description = table.Column<string>(type: "TEXT", nullable: false),
                    InventoryDate = table.Column<DateTime>(type: "TEXT", nullable: false),
                    WarehouseId = table.Column<int>(type: "INTEGER", nullable: true),
                    CategoryId = table.Column<int>(type: "INTEGER", nullable: true),
                    Type = table.Column<int>(type: "INTEGER", nullable: false),
                    Status = table.Column<int>(type: "INTEGER", nullable: false),
                    StartDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    EndDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    ConfirmedDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    ConfirmedBy = table.Column<string>(type: "TEXT", nullable: true),
                    AdjustmentMovementId = table.Column<int>(type: "INTEGER", nullable: true),
                    PositiveDifferenceValue = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    NegativeDifferenceValue = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_InventoryCounts", x => x.Id);
                    table.ForeignKey(
                        name: "FK_InventoryCounts_StockMovements_AdjustmentMovementId",
                        column: x => x.AdjustmentMovementId,
                        principalTable: "StockMovements",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_InventoryCounts_WarehouseArticleCategories_CategoryId",
                        column: x => x.CategoryId,
                        principalTable: "WarehouseArticleCategories",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_InventoryCounts_WarehouseLocations_WarehouseId",
                        column: x => x.WarehouseId,
                        principalTable: "WarehouseLocations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateTable(
                name: "EventiAcconti",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    EventoId = table.Column<int>(type: "INTEGER", nullable: false),
                    DataPagamento = table.Column<DateTime>(type: "TEXT", nullable: true),
                    Importo = table.Column<decimal>(type: "TEXT", nullable: false),
                    Ordine = table.Column<int>(type: "INTEGER", nullable: false),
                    AConferma = table.Column<bool>(type: "INTEGER", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: true),
                    MetodoPagamento = table.Column<string>(type: "TEXT", nullable: true),
                    Note = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EventiAcconti", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EventiAcconti_Eventi_EventoId",
                        column: x => x.EventoId,
                        principalTable: "Eventi",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "EventiAllegati",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    EventoId = table.Column<int>(type: "INTEGER", nullable: false),
                    NomeFile = table.Column<string>(type: "TEXT", nullable: false),
                    MimeType = table.Column<string>(type: "TEXT", nullable: true),
                    Contenuto = table.Column<byte[]>(type: "BLOB", nullable: true),
                    Note = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EventiAllegati", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EventiAllegati_Eventi_EventoId",
                        column: x => x.EventoId,
                        principalTable: "Eventi",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "EventiAltriCosti",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    EventoId = table.Column<int>(type: "INTEGER", nullable: false),
                    Descrizione = table.Column<string>(type: "TEXT", nullable: false),
                    CostoUnitario = table.Column<decimal>(type: "TEXT", nullable: false),
                    Quantita = table.Column<decimal>(type: "TEXT", nullable: false),
                    Ordine = table.Column<int>(type: "INTEGER", nullable: false),
                    ApplicaIva = table.Column<bool>(type: "INTEGER", nullable: false),
                    AliquotaIva = table.Column<decimal>(type: "TEXT", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EventiAltriCosti", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EventiAltriCosti_Eventi_EventoId",
                        column: x => x.EventoId,
                        principalTable: "Eventi",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "EventiDegustazioni",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    EventoId = table.Column<int>(type: "INTEGER", nullable: false),
                    DataDegustazione = table.Column<DateTime>(type: "TEXT", nullable: false),
                    Ora = table.Column<TimeSpan>(type: "TEXT", nullable: true),
                    NumeroPersone = table.Column<int>(type: "INTEGER", nullable: true),
                    NumeroPaganti = table.Column<int>(type: "INTEGER", nullable: true),
                    CostoDegustazione = table.Column<decimal>(type: "TEXT", nullable: true),
                    Detraibile = table.Column<bool>(type: "INTEGER", nullable: false),
                    Menu = table.Column<string>(type: "TEXT", nullable: true),
                    Luogo = table.Column<string>(type: "TEXT", nullable: true),
                    Note = table.Column<string>(type: "TEXT", nullable: true),
                    Completata = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EventiDegustazioni", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EventiDegustazioni_Eventi_EventoId",
                        column: x => x.EventoId,
                        principalTable: "Eventi",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "EventiDettaglioOspiti",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    EventoId = table.Column<int>(type: "INTEGER", nullable: false),
                    TipoOspiteId = table.Column<int>(type: "INTEGER", nullable: false),
                    Numero = table.Column<int>(type: "INTEGER", nullable: false),
                    CostoUnitario = table.Column<decimal>(type: "TEXT", nullable: true),
                    Sconto = table.Column<decimal>(type: "TEXT", nullable: true),
                    Ordine = table.Column<int>(type: "INTEGER", nullable: false),
                    Note = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EventiDettaglioOspiti", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EventiDettaglioOspiti_Eventi_EventoId",
                        column: x => x.EventoId,
                        principalTable: "Eventi",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_EventiDettaglioOspiti_TipiOspite_TipoOspiteId",
                        column: x => x.TipoOspiteId,
                        principalTable: "TipiOspite",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "EventiDettaglioPrelievo",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    EventoId = table.Column<int>(type: "INTEGER", nullable: false),
                    ArticoloId = table.Column<int>(type: "INTEGER", nullable: false),
                    QtaRichiesta = table.Column<decimal>(type: "TEXT", nullable: true),
                    QtaCalcolata = table.Column<decimal>(type: "TEXT", nullable: true),
                    QtaEffettiva = table.Column<decimal>(type: "TEXT", nullable: true),
                    Note = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EventiDettaglioPrelievo", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EventiDettaglioPrelievo_Articoli_ArticoloId",
                        column: x => x.ArticoloId,
                        principalTable: "Articoli",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_EventiDettaglioPrelievo_Eventi_EventoId",
                        column: x => x.EventoId,
                        principalTable: "Eventi",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "EventiDettaglioRisorse",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    EventoId = table.Column<int>(type: "INTEGER", nullable: false),
                    RisorsaId = table.Column<int>(type: "INTEGER", nullable: false),
                    OreLavoro = table.Column<decimal>(type: "TEXT", nullable: true),
                    Costo = table.Column<decimal>(type: "TEXT", nullable: true),
                    OraInizio = table.Column<TimeSpan>(type: "TEXT", nullable: true),
                    OraFine = table.Column<TimeSpan>(type: "TEXT", nullable: true),
                    Ruolo = table.Column<string>(type: "TEXT", nullable: true),
                    Note = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EventiDettaglioRisorse", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EventiDettaglioRisorse_Eventi_EventoId",
                        column: x => x.EventoId,
                        principalTable: "Eventi",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_EventiDettaglioRisorse_Risorse_RisorsaId",
                        column: x => x.RisorsaId,
                        principalTable: "Risorse",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "ArticleSerials",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    ArticleId = table.Column<int>(type: "INTEGER", nullable: false),
                    BatchId = table.Column<int>(type: "INTEGER", nullable: true),
                    SerialNumber = table.Column<string>(type: "TEXT", nullable: false),
                    ManufacturerSerial = table.Column<string>(type: "TEXT", nullable: true),
                    ProductionDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    WarrantyExpiryDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CurrentWarehouseId = table.Column<int>(type: "INTEGER", nullable: true),
                    Status = table.Column<int>(type: "INTEGER", nullable: false),
                    UnitCost = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    SupplierId = table.Column<int>(type: "INTEGER", nullable: true),
                    CustomerId = table.Column<int>(type: "INTEGER", nullable: true),
                    SoldDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    SalesReference = table.Column<string>(type: "TEXT", nullable: true),
                    Attributes = table.Column<string>(type: "TEXT", nullable: true),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ArticleSerials", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ArticleSerials_ArticleBatches_BatchId",
                        column: x => x.BatchId,
                        principalTable: "ArticleBatches",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_ArticleSerials_WarehouseArticles_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "WarehouseArticles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ArticleSerials_WarehouseLocations_CurrentWarehouseId",
                        column: x => x.CurrentWarehouseId,
                        principalTable: "WarehouseLocations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateTable(
                name: "StockLevels",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    ArticleId = table.Column<int>(type: "INTEGER", nullable: false),
                    WarehouseId = table.Column<int>(type: "INTEGER", nullable: false),
                    BatchId = table.Column<int>(type: "INTEGER", nullable: true),
                    Quantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    ReservedQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    OnOrderQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    StockValue = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    UnitCost = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    LastMovementDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    LastInventoryDate = table.Column<DateTime>(type: "TEXT", nullable: true),
                    LocationCode = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_StockLevels", x => x.Id);
                    table.ForeignKey(
                        name: "FK_StockLevels_ArticleBatches_BatchId",
                        column: x => x.BatchId,
                        principalTable: "ArticleBatches",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_StockLevels_WarehouseArticles_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "WarehouseArticles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_StockLevels_WarehouseLocations_WarehouseId",
                        column: x => x.WarehouseId,
                        principalTable: "WarehouseLocations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "StockValuationLayers",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    ArticleId = table.Column<int>(type: "INTEGER", nullable: false),
                    WarehouseId = table.Column<int>(type: "INTEGER", nullable: false),
                    BatchId = table.Column<int>(type: "INTEGER", nullable: true),
                    LayerDate = table.Column<DateTime>(type: "TEXT", nullable: false),
                    SourceMovementId = table.Column<int>(type: "INTEGER", nullable: true),
                    OriginalQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    RemainingQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    UnitCost = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    IsExhausted = table.Column<bool>(type: "INTEGER", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_StockValuationLayers", x => x.Id);
                    table.ForeignKey(
                        name: "FK_StockValuationLayers_ArticleBatches_BatchId",
                        column: x => x.BatchId,
                        principalTable: "ArticleBatches",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_StockValuationLayers_StockMovements_SourceMovementId",
                        column: x => x.SourceMovementId,
                        principalTable: "StockMovements",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_StockValuationLayers_WarehouseArticles_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "WarehouseArticles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_StockValuationLayers_WarehouseLocations_WarehouseId",
                        column: x => x.WarehouseId,
                        principalTable: "WarehouseLocations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "InventoryCountLines",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    InventoryCountId = table.Column<int>(type: "INTEGER", nullable: false),
                    ArticleId = table.Column<int>(type: "INTEGER", nullable: false),
                    WarehouseId = table.Column<int>(type: "INTEGER", nullable: false),
                    BatchId = table.Column<int>(type: "INTEGER", nullable: true),
                    LocationCode = table.Column<string>(type: "TEXT", nullable: true),
                    TheoreticalQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    CountedQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    UnitCost = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    CountedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CountedBy = table.Column<string>(type: "TEXT", nullable: true),
                    SecondCountQuantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    SecondCountBy = table.Column<string>(type: "TEXT", nullable: true),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_InventoryCountLines", x => x.Id);
                    table.ForeignKey(
                        name: "FK_InventoryCountLines_ArticleBatches_BatchId",
                        column: x => x.BatchId,
                        principalTable: "ArticleBatches",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_InventoryCountLines_InventoryCounts_InventoryCountId",
                        column: x => x.InventoryCountId,
                        principalTable: "InventoryCounts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_InventoryCountLines_WarehouseArticles_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "WarehouseArticles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_InventoryCountLines_WarehouseLocations_WarehouseId",
                        column: x => x.WarehouseId,
                        principalTable: "WarehouseLocations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "StockMovementLines",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    MovementId = table.Column<int>(type: "INTEGER", nullable: false),
                    LineNumber = table.Column<int>(type: "INTEGER", nullable: false),
                    ArticleId = table.Column<int>(type: "INTEGER", nullable: false),
                    BatchId = table.Column<int>(type: "INTEGER", nullable: true),
                    SerialId = table.Column<int>(type: "INTEGER", nullable: true),
                    Quantity = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: false),
                    UnitOfMeasure = table.Column<string>(type: "TEXT", nullable: false),
                    UnitCost = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    LineValue = table.Column<decimal>(type: "TEXT", precision: 18, scale: 4, nullable: true),
                    SourceLocationCode = table.Column<string>(type: "TEXT", nullable: true),
                    DestinationLocationCode = table.Column<string>(type: "TEXT", nullable: true),
                    ExternalLineReference = table.Column<string>(type: "TEXT", nullable: true),
                    Notes = table.Column<string>(type: "TEXT", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
                    UpdatedBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_StockMovementLines", x => x.Id);
                    table.ForeignKey(
                        name: "FK_StockMovementLines_ArticleBatches_BatchId",
                        column: x => x.BatchId,
                        principalTable: "ArticleBatches",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_StockMovementLines_ArticleSerials_SerialId",
                        column: x => x.SerialId,
                        principalTable: "ArticleSerials",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_StockMovementLines_StockMovements_MovementId",
                        column: x => x.MovementId,
                        principalTable: "StockMovements",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_StockMovementLines_WarehouseArticles_ArticleId",
                        column: x => x.ArticleId,
                        principalTable: "WarehouseArticles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AppModules_Code",
                table: "AppModules",
                column: "Code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_AppModules_SortOrder",
                table: "AppModules",
                column: "SortOrder");

            migrationBuilder.CreateIndex(
                name: "IX_ArticleBarcodes_ArticleId",
                table: "ArticleBarcodes",
                column: "ArticleId");

            migrationBuilder.CreateIndex(
                name: "IX_ArticleBarcodes_Barcode",
                table: "ArticleBarcodes",
                column: "Barcode",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ArticleBatches_ArticleId_BatchNumber",
                table: "ArticleBatches",
                columns: new[] { "ArticleId", "BatchNumber" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ArticleBatches_ExpiryDate",
                table: "ArticleBatches",
                column: "ExpiryDate");

            migrationBuilder.CreateIndex(
                name: "IX_ArticleBatches_Status",
                table: "ArticleBatches",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_ArticleSerials_ArticleId_SerialNumber",
                table: "ArticleSerials",
                columns: new[] { "ArticleId", "SerialNumber" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ArticleSerials_BatchId",
                table: "ArticleSerials",
                column: "BatchId");

            migrationBuilder.CreateIndex(
                name: "IX_ArticleSerials_CurrentWarehouseId",
                table: "ArticleSerials",
                column: "CurrentWarehouseId");

            migrationBuilder.CreateIndex(
                name: "IX_ArticleSerials_Status",
                table: "ArticleSerials",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_Articoli_CategoriaId",
                table: "Articoli",
                column: "CategoriaId");

            migrationBuilder.CreateIndex(
                name: "IX_Articoli_Codice",
                table: "Articoli",
                column: "Codice",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Articoli_TipoMaterialeId",
                table: "Articoli",
                column: "TipoMaterialeId");

            migrationBuilder.CreateIndex(
                name: "IX_Clienti_PartitaIva",
                table: "Clienti",
                column: "PartitaIva");

            migrationBuilder.CreateIndex(
                name: "IX_Clienti_RagioneSociale",
                table: "Clienti",
                column: "RagioneSociale");

            migrationBuilder.CreateIndex(
                name: "IX_Configurazioni_Chiave",
                table: "Configurazioni",
                column: "Chiave",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Eventi_ClienteId",
                table: "Eventi",
                column: "ClienteId");

            migrationBuilder.CreateIndex(
                name: "IX_Eventi_Codice",
                table: "Eventi",
                column: "Codice");

            migrationBuilder.CreateIndex(
                name: "IX_Eventi_DataEvento",
                table: "Eventi",
                column: "DataEvento");

            migrationBuilder.CreateIndex(
                name: "IX_Eventi_LocationId",
                table: "Eventi",
                column: "LocationId");

            migrationBuilder.CreateIndex(
                name: "IX_Eventi_Stato",
                table: "Eventi",
                column: "Stato");

            migrationBuilder.CreateIndex(
                name: "IX_Eventi_TipoEventoId",
                table: "Eventi",
                column: "TipoEventoId");

            migrationBuilder.CreateIndex(
                name: "IX_EventiAcconti_EventoId",
                table: "EventiAcconti",
                column: "EventoId");

            migrationBuilder.CreateIndex(
                name: "IX_EventiAllegati_EventoId",
                table: "EventiAllegati",
                column: "EventoId");

            migrationBuilder.CreateIndex(
                name: "IX_EventiAltriCosti_EventoId",
                table: "EventiAltriCosti",
                column: "EventoId");

            migrationBuilder.CreateIndex(
                name: "IX_EventiDegustazioni_EventoId",
                table: "EventiDegustazioni",
                column: "EventoId");

            migrationBuilder.CreateIndex(
                name: "IX_EventiDettaglioOspiti_EventoId",
                table: "EventiDettaglioOspiti",
                column: "EventoId");

            migrationBuilder.CreateIndex(
                name: "IX_EventiDettaglioOspiti_TipoOspiteId",
                table: "EventiDettaglioOspiti",
                column: "TipoOspiteId");

            migrationBuilder.CreateIndex(
                name: "IX_EventiDettaglioPrelievo_ArticoloId",
                table: "EventiDettaglioPrelievo",
                column: "ArticoloId");

            migrationBuilder.CreateIndex(
                name: "IX_EventiDettaglioPrelievo_EventoId",
                table: "EventiDettaglioPrelievo",
                column: "EventoId");

            migrationBuilder.CreateIndex(
                name: "IX_EventiDettaglioRisorse_EventoId",
                table: "EventiDettaglioRisorse",
                column: "EventoId");

            migrationBuilder.CreateIndex(
                name: "IX_EventiDettaglioRisorse_RisorsaId",
                table: "EventiDettaglioRisorse",
                column: "RisorsaId");

            migrationBuilder.CreateIndex(
                name: "IX_InventoryCountLines_ArticleId",
                table: "InventoryCountLines",
                column: "ArticleId");

            migrationBuilder.CreateIndex(
                name: "IX_InventoryCountLines_BatchId",
                table: "InventoryCountLines",
                column: "BatchId");

            migrationBuilder.CreateIndex(
                name: "IX_InventoryCountLines_InventoryCountId_ArticleId_WarehouseId_BatchId",
                table: "InventoryCountLines",
                columns: new[] { "InventoryCountId", "ArticleId", "WarehouseId", "BatchId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_InventoryCountLines_WarehouseId",
                table: "InventoryCountLines",
                column: "WarehouseId");

            migrationBuilder.CreateIndex(
                name: "IX_InventoryCounts_AdjustmentMovementId",
                table: "InventoryCounts",
                column: "AdjustmentMovementId");

            migrationBuilder.CreateIndex(
                name: "IX_InventoryCounts_CategoryId",
                table: "InventoryCounts",
                column: "CategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_InventoryCounts_Code",
                table: "InventoryCounts",
                column: "Code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_InventoryCounts_InventoryDate",
                table: "InventoryCounts",
                column: "InventoryDate");

            migrationBuilder.CreateIndex(
                name: "IX_InventoryCounts_Status",
                table: "InventoryCounts",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_InventoryCounts_WarehouseId",
                table: "InventoryCounts",
                column: "WarehouseId");

            migrationBuilder.CreateIndex(
                name: "IX_Location_Nome",
                table: "Location",
                column: "Nome");

            migrationBuilder.CreateIndex(
                name: "IX_ModuleSubscriptions_ModuleId",
                table: "ModuleSubscriptions",
                column: "ModuleId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_MovementReasons_Code",
                table: "MovementReasons",
                column: "Code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_MovementReasons_IsActive",
                table: "MovementReasons",
                column: "IsActive");

            migrationBuilder.CreateIndex(
                name: "IX_MovementReasons_MovementType",
                table: "MovementReasons",
                column: "MovementType");

            migrationBuilder.CreateIndex(
                name: "IX_ReportFonts_FontFamily",
                table: "ReportFonts",
                column: "FontFamily");

            migrationBuilder.CreateIndex(
                name: "IX_ReportImages_Categoria",
                table: "ReportImages",
                column: "Categoria");

            migrationBuilder.CreateIndex(
                name: "IX_ReportTemplates_Categoria",
                table: "ReportTemplates",
                column: "Categoria");

            migrationBuilder.CreateIndex(
                name: "IX_ReportTemplates_Nome",
                table: "ReportTemplates",
                column: "Nome");

            migrationBuilder.CreateIndex(
                name: "IX_Risorse_TipoRisorsaId",
                table: "Risorse",
                column: "TipoRisorsaId");

            migrationBuilder.CreateIndex(
                name: "IX_StockLevels_ArticleId_WarehouseId_BatchId",
                table: "StockLevels",
                columns: new[] { "ArticleId", "WarehouseId", "BatchId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_StockLevels_BatchId",
                table: "StockLevels",
                column: "BatchId");

            migrationBuilder.CreateIndex(
                name: "IX_StockLevels_LocationCode",
                table: "StockLevels",
                column: "LocationCode");

            migrationBuilder.CreateIndex(
                name: "IX_StockLevels_WarehouseId",
                table: "StockLevels",
                column: "WarehouseId");

            migrationBuilder.CreateIndex(
                name: "IX_StockMovementLines_ArticleId",
                table: "StockMovementLines",
                column: "ArticleId");

            migrationBuilder.CreateIndex(
                name: "IX_StockMovementLines_BatchId",
                table: "StockMovementLines",
                column: "BatchId");

            migrationBuilder.CreateIndex(
                name: "IX_StockMovementLines_MovementId_LineNumber",
                table: "StockMovementLines",
                columns: new[] { "MovementId", "LineNumber" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_StockMovementLines_SerialId",
                table: "StockMovementLines",
                column: "SerialId");

            migrationBuilder.CreateIndex(
                name: "IX_StockMovements_DestinationWarehouseId",
                table: "StockMovements",
                column: "DestinationWarehouseId");

            migrationBuilder.CreateIndex(
                name: "IX_StockMovements_DocumentNumber",
                table: "StockMovements",
                column: "DocumentNumber",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_StockMovements_ExternalReference",
                table: "StockMovements",
                column: "ExternalReference");

            migrationBuilder.CreateIndex(
                name: "IX_StockMovements_MovementDate",
                table: "StockMovements",
                column: "MovementDate");

            migrationBuilder.CreateIndex(
                name: "IX_StockMovements_ReasonId",
                table: "StockMovements",
                column: "ReasonId");

            migrationBuilder.CreateIndex(
                name: "IX_StockMovements_SourceWarehouseId",
                table: "StockMovements",
                column: "SourceWarehouseId");

            migrationBuilder.CreateIndex(
                name: "IX_StockMovements_Status",
                table: "StockMovements",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_StockMovements_Type",
                table: "StockMovements",
                column: "Type");

            migrationBuilder.CreateIndex(
                name: "IX_StockValuationLayers_ArticleId_WarehouseId_LayerDate",
                table: "StockValuationLayers",
                columns: new[] { "ArticleId", "WarehouseId", "LayerDate" });

            migrationBuilder.CreateIndex(
                name: "IX_StockValuationLayers_BatchId",
                table: "StockValuationLayers",
                column: "BatchId");

            migrationBuilder.CreateIndex(
                name: "IX_StockValuationLayers_IsExhausted",
                table: "StockValuationLayers",
                column: "IsExhausted");

            migrationBuilder.CreateIndex(
                name: "IX_StockValuationLayers_SourceMovementId",
                table: "StockValuationLayers",
                column: "SourceMovementId");

            migrationBuilder.CreateIndex(
                name: "IX_StockValuationLayers_WarehouseId",
                table: "StockValuationLayers",
                column: "WarehouseId");

            migrationBuilder.CreateIndex(
                name: "IX_StockValuations_ArticleId",
                table: "StockValuations",
                column: "ArticleId");

            migrationBuilder.CreateIndex(
                name: "IX_StockValuations_IsClosed",
                table: "StockValuations",
                column: "IsClosed");

            migrationBuilder.CreateIndex(
                name: "IX_StockValuations_Period_ArticleId_WarehouseId",
                table: "StockValuations",
                columns: new[] { "Period", "ArticleId", "WarehouseId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_StockValuations_ValuationDate",
                table: "StockValuations",
                column: "ValuationDate");

            migrationBuilder.CreateIndex(
                name: "IX_StockValuations_WarehouseId",
                table: "StockValuations",
                column: "WarehouseId");

            migrationBuilder.CreateIndex(
                name: "IX_TipiEvento_TipoPastoId",
                table: "TipiEvento",
                column: "TipoPastoId");

            migrationBuilder.CreateIndex(
                name: "IX_Utenti_Username",
                table: "Utenti",
                column: "Username",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_VirtualDatasets_Categoria",
                table: "VirtualDatasets",
                column: "Categoria");

            migrationBuilder.CreateIndex(
                name: "IX_VirtualDatasets_Nome",
                table: "VirtualDatasets",
                column: "Nome",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_WarehouseArticleCategories_Code",
                table: "WarehouseArticleCategories",
                column: "Code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_WarehouseArticleCategories_FullPath",
                table: "WarehouseArticleCategories",
                column: "FullPath");

            migrationBuilder.CreateIndex(
                name: "IX_WarehouseArticleCategories_ParentCategoryId",
                table: "WarehouseArticleCategories",
                column: "ParentCategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_WarehouseArticles_Barcode",
                table: "WarehouseArticles",
                column: "Barcode");

            migrationBuilder.CreateIndex(
                name: "IX_WarehouseArticles_CategoryId",
                table: "WarehouseArticles",
                column: "CategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_WarehouseArticles_Code",
                table: "WarehouseArticles",
                column: "Code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_WarehouseArticles_IsActive",
                table: "WarehouseArticles",
                column: "IsActive");

            migrationBuilder.CreateIndex(
                name: "IX_WarehouseLocations_Code",
                table: "WarehouseLocations",
                column: "Code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_WarehouseLocations_IsActive",
                table: "WarehouseLocations",
                column: "IsActive");

            migrationBuilder.CreateIndex(
                name: "IX_WarehouseLocations_IsDefault",
                table: "WarehouseLocations",
                column: "IsDefault");
        }

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

            migrationBuilder.DropTable(
                name: "Configurazioni");

            migrationBuilder.DropTable(
                name: "EventiAcconti");

            migrationBuilder.DropTable(
                name: "EventiAllegati");

            migrationBuilder.DropTable(
                name: "EventiAltriCosti");

            migrationBuilder.DropTable(
                name: "EventiDegustazioni");

            migrationBuilder.DropTable(
                name: "EventiDettaglioOspiti");

            migrationBuilder.DropTable(
                name: "EventiDettaglioPrelievo");

            migrationBuilder.DropTable(
                name: "EventiDettaglioRisorse");

            migrationBuilder.DropTable(
                name: "InventoryCountLines");

            migrationBuilder.DropTable(
                name: "ModuleSubscriptions");

            migrationBuilder.DropTable(
                name: "ReportFonts");

            migrationBuilder.DropTable(
                name: "ReportImages");

            migrationBuilder.DropTable(
                name: "ReportTemplates");

            migrationBuilder.DropTable(
                name: "StockLevels");

            migrationBuilder.DropTable(
                name: "StockMovementLines");

            migrationBuilder.DropTable(
                name: "StockValuationLayers");

            migrationBuilder.DropTable(
                name: "StockValuations");

            migrationBuilder.DropTable(
                name: "Utenti");

            migrationBuilder.DropTable(
                name: "VirtualDatasets");

            migrationBuilder.DropTable(
                name: "TipiOspite");

            migrationBuilder.DropTable(
                name: "Articoli");

            migrationBuilder.DropTable(
                name: "Eventi");

            migrationBuilder.DropTable(
                name: "Risorse");

            migrationBuilder.DropTable(
                name: "InventoryCounts");

            migrationBuilder.DropTable(
                name: "AppModules");

            migrationBuilder.DropTable(
                name: "ArticleSerials");

            migrationBuilder.DropTable(
                name: "CodiciCategoria");

            migrationBuilder.DropTable(
                name: "TipiMateriale");

            migrationBuilder.DropTable(
                name: "Clienti");

            migrationBuilder.DropTable(
                name: "Location");

            migrationBuilder.DropTable(
                name: "TipiEvento");

            migrationBuilder.DropTable(
                name: "TipiRisorsa");

            migrationBuilder.DropTable(
                name: "StockMovements");

            migrationBuilder.DropTable(
                name: "ArticleBatches");

            migrationBuilder.DropTable(
                name: "TipiPasto");

            migrationBuilder.DropTable(
                name: "MovementReasons");

            migrationBuilder.DropTable(
                name: "WarehouseLocations");

            migrationBuilder.DropTable(
                name: "WarehouseArticles");

            migrationBuilder.DropTable(
                name: "WarehouseArticleCategories");
        }
    }
}
